mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-02-06 07:04:57 +00:00
take limits into account
This commit is contained in:
parent
e14774110f
commit
397d542fb4
|
@ -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);
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user