1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
<?php
class dbfts_sqlite extends dbfts_abs {
/*
* Constructs a query part to match textfields. Abstracted so we can use
* a database specific FTS engine if one is provided by the DBMS
*/
function createTextQuery($searchFields, $additionalFields) {
SpotTiming::start(__FUNCTION__);
/*
* Initialize some basic values which are used as return values to
* make sure always return a valid set
*/
$filterValueSql = array('(idx_fts_spots.rowid = s.rowid)');
$additionalTables = array('idx_fts_spots');
$matchList = array();
/*
* sqlite can only use one WHERE clause for all textstring matches,
* if you exceed this it throws an unrelated error and refuses the query
* so we have to collapse all textqueries into one query
*/
foreach($searchFields as $searchItem) {
$searchValue = trim($searchItem['value']);
/*
* The caller usually provides an expiciet table.fieldname
* for the select, but sqlite doesn't recgnize this in its
* MATCH statement so we remove it and hope there is no
* ambiguity
*/
$tmpField = explode('.', $searchItem['fieldname']);
$field = $tmpField[1];
$matchList[] = $field . ':' . $this->_db->safe($searchValue);
} # foreach
# add one WHERE MATCH conditions with all conditions
$filterValueSql[] = " (idx_fts_spots MATCH '" . implode(' ', $matchList) . "') ";
SpotTiming::stop(__FUNCTION__, array($filterValueSql,$additionalTables));
return array('filterValueSql' => $filterValueSql,
'additionalTables' => $additionalTables,
'additionalFields' => $additionalFields,
'sortFields' => array());
} # createTextQuery()
} # dbfts_sqlite
|