You are here

public function SolrFilterSubQuery::makeFilterQuery in Apache Solr Search 8

Same name and namespace in other branches
  1. 6.3 Solr_Base_Query.php \SolrFilterSubQuery::makeFilterQuery()
  2. 7 Solr_Base_Query.php \SolrFilterSubQuery::makeFilterQuery()
1 call to SolrFilterSubQuery::makeFilterQuery()
SolrFilterSubQuery::rebuildFq in ./Solr_Base_Query.php
Builds a set of filter queries from $this->fields and all subqueries.

File

./Solr_Base_Query.php, line 123
This class allows you to make operations on a query that will be sent to Apache Solr. methods such as adding and removing sorts, remove and replace parameters, adding and removing filters, getters and setters for various parameters and more

Class

SolrFilterSubQuery
This class allows you to make operations on a query that will be sent to Apache Solr. methods such as adding and removing sorts, remove and replace parameters, adding and removing filters, getters and setters for various parameters and…

Code

public function makeFilterQuery(array $filter) {
  $prefix = empty($filter['#exclude']) ? '' : '-';
  if ($filter['#local']) {
    $prefix = '{!' . $filter['#local'] . '}' . $prefix;
  }

  // If the field value contains a colon or a space, wrap it in double quotes,
  // unless it is a range query or is already wrapped in double quotes or
  // parentheses.
  if (preg_match('/[ :]/', $filter['#value']) && !preg_match('/^[\\[\\{]\\S+ TO \\S+[\\]\\}]$/', $filter['#value']) && !preg_match('/^["\\(].*["\\)]$/', $filter['#value'])) {
    $filter['#value'] = '"' . $filter['#value'] . '"';
  }
  return $prefix . $filter['#name'] . ':' . $filter['#value'];
}