Problem/Motivation

The problem is how to sort the search results (which also implies selecting them based on the sort criteria) based on the entity label (e.g. node title) of the target entity pointed to by an entity reference field. The only search field added to the index for an entity reference field has a value of 'entity_type:entity_id' string. Assuming one entity type in the search results, all this potentially allows for is a sort on the target entity id, not particularly useful for the end user.

This request depends on a related issue (2617448) to even be able to sort on a single-valued field.

I am also suggesting the label field be the default search field because it is a simpler value than the target entity id and the related entity result.

In the course of solving this problem, I attempted to create a field (or field type) as suggested in hook_apachesolr_field_mappings in the api.php file. This does not appear to be a possibility as apachesolr_entity_fields() only considers the $field['type'] as a key in the $mappings array. The new field type that one might define is not related to any field API field, so the mapping is of no effect. If this anaysis is correct, I would suggest another issue to clarify the documentation. As support for this, consider the taxonomy term implementation in which the indexing callback defines multiple search fields for a single field API field type.

Proposed resolution

Add the label field to the indexing callback.

Remaining tasks

Reveiew and test.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

solotandem created an issue. See original summary.

solotandem’s picture

Status: Active » Needs review
StatusFileSize
new5.34 KB

Attached patch implements proposed resolution.