Collect gambits that were matched and applied

This commit is contained in:
Toby Zerner 2015-05-06 11:23:35 +09:30
parent a4d3345b99
commit e7ff776001
2 changed files with 14 additions and 0 deletions

View File

@ -13,6 +13,8 @@ class DiscussionSearcher implements SearcherInterface
protected $relevantPosts = []; protected $relevantPosts = [];
protected $activeGambits = [];
protected $gambits; protected $gambits;
protected $discussions; protected $discussions;
@ -44,6 +46,16 @@ class DiscussionSearcher implements SearcherInterface
return $this->query->getQuery(); return $this->query->getQuery();
} }
public function addActiveGambit($gambit)
{
$this->activeGambits[] = $gambit;
}
public function getActiveGambits()
{
return $this->activeGambits;
}
public function search(DiscussionSearchCriteria $criteria, $limit = null, $offset = 0, $load = []) public function search(DiscussionSearchCriteria $criteria, $limit = null, $offset = 0, $load = [])
{ {
$this->user = $criteria->user; $this->user = $criteria->user;

View File

@ -48,6 +48,7 @@ class GambitManager
foreach ($bits as $k => $bit) { foreach ($bits as $k => $bit) {
foreach ($gambits as $gambit) { foreach ($gambits as $gambit) {
if ($gambit->apply($bit, $searcher)) { if ($gambit->apply($bit, $searcher)) {
$searcher->addActiveGambit($gambit);
unset($bits[$k]); unset($bits[$k]);
break; break;
} }
@ -65,6 +66,7 @@ class GambitManager
$gambit = $this->container->make($this->fulltextGambit); $gambit = $this->container->make($this->fulltextGambit);
$searcher->addActiveGambit($gambit);
$gambit->apply($string, $searcher); $gambit->apply($string, $searcher);
} }