You are here

public function SarniaSolrService::getFieldNames in Sarnia 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.

Overrides SearchApiSolrService::getFieldNames

1 call to SarniaSolrService::getFieldNames()
SarniaSolrService::extractResults in ./service.inc
Extract results from a Solr response.

File

./service.inc, line 93

Class

SarniaSolrService
Search service class using Solr server.

Code

public function getFieldNames(SearchApiIndex $index, $reset = FALSE) {
  $ret = array();

  // Initially, map property Solr field names to themselves.
  $sarnia_entity_info = sarnia_entity_type_load_by_index($index->machine_name);
  if (!empty($index->options['fields'])) {
    foreach (array_keys($index->options['fields']) as $f) {
      $ret[$f] = $f;
    }
  }

  // We have some special property names which may override Solr field names.

  //@TODO these probably shouldn't override.
  $ret = array_merge($ret, array(
    // local property name => solr doc property name
    'search_api_id' => $sarnia_entity_info['id_field'],
    'search_api_relevance' => 'score',
    'search_api_item_id' => $sarnia_entity_info['id_field'],
    'search_api_random' => 'random_' . rand(1, 200),
  ));

  // Let modules adjust the field mappings.
  drupal_alter('search_api_solr_field_mapping', $index, $ret);
  return $ret;
}