Default Filters with Custom Widget
See original GitHub issueHi All,
I’m trying to get my head around using default filtering with custom widgets and I’ve come to a frustrating dead-end.
I have a car search function (make, model, price…) that I’m placing across a website and I need to search all makes and models etc which is working great, but in some places I need to default filter the search form by make e.g. Hyundai, but the rest of the makes still need to be selectable - basically a pre-selected value for an attribute - so I tried default filters (https://community.algolia.com/instantsearch.js/documentation/#default-filters).
Here’s what I’ve got so far:
var search = instantsearch({
[...],
urlSync: true,
searchParameters: {
facetsRefinements: {
make: ['Hyundai']
},
}
});
With this added, I only get the value ‘Hyundai’ in the drop down along with the title ‘All makes’ BUT I don’t get any ‘hits’. The error I get in the console is “Error: make is not defined in the facets attribute of the helper configuration”. I’ve googled and have seen a few solutions but none work for me. Reading the documentation on helpers, that made me more confused as I’m unsure as to how to “connect” helpers with instsantsearch when initiating searches.
I then read about facets that aren’t defined by adding to the above:
facets: ['make']
This then pulls back all hits that are only Hyundai but leaves my select dropdown completely blank (I imagine this overrides the custom widget use). I’ve got a feeling I’m approaching this in the wrong way as I all I need to is to a pre-selected value for the attributeName ‘make’ as if someone has already selected Hyundai.
Hopefully this is not too confusing! Any pointers would be great and many thanks in advance.
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (6 by maintainers)
Top GitHub Comments
Ok I think I just fixed it by doing this:
Let me know how it goes
Done https://github.com/algolia/instantsearch.js/commit/19756c331e2a2965a974f1b75c3ca36bf489b266