From c0fa861693a7d9b220b7d12903cadb549aee7ac8 Mon Sep 17 00:00:00 2001 From: Nathan Bolender Date: Thu, 8 Jun 2017 23:20:11 -0400 Subject: [PATCH 1/2] Allow search-as-you-type functionality on boolean search --- src/TNTSearch.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/TNTSearch.php b/src/TNTSearch.php index b6b3edd..e180cea 100644 --- a/src/TNTSearch.php +++ b/src/TNTSearch.php @@ -151,6 +151,9 @@ public function search($phrase, $numOfResults = 100) */ public function searchBoolean($phrase, $numOfResults = 100) { + $keywords = $this->breakIntoTokens($phrase); + $lastKeyword = end($keywords); + $stack = []; $startTimer = microtime(true); @@ -162,11 +165,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)) { @@ -183,11 +188,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)) { From 7783036c204dd55bb8da89b709cfe9336b316a07 Mon Sep 17 00:00:00 2001 From: Nathan Bolender Date: Wed, 18 Dec 2019 18:26:33 -0500 Subject: [PATCH 2/2] formatting --- src/TNTSearch.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/TNTSearch.php b/src/TNTSearch.php index e180cea..b883bd0 100644 --- a/src/TNTSearch.php +++ b/src/TNTSearch.php @@ -151,8 +151,8 @@ public function search($phrase, $numOfResults = 100) */ public function searchBoolean($phrase, $numOfResults = 100) { - $keywords = $this->breakIntoTokens($phrase); - $lastKeyword = end($keywords); + $keywords = $this->breakIntoTokens($phrase); + $lastKeyword = end($keywords); $stack = []; $startTimer = microtime(true); @@ -165,12 +165,12 @@ public function searchBoolean($phrase, $numOfResults = 100) $left = array_pop($stack); $right = array_pop($stack); if (is_string($left)) { - $isLastKeyword = $left == $lastKeyword; + $isLastKeyword = $left == $lastKeyword; $left = $this->getAllDocumentsForKeyword($this->stemmer->stem($left), true, $isLastKeyword) ->pluck('doc_id'); } if (is_string($right)) { - $isLastKeyword = $right == $lastKeyword; + $isLastKeyword = $right == $lastKeyword; $right = $this->getAllDocumentsForKeyword($this->stemmer->stem($right), true, $isLastKeyword) ->pluck('doc_id'); } @@ -188,12 +188,12 @@ public function searchBoolean($phrase, $numOfResults = 100) $right = array_pop($stack); if (is_string($left)) { - $isLastKeyword = $left == $lastKeyword; + $isLastKeyword = $left == $lastKeyword; $left = $this->getAllDocumentsForKeyword($this->stemmer->stem($left), true, $isLastKeyword) ->pluck('doc_id'); } if (is_string($right)) { - $isLastKeyword = $right == $lastKeyword; + $isLastKeyword = $right == $lastKeyword; $right = $this->getAllDocumentsForKeyword($this->stemmer->stem($right), true, $isLastKeyword) ->pluck('doc_id'); }