Attached patch adds support for indexing the labels of options lists. While search api automatically adds the labels of selected values in if the field gets fulltext indexed, sometimes its of advantage to have it as a separate field. My use case for that is providing a facet of a list field with allowed values being translated via i18n_field, whereas the facet is using the (translated) label as value (and in the URL).
(For adding in the i18n_field translation you'll need the latest entity api dev version for which I've just added support.)
So the attached patch does that by providing an alter callback, which provides a property everything having options lists declared. The code would work with arbitrary hierarchies, however unfortunately it turned out search api does not alter property info of the wrappers recursively, so it only works on the first level. Consequently, I've disabled hierarchy>1 support in the patch for now.
Comment | File | Size | Author |
---|---|---|---|
d7_search_api_options_list_label.patch | 4.25 KB | fago | |
Comments
Comment #1
drunken monkeyThanks a lot for your suggestion and the patch. I can only see one problem:
To quote your own module's documentation (
hook_entity_property_info()
):So please use something else as the suffix.
However, apart from this, I'm not sure this is generally useful enough to warrant addition to this module directly. So, unless others start requesting this, I don't think I will add this patch, sorry!
Someone should really finally start a "Search API Bonus" module/project for such things …
Comment #2
fagosearch API bonus sounds like a good idea. Could you think of a good suffix to add? If we go with a valid name, we might have bad luck and end up with clashing names.
Comment #3
drunken monkeysearch_api_bonus
should be fine, I think. I can't think of any hook or functions that starts with "bonus".But yes, that's of course always a problem in Drupal currently. Thanks god proper namespaces are coming … ;)
Comment #4
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedAny ideas how to do it in D8 (in Search API Core) or do we need an additional module?
Comment #5
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedI think we could leverage \Drupal\Core\TypedData\OptionsProviderInterface here.
Comment #6
drunken monkeySince it's not so simple anymore to get options lists in D8's Entity API, I guess the automatic indexing of options labels for fulltext fields got dropped in D8. For that, you should probably write a separate processor that does this. If it works well enough, we could then also add it to this module, I guess.