Problem/Motivation

On our latest project we found out that "Search: All taxonomy term fields" always returns empty result set even though search index has a lot of taxonomy fields. The reason was found after some debugging - our index uses custom machine names for indexed fields.

The code which should provide mapping between taxonomy bundles and search fields uses Machine Name of the indexed field ($field->getFieldIdentifier(), which is manually editable) and compares it with field name of the entity. Please, take a look on the code from search_api_views.inc (starting from line 599)

$vocabulary_fields = [];
foreach ($index->getFields() as $field_id => $field) {
  ...
  $entity_type_id = $datasource->getEntityTypeId();
  $bundles = \Drupal::getContainer()->get('entity_type.bundle.info')
      ->getBundleInfo($entity_type_id);
  foreach ($bundles as $bundle_id => $bundle) {
    $bundle_fields = \Drupal::getContainer()->get('entity_field.manager')
      ->getFieldDefinitions($entity_type_id, $bundle_id);
    // Check if this bundle has the taxonomy entity reference field.
    if (array_key_exists($field->getFieldIdentifier(), $bundle_fields)) {
      ...
    }
  }
}

Steps to reproduce

Latest core, Search API v.1.25
Create index for any content type, add taxonomy reference field in to index but use custom machine name.
Create view based on the index, use "Search: All taxonomy term fields" and try to search. There will be no results.

Proposed resolution

I guess in the code for mapping (filling $vocabulary_fields variable) we need to use what is called Property Path of the indexed field instead of Machine Name (please, see attached screenshot).

Comments

nsavitsky created an issue. See original summary.

nsavitsky’s picture

Issue summary: View changes
nsavitsky’s picture

StatusFileSize
new1.05 KB
drunken monkey’s picture

Version: 8.x-1.25 » 8.x-1.x-dev
Status: Active » Needs review

Thanks a lot for reporting this problem, and sorry it took me so long to get back to you!
You’re right, this is obviously wrong, and your patch seems to be the correct solution. I just added some more checks while we’re at it – see the attached patch. Would be great if you could give it a try to see whether it still works for you.
In any case, thanks again!

drunken monkey’s picture

Sorry, forgot the patch.

drunken monkey’s picture

Status: Needs review » Fixed

Merged this now.
Thanks a lot again!

Status: Fixed » Closed (fixed)

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