You are here

public static function SarniaSolrService::phrase in Sarnia 7

Used instead of SearchApiSolrConnection::phrase, since the original method's quoting makes it impossible to use wildcards or other quoting.

This phrase escaping allows wildcards, AND and OR, and double quotes.

1 call to SarniaSolrService::phrase()
SarniaSolrService::formatFilterValue in ./service.inc
Override SearchApiSolrService::formatFilterValue() because it relies on SearchApiSolrConnection::phrase().

File

./service.inc, line 392

Class

SarniaSolrService
Search service class using Solr server.

Code

public static function phrase($value) {

  // Escape slashes.
  $value = str_replace('\\', '\\\\', $value);

  // Escape colons, parenthesis, brackets, and square brackets.
  // @see http://us3.php.net/preg_replace
  $value = preg_replace('/[:(){}\\[\\]]/', '\\\\\\0', $value);

  // Escape search operators or wildcards appearing at the beginning of the value.
  $value = preg_replace('/^(AND|OR|NOT|\\*|[+-])/', '\\\\\\0', $value);

  // Escape unmatched double quotes.
  if (substr_count($value, '"') % 2 != 0) {
    $value = str_replace('"', '\\"', $value);
  }
  return $value;
}