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);
// 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";