You are here

public function SearchApiSolrService::getFieldNames in Search API Solr 7

Create a list of all indexed field names mapped to their Solr field names.

The special fields "search_api_id" and "search_api_relevance" are also included. Any Solr fields that exist on search results are mapped back to to their local field names in the final result set.

See also

SearchApiSolrService::search()

7 calls to SearchApiSolrService::getFieldNames()
SearchApiSolrService::extractFacets in includes/service.inc
Extract facets from a Solr response.
SearchApiSolrService::extractResults in includes/service.inc
Extract results from a Solr response.
SearchApiSolrService::fieldsUpdated in includes/service.inc
Implements SearchApiServiceInterface::__construct().
SearchApiSolrService::getAutocompleteSuggestions in includes/service.inc
SearchApiSolrService::indexItems in includes/service.inc
Indexes the specified items.

... See full list

File

includes/service.inc, line 708

Class

SearchApiSolrService
Search service class using Solr server.

Code

public function getFieldNames(SearchApiIndex $index, $reset = FALSE) {
  if (!isset($this->fieldNames[$index->machine_name]) || $reset) {

    // This array maps "local property name" => "solr doc property name".
    $ret = array(
      'search_api_id' => 'item_id',
      'search_api_relevance' => 'score',
      'search_api_random' => 'random',
    );

    // Add the names of any fields configured on the index.
    $fields = isset($index->options['fields']) ? $index->options['fields'] : array();
    foreach ($fields as $key => $field) {

      // Generate a field name; this corresponds with naming conventions in
      // our schema.xml
      $type = $field['type'];

      // Use the real type of the field if the server supports this type.
      if (isset($field['real_type'])) {
        $custom_type = search_api_extract_inner_type($field['real_type']);
        if ($this
          ->supportsFeature('search_api_data_type_' . $custom_type)) {
          $type = $field['real_type'];
        }
      }
      $inner_type = search_api_extract_inner_type($type);
      $type_info = search_api_solr_get_data_type_info($inner_type);
      $pref = isset($type_info['prefix']) ? $type_info['prefix'] : '';
      if (empty($type_info['always multiValued'])) {
        $pref .= $type == $inner_type ? 's' : 'm';
      }
      if (!empty($this->options['clean_ids'])) {
        $name = $pref . '_' . str_replace(':', '$', $key);
      }
      else {
        $name = $pref . '_' . $key;
      }
      $ret[$key] = $name;
    }

    // Let modules adjust the field mappings.
    drupal_alter('search_api_solr_field_mapping', $index, $ret);
    $this->fieldNames[$index->machine_name] = $ret;
  }
  return $this->fieldNames[$index->machine_name];
}