Skip to content

Commit

Permalink
Allow search-as-you-type functionality on boolean search
Browse files Browse the repository at this point in the history
  • Loading branch information
nbolender committed Jun 9, 2017
1 parent 163817a commit f12cacb
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/TNTSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ public function search($phrase, $numOfResults = 100)

public function searchBoolean($phrase, $numOfResults = 100)
{
$keywords = $this->breakIntoTokens($phrase);
$lastKeyword = end($keywords);

$stack = [];
$startTimer = microtime(true);

Expand All @@ -141,11 +144,13 @@ public function searchBoolean($phrase, $numOfResults = 100)
$left = array_pop($stack);
$right = array_pop($stack);
if (is_string($left)) {
$left = $this->getAllDocumentsForKeyword($this->stemmer->stem($left), true)
$isLastKeyword = $left == $lastKeyword;
$left = $this->getAllDocumentsForKeyword($this->stemmer->stem($left), true, $isLastKeyword)
->pluck('doc_id');
}
if (is_string($right)) {
$right = $this->getAllDocumentsForKeyword($this->stemmer->stem($right), true)
$isLastKeyword = $right == $lastKeyword;
$right = $this->getAllDocumentsForKeyword($this->stemmer->stem($right), true, $isLastKeyword)
->pluck('doc_id');
}
if (is_null($left)) {
Expand All @@ -162,11 +167,13 @@ public function searchBoolean($phrase, $numOfResults = 100)
$right = array_pop($stack);

if (is_string($left)) {
$left = $this->getAllDocumentsForKeyword($this->stemmer->stem($left), true)
$isLastKeyword = $left == $lastKeyword;
$left = $this->getAllDocumentsForKeyword($this->stemmer->stem($left), true, $isLastKeyword)
->pluck('doc_id');
}
if (is_string($right)) {
$right = $this->getAllDocumentsForKeyword($this->stemmer->stem($right), true)
$isLastKeyword = $right == $lastKeyword;
$right = $this->getAllDocumentsForKeyword($this->stemmer->stem($right), true, $isLastKeyword)
->pluck('doc_id');
}
if (is_null($left)) {
Expand Down

0 comments on commit f12cacb

Please sign in to comment.