algoliasearch-helper-js icon indicating copy to clipboard operation
algoliasearch-helper-js copied to clipboard

A toggleNumericRefinement method?

Open Jerska opened this issue 9 years ago • 6 comments

Here is what we currently have:

  • Facet => toggleRefinement
  • Disjunctive facet => toggleRefinement
  • Hierarchical facet => toggleRefinement
  • Exclude => toggleFacetExclusion
  • Numeric => Only {add,remove}
  • Tag => toggleTag

We should probably add toggleNumericRefinement for consistency.

Jerska avatar Nov 16 '15 16:11 Jerska

Yes, that's something I wanted as well.

Also, most of the time you're using a single operator and want to switch from 1 refinement to another. Like you're filtering with created_at>1 week ago and you want to move to created_at>1 month ago or created_at>1 day ago. Not sure the toggleNumericRefinement is enough for that use-case.

redox avatar Nov 16 '15 16:11 redox

It isn't, we're now using an array of refinements by operator ( https://github.com/algolia/algoliasearch-helper-js/blob/d3bf223fcfe9da6a4a47c2349d758d402d67729a/dist/algoliasearch.helper.js#L8177 ) and all the other ones use the value to know which one to add/remove, so I wouldn't change the behaviour for this method only, but we could probably add a 4th parameter override ?

Jerska avatar Nov 16 '15 16:11 Jerska

so I wouldn't change the behaviour for this method only, but we could probably add a 4th parameter override ?

Or maybe another method, because optional 4th parameter is not super nice :/

helper.toggleNumericRefinement(attribute, operator, value);
// and maybe
helper.switchNumericRefinement(attribute, operator, value); // clear + add ?

redox avatar Nov 16 '15 19:11 redox

I like the switch method. This is pretty common to use this clear + add pattern. My concern would be that it's yet another kind of method. What do you think?

bobylito avatar Nov 16 '15 20:11 bobylito

My concern would be that it's yet another kind of method. What do you think?

Yes true; maybe we should just go for toggle then. Even if the switch is a common pattern, we can definitely call clear+add instead.

redox avatar Nov 16 '15 20:11 redox

Maybe we could have that in the next major release and rethink the method names?

bobylito avatar Nov 17 '15 12:11 bobylito