TeamTNT\TNTSearch\TNTSearch::totalDocumentsInCollection PHP Method

totalDocumentsInCollection() public method

    public function totalDocumentsInCollection()
    {
        $query = "SELECT * FROM info WHERE key = 'total_documents'";
        $docs = $this->index->query($query);
        return $docs->fetch(PDO::FETCH_ASSOC)['value'];
    }

Usage Example

Example #1
0
 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']);
     $this->assertEquals(12, $tnt->totalDocumentsInCollection());
     $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');
     $this->assertEquals(13, $tnt->totalDocumentsInCollection());
     $res = $tnt->search('Othello');
     $this->assertEquals([13], $res['ids']);
 }