Vue-instantsearch: Search Store Facet Refinement - "OR"

Created on 20 Dec 2017  ·  3Comments  ·  Source: algolia/vue-instantsearch

First things - great library.

What I would like to know is how to use "add facet refinement" to do an "OR" query instead of an "AND" query.

i.e. store.addFacetRefinement("skills", "dev"); store.addFacetRefinement("skills", "designer")

The above causes it to be an "and" query (where each person must be a dev AND a designer).

According to the algolia documentation, we need to parse in an "array".

I.e. the above in the actual ajax request sends: facetFilters:["skills:dev","skills:designer", "someotherthing:true"]

The documentation has an example like this (book OR ebook AND author JK Rowling)
facetFilters: [["category:Book", "category:Ebook"], "author:JK Rowling"]

https://www.algolia.com/doc/guides/searching/filtering/?language=javascript#facet-filters

Thanks

Most helpful comment

Definitely something we need to add to our docs.
This has become a frequent question.

Moreover, a lot of users are trying to leverage the queryParameters for this and it doesn't work.
Maybe we should see what's happening there and make it work if it makes sense, or raise an error for users to act accordingly.

All 3 comments

import { FACET_OR } from "vue-instantsearch";

//... create store

store.addFacet("the-attribute", FACET_OR);
store.addFacetRefinement("the-attribute", "the-value");

That way that facet is set up for faceting with “or”, rather than the default of “and”

Thanks for using Vue InstantSearch and don’t hesitate to reach out for any other questions

Definitely something we need to add to our docs.
This has become a frequent question.

Moreover, a lot of users are trying to leverage the queryParameters for this and it doesn't work.
Maybe we should see what's happening there and make it work if it makes sense, or raise an error for users to act accordingly.

Was this page helpful?
0 / 5 - 0 ratings