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

Proper way to modify SearchParameters on the AlgoliaSearchHelper object? #84

Closed
acechase opened this issue May 26, 2015 · 8 comments
Closed
Assignees
Milestone

Comments

@acechase
Copy link

On initialization of my helper I am setting a couple geo params. My initialization looks like this:

var algolia = window.algoliasearch(window.ALGOLIA_APPLICATION_ID, window.ALGOLIA_SEARCH_API_KEY);

var algoliaHelper = window.algoliasearchHelper(algolia, 'metros', {
  hitsPerPage: 1,
  aroundLatLngViaIP: true,
  aroundRadius: 250000
});

Working with the helper as my primary object, what I do not understand from looking at the docs is how do I update values like aroundRadius? I cannot mutate the helper so I can't just do:

var s = helper.state;
s.aroundRadius = 10000000; // read-only attribute error

I would expect to see some type of "helper.state.setOption()" type of method, but I don't see anything like that. All the setters I see seem to apply specifically to facets.

I was able to get this to work using the mutateMe method on the state object, but that seems pretty low level. Is there a better way to do this?

My final code for updating the aroudnRadius param looks like this:

var searchState = algoliaHelper.state.mutateMe(function(state){
                    state.aroundRadius = 1000000;
                });
algoliaHelper.setState(searchState);
algoliaHelper.search('');
@redox
Copy link
Contributor

redox commented May 26, 2015

Indeed, would be cool to have something like:

  setQueryParameter : function setQueryParameter( param, value ) {
    return this.mutateMe( function( m ) {
      m[param] = value;
    } );
  },

What do you think @bobylito ?

@bobylito
Copy link
Contributor

This is linked to #76

We need to propose that kind of feature. We often end up modifying multiple parameters at once, so having something more general like a setPartialState would eliminate the intermediate state created by the multiple calls to setQueryParameters.

@redox
Copy link
Contributor

redox commented May 30, 2015

setPartialState looks a bit techy/internal to me; what about setQueryParameter(param, value) and setQueryParameters(params)?

@bobylito
Copy link
Contributor

Sounds right!

@bobylito
Copy link
Contributor

And what about setQueryParameter( param, value ) and merge( object )?

@redox
Copy link
Contributor

redox commented May 30, 2015

Maybe merge could be used internally on the state object but I prefer helper.setQueryParameters than helper.merge, what do you think?

@bobylito
Copy link
Contributor

bobylito commented Jun 1, 2015

Ok let's do that! :)

@bobylito bobylito added this to the 2.1.0 milestone Jun 1, 2015
@bobylito bobylito self-assigned this Jun 2, 2015
@bobylito
Copy link
Contributor

bobylito commented Jun 2, 2015

@acechase @redox made a PR for this issue, see if it fits you :) #90

bobylito added a commit that referenced this issue Jun 2, 2015
bobylito pushed a commit that referenced this issue Jun 15, 2015
  * FIX : #29 Avoid callback for outdated queries
  * FIX : #64 Sum up the processing time of all queries
  * FIX : #92 Parameters that can be set in the dashboard shouldn't have defaults
  * FIX : #62 Make sure disctinct is set to false when it's not possible to use distinct in Algolia
  * FEATURE : #91 Support for tags (with support for the raw format #98)
  * FEATURE : #70 Ability to get all refined values : helper.getRefinements( facetname )
  * FEATURE : #51 multiple filters for a single conjunctive facet (tests)
  * FEATURE : Ability to modify any parameter of the state easily (#76 #84 #12)
  * FEATURE : #69 Ability to know if a facet is refined, whatever the value
  * FEATURE : #86 Expose SearchParameters, AlgoliaSearchHelper, SearchResults to users directly in the builds
  * FEATURE : #25 let the user do a clearRefinement with a function as a filter
  * REFACTORING : SearchParameters is immutable (#14)
  * REFACTORING : Ensure SearchParameters is totally frozen (#14)
  * LIB : Update lodash version to 3.9.x
dhayab pushed a commit to algolia/instantsearch that referenced this issue Jul 10, 2023
…pdate a single parameter on SearchParameters
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

3 participants