Skip to content

Commit

Permalink
number of results
Browse files Browse the repository at this point in the history
  • Loading branch information
nticaric committed Apr 20, 2016
1 parent d4a77fd commit b37e238
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions src/TNTSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/indexer/IndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down

0 comments on commit b37e238

Please sign in to comment.