You are here

protected function Solr_Base_Query::parse_filters in Apache Solr Search 5.2

Same name and namespace in other branches
  1. 6 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 412

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 (count($extracted)) {
      foreach ($extracted as $filter) {
        $pos = strpos($this->filterstring, $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);
}