Fix #146 : add a way to make queries that don't change the inner state #193
Conversation
This has been made in order to be able to reuse the way the requests for the client without relying on a complete helper. This way we can create requests just based on the search state.
```js | ||
var state = | ||
helper.searchOnce( | ||
helper.state.addFacetRefinement('facet', 'f2');, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small typo, trailing ;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would start with a simpler example instead of calling addFacetRefinement
, something like:
helper.searchOnce({hitsPerPage: 1}, function(error, content, state) { /*... */ });
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok makes sense. Actually I think this way of expressing the mutation of the state is nice but it involves creating a full new search state each time we call one of the methods which is not that wise...
Since // search for the 3 first best (distinct) hits
helper.searchOnce({query: 'foo', disjunctiveFacets: [], facets: [], distinct: true, hitsPerPage: 3}, fn); |
Do you mean you want to avoid any other queries other than the main one (the one that does the search with all the filters)? |
Conflicts: dist/algoliasearch.helper.js dist/algoliasearch.helper.min.js src/algoliasearch.helper.js
Yes, because most of the time the "extra" query we want to do is only to fetch "special" hits (like a query retrieving the top 3 products with |
Yaw. About helper.once('result'); So I thought that searchOnce could be understood as something related to the |
From what I see in the code, we do send the refinements wether or not we have facets or disjunctive facets set. So if the engine let us do that then we're good :)
Ok I get it! I don't think it'll be that much of a problem because we are assuming people are reading the documentation to get information about the API and we don't put too much emphasise on |
Yes it should be ok.
Exactly |
So after all, are we good to go on this PR? :) |
LGTM |
Cool :) Mergin' |
Fix #146 : add a way to make queries that don't change the inner state
For future PRs, can we agree not to commit the builded files? We should only build when releasing (I guess it was a mistake maybe) |
Yes sure :) |
…eature/searchOnce Fix algolia/algoliasearch-helper-js#146 : add a way to make queries that don't change the inner state
Introducing searchOnce, a method to query an index without modifying the state stored in the helper.