You are here

static function Solr_Base_Query::query_extract in Apache Solr Search 5

This is copied from search module. The search module implementation doesn't handle quoted terms correctly (bug) and this function is copied here until I have the bugfix perfected, at which point a patch will be submitted to search module with the goal of removing the function here.

Extract a module-specific search option from a search query. e.g. 'type:book'

2 calls to Solr_Base_Query::query_extract()
Solr_Base_Query::parse_query in ./Solr_Base_Query.php
Solr_Base_Query::query_replace in ./Solr_Base_Query.php
Replaces all occurances of $option in $keys.

File

./Solr_Base_Query.php, line 30

Class

Solr_Base_Query

Code

static function query_extract($keys, $option) {
  $pattern = '/(^| )' . $option . ':(\\"([^\\"]*)\\")/i';
  preg_match_all($pattern, $keys, $matches);
  if (!empty($matches[2])) {

    // The preg_replace removes beginning and trailing quotations.
    return preg_replace('/^"|"$/', '', $matches[2]);
  }
  $pattern = '/(^| )' . $option . ':([^ ]*)/i';
  if (preg_match_all($pattern, $keys, $matches)) {
    if (!empty($matches[2])) {
      return $matches[2];
    }
  }
}