take limits into account

This commit is contained in:
Uwe Steinmann 2020-09-14 16:34:21 +02:00
parent e14774110f
commit 397d542fb4

View File

@ -135,18 +135,30 @@ class SeedDMS_SQLiteFTS_Indexer {
/**
* Find documents in index
*
* @param object $doc indexed document of class
* SeedDMS_SQLiteFTS_IndexedDocument
* @return boolean false in case of an error, otherwise true
* @param string $query
* @param array $limit array with elements 'limit' and 'offset'
* @return boolean false in case of an error, otherwise array with elements
* 'count', 'hits', 'facets'
*/
public function find($query) { /* {{{ */
public function find($query, $limit=array()) { /* {{{ */
if(!$this->_conn)
return false;
$sql = "SELECT count(*) AS `c` FROM `docs`";
if($query)
$sql .= " WHERE docs MATCH ".$this->_conn->quote($query);
$res = $this->_conn->query($sql);
$row = $res->fetch();
$sql = "SELECT docid FROM docs";
if($query)
$sql .= " WHERE docs MATCH ".$this->_conn->quote($query);
$res = $this->_conn->query($sql);
if(!empty($limit['limit']))
$sql .= " LIMIT ".(int) $limit['limit'];
if(!empty($limit['offset']))
$sql .= " OFFSET ".(int) $limit['offset'];
$res = $this->_conn->query($sql);
$hits = array();
if($res) {
foreach($res as $rec) {
@ -155,7 +167,7 @@ class SeedDMS_SQLiteFTS_Indexer {
$hits[] = $hit;
}
}
return array('count'=>count($hits), 'hits'=>$hits);
return array('count'=>$row['c'], 'hits'=>$hits);
} /* }}} */
/**