Am I missing something, or did this issue #1477938: Boolean facet label never get addressed in the Search API module?
Problem/Motivation
Boolean Facets have no labels.
Proposed resolution
Map Boolean facet values to human readable values.
Remaining tasks
Patch to be written and tested.
User interface changes
This could possibly be added as a configuration option for the facet display settings, allowing the user to specify the values to be used for the labels on a per facet basis.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 1878606-7--boolean_facet_labels.patch | 3.21 KB | drunken monkey |
| #6 | 1878606-6--boolean_facet_labels.patch | 3.21 KB | drunken monkey |
| #5 | 1878606-5--boolean_facet_labels.patch | 3.03 KB | drunken monkey |
Comments
Comment #1
jantoine commentedOK... so I did some digging and found the _search_api_facetapi_facet_create_label() function, which seems to handle Boolean facet values as a last resort. Unfortunately, my values never make it that far, as they are caught in a earlier section of code meant to handle option lists. Following the rabbit trail, we eventually end up in the entity_metadata_field_options_list() function in the callbacks.inc file of the Entity API module, where a module_invoke() is called with NULL $field and $instance variables eventual returning an array with two empty strings to the _search_api_facetapi_facet_create_label() function, which is then used as labels for my Boolean values.
I am changing this to a bug report as it appears it has already been implemented but is not working correctly! Please let me know if I can provide any other information.
Comment #2
jantoine commentedI discovered today that this is only happening when the display widget is set to 'Links with checkboxes'! When the widget is set to 'Links', the true/false values show up.*Edit: Not sure how the above was ever possible, but I cannot reproduce it.
Comment #3
jantoine commentedOK... I could be wrong, but this seems to be a core issue with the Options List sub-module not returning default allowed values, but instead is returning empty strings. Per the 'On value' help text 'If left empty, "1" will be used.' and the 'Off value' help text 'If left empty, "0" will be used.', I would expect the list_allowed_values() function to return the following:
but instead, it returns the following:
Comment #4
neRok commentedI was working on a patch for list_allowed_values() mentioned in #3.
#1793432: For boolean with empty values, list_allowed_values() should return array('0', '1')
In summary of that issue, list_allowed_values() function needs to return empty strings if no values were set, otherwise there will be 0 and 1's popping up on nodes when you in fact wanted an empty string.
It is recommended that Search API checks for empty string and does something appropriate. You need to remember that people may actually want empty strings though, you cant just go making 0 and 1 labels in results, but for 'settings' pages, 0 and 1 might be fine.
Comment #5
drunken monkeyI don't think people want empty labels for facet links – that would look rather weird for end users.
Here, at any rate, is a patch which tries to fix the label creating function by only taking non-empty values into the mapping, and only returning early if all values have been mapped.
Please test if it solves your problems!
Comment #6
drunken monkeyFound some bugs, revised patch attached.
Comment #7
drunken monkeyAnd another (though it shouldn't have been any real problem).
Comment #8
drunken monkeyCommitted.