various minor improvements

This commit is contained in:
Uwe Steinmann 2023-01-08 16:22:52 +01:00
parent 593792089f
commit 71b8b197da

View File

@ -54,7 +54,7 @@ class SeedDMS_SQLiteFTS_Indexer {
$words = preg_split('/[^-\w\']+/u', $str, -1, PREG_SPLIT_NO_EMPTY); $words = preg_split('/[^-\w\']+/u', $str, -1, PREG_SPLIT_NO_EMPTY);
// 2.) if we have at least 2 words, remove stopwords // 2.) if we have at least 2 words, remove stopwords
if(count($words) > 1) { if(!empty($words)) {
$stopwords = $this->_stop_words; $stopwords = $this->_stop_words;
$words = array_filter($words, function ($w) use (&$stopwords) { $words = array_filter($words, function ($w) use (&$stopwords) {
return ((mb_strlen($w, 'utf-8') > 2) && !isset($stopwords[mb_strtolower($w, "utf-8")])); 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')) { if(file_exists($conf['indexdir'].'/index.db')) {
return new SeedDMS_SQLiteFTS_Indexer($conf['indexdir']); return new SeedDMS_SQLiteFTS_Indexer($conf['indexdir']);
} else } else
return self::create($conf); return static::create($conf);
} /* }}} */ } /* }}} */
/** /**
@ -183,8 +183,7 @@ class SeedDMS_SQLiteFTS_Indexer {
/** /**
* Remove document from index * Remove document from index
* *
* @param object $doc indexed document of class * @param object $id internal id of document
* SeedDMS_SQLiteFTS_IndexedDocument
* @return boolean false in case of an error, otherwise true * @return boolean false in case of an error, otherwise true
*/ */
public function delete($id) { /* {{{ */ public function delete($id) { /* {{{ */
@ -215,7 +214,7 @@ class SeedDMS_SQLiteFTS_Indexer {
* @return boolean false in case of an error, otherwise array with elements * @return boolean false in case of an error, otherwise array with elements
* 'count', 'hits', 'facets'. 'hits' is an array of SeedDMS_SQLiteFTS_QueryHit * '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) if(!$this->_conn)
return false; return false;
@ -392,16 +391,16 @@ class SeedDMS_SQLiteFTS_Indexer {
* *
* @return array list of SeedDMS_SQLiteFTS_Term * @return array list of SeedDMS_SQLiteFTS_Term
*/ */
public function terms($query='', $col='') { /* {{{ */ public function terms($prefix='', $col='') { /* {{{ */
if(!$this->_conn) if(!$this->_conn)
return false; return false;
if($this->_ftstype == 'fts5') { if($this->_ftstype == 'fts5') {
$sql = "SELECT term, col, doc as occurrences FROM docs_terms"; $sql = "SELECT term, col, doc as occurrences FROM docs_terms";
if($query || $col) { if($prefix || $col) {
$sql .= " WHERE"; $sql .= " WHERE";
if($query) { if($prefix) {
$sql .= " term like '".$query."%'"; $sql .= " term like '".$prefix."%'";
if($col) if($col)
$sql .= " AND"; $sql .= " AND";
} }
@ -411,8 +410,8 @@ class SeedDMS_SQLiteFTS_Indexer {
$sql .= " ORDER BY col, occurrences desc"; $sql .= " ORDER BY col, occurrences desc";
} else { } else {
$sql = "SELECT term, col, occurrences FROM docs_terms WHERE col!='*'"; $sql = "SELECT term, col, occurrences FROM docs_terms WHERE col!='*'";
if($query) if($prefix)
$sql .= " AND term like '".$query."%'"; $sql .= " AND term like '".$prefix."%'";
if($col) if($col)
$sql .= " AND col = '".$col."'"; $sql .= " AND col = '".$col."'";
$sql .= " ORDER BY col, occurrences desc"; $sql .= " ORDER BY col, occurrences desc";