Add a way to make a inline query with different parameters #146
Comments
Would the following suits your needs : helperInstance.searchOnce( specificParameters, function( results, state ){
// specificParameters is an object merged with the current search state, meaning that it overrides only the properties needed
// results is of type SearchResults and state is of type
// Do here your specific search behavior
} ); If we want to be fancy, we could support the double callback/promise API of the client (and it would make sense) What do you think @vvo @pixelastic @redox? |
Would it be feasible for you to directly use the helper.client? var params = helper.getSearchParameters(); // non existent right now I think
params.whatYouWant = value;
helper.client.search(params, function(){}); ? I am not sure your need @maxiloc is something that belongs to the helper. Dont you just want to do a search query? |
Well since you have already some parameters in the helper, it could be handy to use it from time to time directly from the helper, instead of having to use the raw client. Example of implementation (with the current API, that is far from perfect for this case) AlgoliaSearchHelper.prototype.searchOnce = function(parameters, callback){
var newState = this.state.setQueryParameters(parameters);
var helper = new AlgoliaSearchHelper(this.client, this.index, newState);
this.client.search( helper._getQueries(), function(error, results) {
var formattedResponse = new SearchResults( newState, results );
callback(formattedResponse, newState);
} );
}; |
@vvo The thing is, the goal is to use the exact same code used with the helper, but with 1 or 2 parameters different. The content object need to be the same |
So @bobylito solution fits I guess. As the helper is stateful, event based, adding this function seems at first a little weird. Getting the current search parameters, modifying them and doing a client.search would work. Otherwise:
|
OK I'm starting to dig a little further into this one. Proposition of API : helper.rawSearch_wipNAME(
{
index: '', // this one is tricky, this is not a SearchParameters attribute
// but I guess we have to be able to update it
query: ''
}, function(error, results, state){
// error is the fw of the error
// results is a SearchResults
// state is the state as sent to Algolia
}
);
// Of course we would need to support the callbackless/promise style :)
helper.rawSearch_wipNAME(
{
index: '', // this one is tricky, this is not a SearchParameters attribute
// but I guess we have to be able to update it
query: ''
}
).then(function onFulfill(arrayOfObjects){
// Here we have a problem though we can't pass two arguments because of the promise contract
// So why not an array?
// - [0] for the results as a SearchResults
// - [1] for the state as sent to Algolia (SearchParameters)
}, function onError(err){}); |
LGTM, my 2cts:
|
Thanks, short answer to your points :
|
Why not reuse the current .search but allow passing a parameters + callback? It would trigger the "callback search" mode. helper.search([indexName], {mergedQueryParameters}, cb); helper.search([indexName], {mergedQueryParameters}).then; ? |
No way :)
|
…eature/searchOnce Fix algolia/algoliasearch-helper-js#146 : add a way to make queries that don't change the inner state
The use case is to be able to make a small query with the helper and modifying just some parameters
For example being able to an empty query just to get the facets
The text was updated successfully, but these errors were encountered: