add optional parameter $col and $query to terms()

This commit is contained in:
Uwe Steinmann 2022-12-09 10:51:43 +01:00
parent 91c5b113b2
commit 68f19b87c3

View File

@ -334,16 +334,33 @@ class SeedDMS_SQLiteFTS_Indexer {
/** /**
* Return list of terms in index * Return list of terms in index
* *
* This function does nothing! * @return array list of SeedDMS_SQLiteFTS_Term
*/ */
public function terms() { /* {{{ */ public function terms($query='', $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 WHERE col!='*' ORDER BY col"; $sql = "SELECT term, col, doc as occurrences FROM docs_terms";
else if($query || $col) {
$sql = "SELECT term, col, occurrences FROM docs_terms WHERE col!='*' ORDER BY col"; $sql .= " WHERE";
if($query) {
$sql .= " term like '".$query."%'";
if($col)
$sql .= " AND";
}
if($col)
$sql .= " col = '".$col."'";
}
$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($col)
$sql .= " AND col = '".$col."'";
$sql .= " ORDER BY col, occurrences desc";
}
$res = $this->_conn->query($sql); $res = $this->_conn->query($sql);
$terms = array(); $terms = array();
if($res) { if($res) {