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 * Find documents in index
* *
* @param object $doc indexed document of class * @param string $query
* SeedDMS_SQLiteFTS_IndexedDocument * @param array $limit array with elements 'limit' and 'offset'
* @return boolean false in case of an error, otherwise true * @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) if(!$this->_conn)
return false; 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"; $sql = "SELECT docid FROM docs";
if($query) if($query)
$sql .= " WHERE docs MATCH ".$this->_conn->quote($query); $sql .= " WHERE docs MATCH ".$this->_conn->quote($query);
$res = $this->_conn->query($sql); $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(); $hits = array();
if($res) { if($res) {
foreach($res as $rec) { foreach($res as $rec) {
@ -155,7 +167,7 @@ class SeedDMS_SQLiteFTS_Indexer {
$hits[] = $hit; $hits[] = $hit;
} }
} }
return array('count'=>count($hits), 'hits'=>$hits); return array('count'=>$row['c'], 'hits'=>$hits);
} /* }}} */ } /* }}} */
/** /**