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).
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 3311004-4--all_taxonomy_terms_filter_broken_for_custom_ids.patch | 2.01 KB | drunken monkey |
Comments
Comment #2
nsavitsky commentedComment #3
nsavitsky commentedComment #4
drunken monkeyThanks 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!
Comment #5
drunken monkeySorry, forgot the patch.
Comment #7
drunken monkeyMerged this now.
Thanks a lot again!