Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Add a way to make a inline query with different parameters #146

Closed
maxiloc opened this issue Jul 20, 2015 · 10 comments
Closed

Add a way to make a inline query with different parameters #146

maxiloc opened this issue Jul 20, 2015 · 10 comments
Assignees
Milestone

Comments

@maxiloc
Copy link
Contributor

maxiloc commented Jul 20, 2015

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

@bobylito
Copy link
Contributor

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?

@vvo
Copy link
Contributor

vvo commented Jul 20, 2015

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?

@bobylito
Copy link
Contributor

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);
  } );
};

@maxiloc
Copy link
Contributor Author

maxiloc commented Jul 20, 2015

@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

@vvo
Copy link
Contributor

vvo commented Jul 20, 2015

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:

  • searchOnce feels not the best name we can find, .rawSearch()? Any other idea?
  • we must forward the client error to the callback

@bobylito bobylito modified the milestone: 2.4.0 Aug 4, 2015
@bobylito
Copy link
Contributor

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){});

@redox
Copy link
Contributor

redox commented Aug 14, 2015

LGTM, my 2cts:

  • the index parameter must be optional
  • every query parameters set here must override the underlying ones
  • I would still add a getSearchParameters() function to retrieve the actual parameters that will be sent (based on the underlying _getHitsSearchParameters) -> can be useful to build more complex search logic (like playing with filters)
  • regarding the naming, I don't have a lot of ideas. I think helper.searchOnce is OK-ish :)

@bobylito
Copy link
Contributor

Thanks, short answer to your points :

  • all parameters are optional, they are juste there as a way to override the current state for this specific request
  • indeed they do
  • from our discussion IRL, there are already some methods on the helper that do that (_getQueries...).
  • right now it's between rawSearch and searchOnce. I love neither of them. What about something that explicitly says that we are not modifying the state? searchWithoutStateUpdate? statelessSearch?

@vvo
Copy link
Contributor

vvo commented Aug 18, 2015

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;

?

@bobylito
Copy link
Contributor

No way :)

search is a method of the helper flow. The new method forks the flow into a separate and distinct operation. Those are two approach to do the search.

@bobylito bobylito self-assigned this Aug 24, 2015
dhayab pushed a commit to algolia/instantsearch that referenced this issue Jul 10, 2023
…eature/searchOnce

Fix algolia/algoliasearch-helper-js#146 : add a way to make queries that don't change the inner state
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants