Currently the field mapping retrieval is nested in the apachesolr_entity_fields() between lines 1937 and 1967. I have a use case where I need to be able to get the name of the field stored in Solr from the machine name of the field. The only way I can see hoe to do this is to replicate the code in the lines mentioned above, but if there was an API function to get the mappings this task would be a lot easier.

Comments

cpliakas’s picture

Status: Active » Needs work
StatusFileSize
new4.48 KB

First crack at a patch. Marking as needs work because I do not know what the "name callback" does.

You have to follow the code trail, but the use case is illustrated by the rich_snippets_get_solr_fields() function. This calls the apachesolr_get_index_key_map() function, which requires the API function posted in this patch.

nick_vh’s picture

part 1

        // @todo: for fields like taxonomy we are indexing multiple Solr fields
        // per entity field, but are keying on a single Solr field name here.
        $function = !empty($row['name callback']) ? $row['name callback'] : NULL;
        if ($function && is_callable($function)) {
          $row['name'] = $function($field);
        }
        else {
          $row['name'] = $field['field_name'];
        }

part 2

$fields[$entity_type][apachesolr_index_key($row)][] = $row;

part 3

  return substr($type_prefix . $sm . $field['name'], 0, 32);

so the name callback allows you to create a different name for the solr field. Nothing super critical, but flexible enough to allow custom implementations

cpliakas’s picture

Ah, I got you. So if I had an long integer field named "field_foo", I could change it to "field_bar" which would the would be stored in Solr as "i_field_bar". Is that about right?

nick_vh’s picture

Status: Needs work » Needs review

That is completely correct! Marking this as needs review to let the testbot grind

cpliakas’s picture

StatusFileSize
new4.71 KB

Re-rolling patch with a description of the "name callback" key.

nick_vh’s picture

Version: 7.x-1.x-dev » 6.x-3.x-dev
Status: Needs review » Patch (to be ported)

Needs backport to 6.x-3.x

nick_vh’s picture

Oh, just to clarify - this was committed. Thanks!

MickC’s picture

mkalkbrenner’s picture

Assigned: Unassigned » mkalkbrenner
Issue summary: View changes
Status: Patch (to be ported) » Needs review
StatusFileSize
new4.74 KB
mkalkbrenner’s picture

Status: Needs review » Fixed

  • Commit c1f8e18 on 6.x-3.x by mkalkbrenner:
    Issue #1825426 by cpliakas, mkalkbrenner: Add an API function...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.