-
Notifications
You must be signed in to change notification settings - Fork 504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to pass default SearchParameters #1342
Comments
Really need this. In my own index, I have by default set distinct = true But in my UI I have use cases where I want to set it to false. |
This is planned and need to be done, yes |
Hi @vvo I was trying to find how to do it with current beta 13. Any leads? |
I would suggest you to clone the projet, create a new "Connector" see how the searchBox connector is done, then see how a generic "configure" component could be done. Should be doable, but you will have to dig in the docs (making your own widget: https://community.algolia.com/instantsearch.js/react/Customization.html) and the code. Good luck. |
Got it, I was looking for this page only. It wasnt linked in the current new docs. |
Thanks I used the hits connecter from docs https://github.com/algolia/instantsearch.js/blob/v2/packages/react-instantsearch/src/widgets/Hits/connect.js My getSearchParameters looks like this now. getSearchParameters(searchParameters, props) {
// set distinct to false.
searchParameters = searchParameters.setQueryParameter("distinct", false);
if (
typeof props.hitsPerPage !== 'undefined' &&
typeof searchParameters.hitsPerPage === 'undefined'
) {
return searchParameters.setHitsPerPage(props.hitsPerPage);
}
return searchParameters;
} |
Awesome! Utilmately we need a simpler API to do that. |
What about a function passed as a prop on InstantSearch with the signature |
Not sure to get what you are proposing |
Updated my comment @vvo |
Yes it is easier to manipulate an existing state rather than having to provide an API to create a state. As for an option on var WithGeo = <Configure state={state => state.addQueryParameters('geo', '...')} />
var WithDistinct = <Configure state={state => state.addQueryParameters('geo', '...')} />
// later on..
<WithGeo/><WithDistinct/>
// and remove them when needed. I guess the same is achievable with just a function on |
That's an interesting declarative Api using configure. What do you think @mthuret? |
Having a function that configure SearchParameter on the component feel more natural to me than having several widget. But if it's really easier for changing refinements dynamically that's a real advantage. In either case that's great, I will need this feature in a near future :) |
Sorry the example was misleading, we won't have several widget, only one The issue I see if we put it as an option on This is a good investigation issue. |
I've given some thoughts 🤔 on the
The function on var WithGeo = state => state.addQueryParameter('geo', '...')};
var WithDistinct = state => state.addQueryParameter('distinct', '...')};
// later on..
<InstantSearch searchStateConfig={withGeo}/>
// Or
<InstantSearch searchStateConfig={withGeo}/>
// And it can be composed too
<InstantSearch searchStateConfig={s => withDistinct(withGeo(s)) }/> Also:
I suggest we go for a prop on |
WFM, I think I was up and proposed for the |
(Also don't try to millennial-convince us lowl) |
it always works better to convey the messsage 😸 |
With our focus on widget states, we missed one important usecase: being able to define simple SearchParameters that will always be sent.
This goes back to the idea of @bobylito of having a
<Configure/>
widget. For instance we could imagine having such simple<Configure/>
widget that we pass a state to search parameters function that will allow users to set distinct=true for instance or any other Search parameter.What do you think?
The text was updated successfully, but these errors were encountered: