From 35e2f86dba710a6e3db2f18dcbdabc16d90c6a69 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Sat, 10 Dec 2022 12:58:37 +0100 Subject: [PATCH] add parameter $filter to find() --- SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php b/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php index c018e4d6a..10d3d63ae 100644 --- a/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php +++ b/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php @@ -179,15 +179,22 @@ 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, $limit=array(), $order=array()) { /* {{{ */ + public function find($query, $filter, $limit=array(), $order=array()) { /* {{{ */ if(!$this->_conn) return false; /* First count some records for facets */ foreach(array('owner', 'mimetype', 'category') as $facetname) { $sql = "SELECT `".$facetname."`, count(*) AS `c` FROM `docs`"; - if($query) + if($query) { $sql .= " WHERE docs MATCH ".$this->_conn->quote($query); + } + if($filter) { + if($query) + $sql .= " AND ".$filter; + else + $sql .= " WHERE ".$filter; + } $res = $this->_conn->query($sql." GROUP BY `".$facetname."`"); if(!$res) throw new SeedDMS_SQLiteFTS_Exception("Counting records in facet \"$facetname\" failed."); @@ -219,6 +226,12 @@ class SeedDMS_SQLiteFTS_Indexer { $sql = "SELECT `record_type`, count(*) AS `c` FROM `docs`"; if($query) $sql .= " WHERE docs MATCH ".$this->_conn->quote($query); + if($filter) { + if($query) + $sql .= " AND ".$filter; + else + $sql .= " WHERE ".$filter; + } $res = $this->_conn->query($sql." GROUP BY `record_type`"); if(!$res) throw new SeedDMS_SQLiteFTS_Exception("Counting records in facet \"record_type\" failed."); @@ -232,6 +245,12 @@ class SeedDMS_SQLiteFTS_Indexer { $sql = "SELECT ".$this->_rawid.", documentid FROM docs"; if($query) $sql .= " WHERE docs MATCH ".$this->_conn->quote($query); + if($filter) { + if($query) + $sql .= " AND ".$filter; + else + $sql .= " WHERE ".$filter; + } if($this->_ftstype == 'fts5') { //$sql .= " ORDER BY rank"; // boost documentid, record_type, title, comment, keywords, category, mimetype, origfilename, owner, content, created unindexed, users, status, path