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
|
<?php
class dbfts_pgsql 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();
$sortFields = array();
foreach($searchFields as $searchItem) {
$searchValue = trim($searchItem['value']);
$field = $searchItem['fieldname'];
/*
* if we get multiple textsearches, we sort them per order
* in the system
*/
$tmpSortCounter = count($additionalFields);
# Prepare the to_tsvector and to_tsquery strings
$ts_vector = "to_tsvector('Dutch', " . $field . ")";
$ts_query = "plainto_tsquery('Dutch', '" . $this->_db->safe(strtolower($searchValue)) . "')";
$filterValueSql[] = " " . $ts_vector . " @@ " . $ts_query;
$additionalFields[] = " ts_rank(" . $ts_vector . ", " . $ts_query . ") AS searchrelevancy" . $tmpSortCounter;
$sortFields[] = array('field' => 'searchrelevancy' . $tmpSortCounter,
'direction' => 'DESC',
'autoadded' => true,
'friendlyname' => null);
} # foreach
SpotTiming::stop(__FUNCTION__, array($filterValueSql,$additionalFields,$sortFields));
return array('filterValueSql' => $filterValueSql,
'additionalTables' => array(),
'additionalFields' => $additionalFields,
'sortFields' => $sortFields);
} # createTextQuery()
} # dbfts_abs
|