You are here

private function Solr_Base_Query::parse_query in Apache Solr Search 5

1 call to Solr_Base_Query::parse_query()
Solr_Base_Query::__construct in ./Solr_Base_Query.php

File

./Solr_Base_Query.php, line 226

Class

Solr_Base_Query

Code

private function parse_query() {
  $this->_fields = array();
  $_keys = $this->_query;

  // Gets information about the fields already in solr index.
  $index_fields = Solr_Base_Query::get_fields_in_index();
  $rows = array();
  foreach ((array) $index_fields as $name => $field) {
    do {

      // save the strlen so we can detect if it has changed at the bottom
      // of the do loop
      $a = (int) strlen($_keys);

      // Get the values for $name
      $values = Solr_Base_Query::query_extract($_keys, $name);
      if (count($values) > 0) {
        foreach ($values as $value) {
          $found = Solr_Base_Query::make_field(array(
            '#name' => $name,
            '#value' => $value,
          ));
          $pos = strpos($this->_query, $found);

          // $solr_keys and $solr_crumbs are keyed on $pos so that query order
          // is maintained. This is important for breadcrumbs.
          $this->_fields[$pos] = array(
            '#name' => $name,
            '#value' => trim($value),
          );
        }

        // Update the local copy of $_keys by removing the key that was just found.
        $_keys = trim(Solr_Base_Query::query_replace($_keys, $name));
      }

      // Take new strlen to compare with $a.
      $b = (int) strlen($_keys);
    } while ($a !== $b);

    // Clean up by adding remaining keywords.
    if (!empty($_keys)) {
      $pos = strpos($this->_query, $_keys);
      $this->_fields[$pos] = array(
        '#name' => '',
        '#value' => trim($_keys),
      );
    }
  }

  // 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($this->_fields);
}