Multiple groups of filters for search products query
See original GitHub issueIs your feature request related to a problem? Please describe. Allow user to filter by multiple filters. For example, user want to filter some category by color (red (facet_id=1) or white (facet_id=2)) and by material (leather (facet_id=10)).
Now search query allow to input list of facets and logical operator for list https://www.vendure.io/docs/graphql-api/shop/input-types/#searchinput
Describe the solution you’d like
Allowing to pass groups of facets to search query.
For example,: { facets: [ { facets_ids: [1,2], logical_operator: "OR" }, { facets_ids:[10] } ], logical_operator: "AND" }
Describe alternatives you’ve considered So, the only way to filter by multiple filters is querying shop-api two times.
- first time with facet_ids = [1,2] and logical operator= Or
- second time with facet_ids=[10]
- merge results at client side
Additional context Probably it can be implemented by ElasticSearch plugin?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
We discussed this on Slack. Here is my piece of code that can be used to extend ListQueryBuilder object (Product or ProductVariant) that does similiar to what you ask for, though without customizable logical operator - it will always look between facetValues of same facet (
OR between facetValues of x facet
ANDOR between facetValues of y facet
AND so on…)qb.andWhere(
"product"."id" IN ( WITH targets AS (SELECT * FROM facet_value WHERE id IN (:...argProductFacetValues)) SELECT "productId" FROM product_facet_values_facet_value AS map INNER JOIN targets AS tgt ON tgt.id = map."facetValueId" GROUP BY map."productId" HAVING COUNT(DISTINCT tgt."facetId") = (SELECT COUNT(DISTINCT "facetId") FROM targets) )
, { argProductFacetValues: options.facetValueIds });Open the continuation of this issue #815