Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple calls to search method does not return expected results #19

Closed
michaeldim opened this issue Jun 15, 2016 · 3 comments
Closed

Comments

@michaeldim
Copy link
Contributor

michaeldim commented Jun 15, 2016

When I try to use the search method in multiple calls it does not return result after adding the value to the index.

For example:

public function test()
    {
        $this->loadConfig();

        if (!file_exists(storage_path('/app/events.index'))) {
            $this->tnt->createIndex('events.index');
        }

        $this->tnt->selectIndex('events.index');

        $str = 'test';

        $this->tnt->search($str);  // returns no results as expected

        $index = $this->tnt->getIndex();
        $index->insert(['id' => 1, 'name' => $str]);

        $this->tnt->search($str);  // should return 'test' as a result from the index but returns 'ids' array as null
    }
@nticaric
Copy link
Contributor

Can you write a failing unit test for this so I can try to fix it?

@michaeldim
Copy link
Contributor Author

No problem. This is the failing test:

public function testMultipleSearch()
    {
        $tnt = new TNTSearch;

        $tnt->loadConfig($this->config);

        $indexer                = $tnt->createIndex($this->indexName);
        $indexer->disableOutput = true;
        $indexer->query('SELECT id, title, article FROM articles;');
        $indexer->run();

        $tnt->selectIndex($this->indexName);

        $res = $tnt->search('Othello');
        $this->assertEmpty($res['ids']);

        $index = $tnt->getIndex();

        $count = $index->countWordInWordList('Othello');
        $this->assertTrue($count == 0, 'Word Othello should be 0');
        $index->insert(['id' => '13', 'title' => 'Othello', 'article' => 'For she had eyes and chose me.']);

        $count = $index->countWordInWordList('Othello');
        $this->assertEquals(1, $count, 'Word Othello should be 1');

        $res = $tnt->search('Othello');
        $this->assertEquals([13], $res['ids']);

    }

nticaric added a commit that referenced this issue Jun 21, 2016
@nticaric
Copy link
Contributor

Thanks for spotting this. It should be fixed in version v.0.6.4

sleepless pushed a commit to sleepless/tntsearch that referenced this issue Oct 25, 2017
* commit '3d81cc2cac3bea2ac7041fe2ea3ec92f379c80cc':
  added config for testing.poporder-seg.de
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants