-
Notifications
You must be signed in to change notification settings - Fork 515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allowing user to exclude facets from search using refinementList #1232
Comments
Hi @billvieux Thanks for posting this issue. And your codepen is very helpful too :) This kind of behaviour should be in the API as it is kinda tricky to implement over existing widgets. Maybe have an option to be able to activate this kind of exclusion link when using |
Yes it could be in the API (the instantsearch.js API), but should a refinementList widget allows users to both refine and remove (exclude)? The codepen demo has both actions in the same widget, it's powerful but is it easy to understand? |
Thanks for quick response! In my scenario, I could live with a 2nd refinementList widget on the page that called In my codepen implementation, I use a currentRefinedValues widget, so the user can see what has been removed. In an instantsearch.js API-level implementation (in the refinementList), I would think you'd want to implement this feature in a way that wouldn't require the currentRefinedValues widget for the user to keep track of exclusions. Ideally, I think the excluded facet would still show in the refinementList, but support being styled differently (e.g., strikethrough). Do you have any suggestions / concerns about they way I used |
The way you did the prototype is not really orthodox :) And leads to some weird behaviour. This is likely to be cause by the way this widget is implemented. There are two alternatives here, either you create a proper custom widget or you wait for such a feature to be implemented, given our bandwidth and the complexity of making a nice API for that, I'm not sure that we will implement it in the coming days. I'm pretty confident that you can make a straightforward refinement list custom widget that will fit your need. |
Thanks @bobylito. Regarding the custom widget - is there anyway recommended way to extend the refinementList widget? It seems a shame to copy that entire widget just to support an |
@billvieux I detailed a bit more doing a custom widget in another thread: #868 (comment). Once you get the three methods, the helper and you are able to do a bit of JS/jQuery you should be good. Ask any other question in other issues about building custom widgets if you have. Thanks! |
@billvieux What solution did you end up with? I am currently facing the same problem. |
Not the cleanest, but I just added another link next to the refinement with a red 'x' and when clicked, it excludes that refinement. When creating the widget, I specify the item template as follows
My
When that link is clicked, I pull the data attribute and add a facet refinement and re-do the search.
I also have a |
@billvieux I tried doing what you're doing in codepen, but I think something changed in instantsearch v2 and clicking on label gets caught before your custom click listener, and thus it does not work :( |
My solution requires clicking directly on the red |
Yeah I was clicking on the 'x', it still didn't catch the click, not sure why. I basically have the same scenario as you do. |
Can you open a new issue with the problems you have @xPaw |
I decided to look at this again, and there's still no easy way of achieving this. Can you re-open this issue because I think |
Hi @xPaw, this issue is very old, and I have lost the context. Do you want to prevent an item from being shown (if so, filter in transformItems), or it still to be shown, but not refine (map in transformItems where you remove the 'value' on the item) |
I want to exclude items from search results (refine with For example, if you look on https://steamdb.info/sales/ and click 'Filter by user tags', you can see [+] and [-]. Right now The example above doesn't use Algolia, you can see the refinement widget here: https://steamdb.info/instantsearch/ |
ah okay, exclusion in this way. You can create the custom UI with connectRefinementList, and call either An example here does something similar, although only excludes, not a mix https://codesandbox.io/s/4xvz9wmj00 |
I think I can get it working with the example, yeah. As I understand it, Also, do you think it's worth investigating whether this feature should be added to instantsearch.js? I think it's an important filtering mechanism. |
Can you open a fresh issue with the full use case you have? Old issues like this aren't really monitored. thanks! |
I think this issue explains the use case well, no reason to duplicate it. Can you simply reopen it? Here's another issue I ran into with my exclusions widget that I think would be possible to solve if implemented properly: If you want to do EDIT: Forgot I made a discussion for this: #4754 |
I want to support a scenario where a user can exclude tags from the search. Ideally, it would be using the existing refinementList (or extending it).
Here is a CodePen that basically behaves I want. For example, click the red 'x' next to 'Used' to exclude records tagged 'Used'.
http://codepen.io/billvieux/pen/QKWWqy
However, this is a terrible implementation. I modified the refinementList item template to include a link in the label along with the tag name. Then I get the tag name during the click:
$(document).on('click','.ais-refinement-list--label a', function(e){ search.helper.addFacetRefinement('tags', '-' + $(e.target)[0].dataset.tag); search.helper.search(); });
I had to use the
-tagname
syntax withaddFacetRefinement
to ensure that the tag was removed from the refinementList. When I tried to useaddFacetExclusion
the hits were correct, but the refinementList and currentRefinementValues widgets didn't work as expected.I also had to keep the link inside the
<label>
as moving it outside the label seemed to always result in both thetagname
and-tagname
refinements being added. (I saw refinementList has to do some work as-is to avoid double responding to a click.)Cons: This uses a global document bind to watch for click events, has a small target area to click for exclusions (and that link can't be outside the
<label>
, and currently allows the user to select a tag & then exclude it, thus getting 0 search results.For a scenario like this, I would really welcome any suggestions on better ways to approach the implementation or achieve this kind of behavior.
The text was updated successfully, but these errors were encountered: