From 397d542fb43832e26ee1f452f87a6309da0a3a60 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Mon, 14 Sep 2020 16:34:21 +0200 Subject: [PATCH] take limits into account --- SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php b/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php index 0cd802877..d6c40c278 100644 --- a/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php +++ b/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php @@ -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); } /* }}} */ /**