I have a query about facets preselection. I have a custom facet which is mapped to a metadata field. We have configured the search to return full results for empty query. There is no option to preselect a facet option when you load the SERP. What is the best way to do the facet preselection when the SERP is loaded.
For eg:- I have a date facet with options
-Any Time
-last month
-Last week
-Yesterday
I want ‘Any time’ option to be selected at all times unless the user changes it to any other option
I can’t think what SERP is, but we pre-selected using the hook_pre_process.groovy file with this configuration:
if(transaction.question.profile == "research" || transaction.question.profile == "research_preview") { transaction.question.rawInputParameters["f.Category|category"] = ["Research","Teaching"] }
The code preselects the options ‘Research’ and ‘Teaching’ in the facet named ‘Category’ for the profiles research and research_preview.
I believe this keeps the facet option ‘Research’ & ‘Teaching’ permanently selected. In our case ‘Any Time’ needs to be defaulted initially when the result page is loaded but users still need to have the chance to select any of the facets after loading for the first time. Basically it should default to ‘Any Time’ if nothing else is selected.
I didn’t know, so I tested this. You’re correct that the facet options are permanent for that facet. I think that they’re re-applied on any change, but it amounts to the same thing. You can still change other facets in the normal way while these are selected.