protected function FuzzySearchService::createFilterCondition in Fuzzy Search 7
Helper method for creating a condition for filtering search results.
Return value
QueryConditionInterface Search results filter condition.
1 call to FuzzySearchService::createFilterCondition()
- FuzzySearchService::search in includes/
service.inc - Executes a search on the server represented by this object.
File
- includes/
service.inc, line 1172
Class
- FuzzySearchService
- Search service class using the database for storing index information.
Code
protected function createFilterCondition(SearchApiQueryFilterInterface $filter, array $fields, SelectQueryInterface $db_query) {
$cond = db_condition($filter
->getConjunction());
$empty = TRUE;
foreach ($filter
->getFilters() as $f) {
if (is_object($f)) {
$c = $this
->createFilterCondition($f, $fields, $db_query);
if ($c) {
$empty = FALSE;
$cond
->condition($c);
}
}
else {
$empty = FALSE;
if (!isset($fields[$f[0]])) {
throw new SearchApiException(t('Unknown field in filter clause: !field.', array(
'!field' => $f[0],
)));
}
if ($f[1] === NULL) {
$query = db_select($fields[$f[0]]['table'], 't')
->fields('t', array(
'item_id',
));
$cond
->condition('t.item_id', $query, $f[2] == '<>' || $f[2] == '!=' ? 'IN' : 'NOT IN');
continue;
}
if (search_api_is_text_type($fields[$f[0]]['type'])) {
// #negation is set here purely because we don't want any score.
$keys = array(
'#conjunction' => 'AND',
'#negation' => TRUE,
$f[1],
);
$keys = $this
->prepareKeys($keys);
$query = $this
->createKeysQuery($keys, array(
$fields[$f[0]],
), $fields);
$cond
->condition('t.item_id', $query, $f[2] == '<>' || $f[2] == '!=' ? 'NOT IN' : 'IN');
}
else {
$alias = $this
->getTableAlias($fields[$f[0]], $db_query, search_api_is_list_type($fields[$f[0]]['type']));
$cond
->condition($alias . '.value', $f[1], $f[2]);
}
}
}
return $empty ? NULL : $cond;
}