I have a search index for a content type (Publication) that has a list (integer) field named Publication Type.
I want to enable users to filter by the publication type field.
The field is indexed as an integer, and solr has correctly indexed the integer key for each node.
In my search view, I have exposed the Publication Type field and this displays a text field. If I enter an integer in to the field, it correctly returns nodes with that type.
What I'd like to be able to do is:
1) Search for multiple publication types at once. I've tried entering "1 OR 2" in to the exposed field (without the quotes), but this gets sent to Solr as "1 OR 2" with the quotes and therefore doesn't return any results (it's doing a string search rather than numeric). If I use the Solr Query interface and search for "1 or 2" without the quotes then it works fine, so I just need to get Drupal to send the value without the quotes... Any ideas how?
2) Once I've got step 1 working, I'd like to replace the text field with checkboxes for each type. The checkboxes would need to be labeled correctly (eg with the label, not the value) so users see a meaningful list of checkboxes.
I'd really appreciate any thoughts on how to approach this.
Comments
Comment #2
mkalkbrennerI think this support request is not Solr specific, but Search API in general or Views itself.
Since I'm not an expert in Views I move this request.
Comment #3
drunken monkey1) That's currently not supported, I think. You'd have to use a contextual filter for that (which support multi-valued input by default) or write your own filter handler (extending
SearchApiNumeric) that supports this.2) For that, there already is a filter plugin that should work in the Search API:
SearchApiOptions. However, as you can see in_search_api_views_get_handlers(), we currently have trouble finding out which fields should use that filter plugin. If you know of a way to detect the options list of a field, please tell us, that would be great to have fixed!Otherwise, you can just use
hook_views_data_alter()to set the Publication Type filter handler tosearch_api_options, plus an appropriateoptions callback, and it should work.Comment #4
nicrodgersGreat, thanks for your guidance.
As it happens, by setting the filter to search_api_options it automatically solves the first part too, as it makes the 'Is one of' operator available, and it seems to work just fine.
I've created a follow-up issue #2840675: Support for filtering list fields - using its options to automatically implement search_api_options for list fields.