You are here

protected function Solr_Base_Query::parse_filters in Apache Solr Search 6

Same name and namespace in other branches
  1. 5.2 Solr_Base_Query.php \Solr_Base_Query::parse_filters()
  2. 6.2 Solr_Base_Query.php \Solr_Base_Query::parse_filters()

Parse the filter string in $this->filters into $this->fields.

Builds an array of field name/value pairs.

3 calls to Solr_Base_Query::parse_filters()
Solr_Base_Query::add_field_aliases in ./Solr_Base_Query.php
Handle aliases for field to make nicer URLs
Solr_Base_Query::clear_field_aliases in ./Solr_Base_Query.php
Solr_Base_Query::__construct in ./Solr_Base_Query.php

File

./Solr_Base_Query.php, line 407

Class

Solr_Base_Query

Code

protected function parse_filters() {
  $this->fields = array();
  $parsed_fields = array();
  $filterstring = $this->filterstring;

  // Gets information about the fields already in solr index.
  $index_fields = $this->solr
    ->getFields();
  foreach ((array) $index_fields as $name => $data) {

    // Look for a field alias.
    $alias = isset($this->field_map[$name]) ? $this->field_map[$name] : $name;

    // Get the values for $name
    $extracted = $this
      ->filter_extract($filterstring, $alias);
    if (!empty($extracted)) {

      // A trailing space is required since we match all individual
      // filter terms using a trailing space.
      $filter_pos_string = $this->filterstring . ' ';
      foreach ($extracted as $filter) {

        // The trailing space on $filter['#query'] avoids incorrect
        // matches to a substring. See http://drupal.org/node/891962
        $pos = strpos($filter_pos_string, $filter['#query'] . ' ');

        // $solr_keys and $solr_crumbs are keyed on $pos so that query order
        // is maintained. This is important for breadcrumbs.
        $filter['#name'] = $name;
        $parsed_fields[$pos] = $filter;
      }
    }
  }

  // Even though the array has the right keys they are likely in the wrong
  // order. ksort() sorts the array by key while maintaining the key.
  ksort($parsed_fields);
  foreach ($this->fields_removed as $name => $values) {
    foreach ($values as $val) {
      $this
        ->unset_filter($parsed_fields, $name, $val);
    }
  }
  $this->fields = array_merge(array_values($parsed_fields), $this->fields_added);
}