From 9a02543b5e197a36842ac81da3d0a0bbb0bae084 Mon Sep 17 00:00:00 2001 From: Nenad Ticaric Date: Fri, 14 Jul 2023 11:08:20 +0200 Subject: [PATCH] refactor --- src/Contracts/EngineContract.php | 2 +- src/Engines/RedisEngine.php | 2 +- src/Engines/SqliteEngine.php | 10 +++++++--- tests/TNTSearchTest.php | 1 - 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Contracts/EngineContract.php b/src/Contracts/EngineContract.php index 467b493..0b6c220 100644 --- a/src/Contracts/EngineContract.php +++ b/src/Contracts/EngineContract.php @@ -14,7 +14,7 @@ public function saveToIndex($stems, $docId); public function selectIndex($indexName); public function saveWordlist($stems); public function saveDoclist($terms, $docId); - public function saveHitList(); + public function saveHitList($stems, $docId, $termsList); public function delete($documentId); public function totalDocumentsInCollection(); public function getWordFromWordList($word); diff --git a/src/Engines/RedisEngine.php b/src/Engines/RedisEngine.php index b8f50f7..442c144 100644 --- a/src/Engines/RedisEngine.php +++ b/src/Engines/RedisEngine.php @@ -205,7 +205,7 @@ public function saveDoclist($terms, $docId) } } - public function saveHitList() + public function saveHitList($stems, $docId, $termsList) { return; } diff --git a/src/Engines/SqliteEngine.php b/src/Engines/SqliteEngine.php index 51be9bf..4df25f0 100644 --- a/src/Engines/SqliteEngine.php +++ b/src/Engines/SqliteEngine.php @@ -56,9 +56,7 @@ public function createIndex($indexName) { $this->indexName = $indexName; - if (file_exists($this->config['storage'] . $indexName)) { - unlink($this->config['storage'] . $indexName); - } + $this->flushIndex($indexName); $this->index = new PDO('sqlite:' . $this->config['storage'] . $indexName); $this->index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); @@ -666,4 +664,10 @@ public function getAllDocumentsForFuzzyKeyword($words, $noLimit) return new Collection($stmtDoc->fetchAll(PDO::FETCH_ASSOC)); } + public function flushIndex($indexName) + { + if (file_exists($this->config['storage'] . $indexName)) { + unlink($this->config['storage'] . $indexName); + } + } } diff --git a/tests/TNTSearchTest.php b/tests/TNTSearchTest.php index cf7ca78..fb2befc 100644 --- a/tests/TNTSearchTest.php +++ b/tests/TNTSearchTest.php @@ -14,7 +14,6 @@ class TNTSearchTest extends PHPUnit\Framework\TestCase 'engine' => 'TeamTNT\TNTSearch\Engines\RedisEngine', 'redis_host' => '127.0.0.1', 'redis_port' => '6379', - 'engine' => 'TeamTNT\TNTSearch\Engines\RedisEngine', 'database' => __DIR__ . '/_files/articles.sqlite', 'host' => 'localhost', 'username' => 'testUser',