From 71b8b197da23ec72cdab7e7227bf29f5c04508a1 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Sun, 8 Jan 2023 16:22:52 +0100 Subject: [PATCH] various minor improvements --- SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php b/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php index 506af59bc..ed86ce32e 100644 --- a/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php +++ b/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php @@ -54,7 +54,7 @@ class SeedDMS_SQLiteFTS_Indexer { $words = preg_split('/[^-\w\']+/u', $str, -1, PREG_SPLIT_NO_EMPTY); // 2.) if we have at least 2 words, remove stopwords - if(count($words) > 1) { + if(!empty($words)) { $stopwords = $this->_stop_words; $words = array_filter($words, function ($w) use (&$stopwords) { return ((mb_strlen($w, 'utf-8') > 2) && !isset($stopwords[mb_strtolower($w, "utf-8")])); @@ -90,7 +90,7 @@ class SeedDMS_SQLiteFTS_Indexer { if(file_exists($conf['indexdir'].'/index.db')) { return new SeedDMS_SQLiteFTS_Indexer($conf['indexdir']); } else - return self::create($conf); + return static::create($conf); } /* }}} */ /** @@ -183,8 +183,7 @@ class SeedDMS_SQLiteFTS_Indexer { /** * Remove document from index * - * @param object $doc indexed document of class - * SeedDMS_SQLiteFTS_IndexedDocument + * @param object $id internal id of document * @return boolean false in case of an error, otherwise true */ public function delete($id) { /* {{{ */ @@ -215,7 +214,7 @@ class SeedDMS_SQLiteFTS_Indexer { * @return boolean false in case of an error, otherwise array with elements * 'count', 'hits', 'facets'. 'hits' is an array of SeedDMS_SQLiteFTS_QueryHit */ - public function find($query, $filter, $limit=array(), $order=array()) { /* {{{ */ + public function find($query, $filter='', $limit=array(), $order=array()) { /* {{{ */ if(!$this->_conn) return false; @@ -392,16 +391,16 @@ class SeedDMS_SQLiteFTS_Indexer { * * @return array list of SeedDMS_SQLiteFTS_Term */ - public function terms($query='', $col='') { /* {{{ */ + public function terms($prefix='', $col='') { /* {{{ */ if(!$this->_conn) return false; if($this->_ftstype == 'fts5') { $sql = "SELECT term, col, doc as occurrences FROM docs_terms"; - if($query || $col) { + if($prefix || $col) { $sql .= " WHERE"; - if($query) { - $sql .= " term like '".$query."%'"; + if($prefix) { + $sql .= " term like '".$prefix."%'"; if($col) $sql .= " AND"; } @@ -411,8 +410,8 @@ class SeedDMS_SQLiteFTS_Indexer { $sql .= " ORDER BY col, occurrences desc"; } else { $sql = "SELECT term, col, occurrences FROM docs_terms WHERE col!='*'"; - if($query) - $sql .= " AND term like '".$query."%'"; + if($prefix) + $sql .= " AND term like '".$prefix."%'"; if($col) $sql .= " AND col = '".$col."'"; $sql .= " ORDER BY col, occurrences desc";