mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-13 21:21:27 +00:00
add optional parameter $order to find()
This commit is contained in:
parent
6341e13ca6
commit
91c5b113b2
|
@ -179,7 +179,7 @@ class SeedDMS_SQLiteFTS_Indexer {
|
||||||
* @return boolean false in case of an error, otherwise array with elements
|
* @return boolean false in case of an error, otherwise array with elements
|
||||||
* 'count', 'hits', 'facets'. 'hits' is an array of SeedDMS_SQLiteFTS_QueryHit
|
* 'count', 'hits', 'facets'. 'hits' is an array of SeedDMS_SQLiteFTS_QueryHit
|
||||||
*/
|
*/
|
||||||
public function find($query, $limit=array()) { /* {{{ */
|
public function find($query, $limit=array(), $order=array()) { /* {{{ */
|
||||||
if(!$this->_conn)
|
if(!$this->_conn)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -232,10 +232,26 @@ class SeedDMS_SQLiteFTS_Indexer {
|
||||||
$sql = "SELECT ".$this->_rawid.", documentid FROM docs";
|
$sql = "SELECT ".$this->_rawid.", documentid FROM docs";
|
||||||
if($query)
|
if($query)
|
||||||
$sql .= " WHERE docs MATCH ".$this->_conn->quote($query);
|
$sql .= " WHERE docs MATCH ".$this->_conn->quote($query);
|
||||||
if($this->_ftstype == 'fts5')
|
if($this->_ftstype == 'fts5') {
|
||||||
//$sql .= " ORDER BY rank";
|
//$sql .= " ORDER BY rank";
|
||||||
// boost documentid, title and comment
|
// boost documentid, record_type, title, comment, keywords, category, mimetype, origfilename, owner, content, created unindexed, users, status, path
|
||||||
$sql .= " ORDER BY bm25(docs, 10.0, 10.0, 10.0)";
|
if(!empty($order['by'])) {
|
||||||
|
switch($order['by']) {
|
||||||
|
case "title":
|
||||||
|
$sql .= " ORDER BY title";
|
||||||
|
break;
|
||||||
|
case "created":
|
||||||
|
$sql .= " ORDER BY created";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$sql .= " ORDER BY bm25(docs, 10.0, 0.0, 10.0, 5.0, 5.0, 10.0)";
|
||||||
|
}
|
||||||
|
if(!empty($order['dir'])) {
|
||||||
|
if($order['dir'] == 'desc')
|
||||||
|
$sql .= " DESC";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if(!empty($limit['limit']))
|
if(!empty($limit['limit']))
|
||||||
$sql .= " LIMIT ".(int) $limit['limit'];
|
$sql .= " LIMIT ".(int) $limit['limit'];
|
||||||
if(!empty($limit['offset']))
|
if(!empty($limit['offset']))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user