diff --git a/composer.lock b/composer.lock index 405cfc9..2fc17fe 100644 --- a/composer.lock +++ b/composer.lock @@ -458,16 +458,16 @@ }, { "name": "phpunit/phpunit", - "version": "5.3.1", + "version": "5.3.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "34a3acb401ae79deb37bc6e5f5ec3d325b369b4c" + "reference": "2c6da3536035617bae3fe3db37283c9e0eb63ab3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/34a3acb401ae79deb37bc6e5f5ec3d325b369b4c", - "reference": "34a3acb401ae79deb37bc6e5f5ec3d325b369b4c", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2c6da3536035617bae3fe3db37283c9e0eb63ab3", + "reference": "2c6da3536035617bae3fe3db37283c9e0eb63ab3", "shasum": "" }, "require": { @@ -529,7 +529,7 @@ "testing", "xunit" ], - "time": "2016-04-07 07:04:34" + "time": "2016-04-12 16:20:08" }, { "name": "phpunit/phpunit-mock-objects", diff --git a/src/TNTSearch.php b/src/TNTSearch.php index 7975d9f..0b57dea 100644 --- a/src/TNTSearch.php +++ b/src/TNTSearch.php @@ -143,7 +143,7 @@ public function searchBoolean($phrase, $numOfResults = 100) $stack[] = array_unique(array_merge($left, $right)); } else if ($token == '~') { - $left = array_pop($stack); + $left = array_pop($stack); if (is_string($left)) { $left = $this->getAllDocumentsForWhereKeywordNot($this->stemmer->stem($left), true) ->pluck('doc_id'); @@ -162,8 +162,16 @@ public function searchBoolean($phrase, $numOfResults = 100) $docs = new Collection; } + $counter = 0; + $docs = $docs->filter(function ($item) use (&$counter, $numOfResults) { + $counter++; + if ($counter <= $numOfResults) { + return $item; + } + }); + $stopTimer = microtime(true); - + if ($this->isFileSystemIndex()) { return $this->filesystemMapIdsToPaths($docs)->toArray(); } diff --git a/tests/indexer/IndexerTest.php b/tests/indexer/IndexerTest.php index cdaef48..c7be120 100644 --- a/tests/indexer/IndexerTest.php +++ b/tests/indexer/IndexerTest.php @@ -29,7 +29,7 @@ public function testSearch() $tnt->selectIndex($this->indexName); $tnt->asYouType = true; $res = $tnt->search('Juliet'); - $this->assertEquals([9, 5, 6, 7, 8], $res['ids']); + $this->assertEquals([9, 5, 6, 7, 8, 10], $res['ids']); $res = $tnt->search('Queen Mab'); $this->assertEquals([7], $res['ids']);