Hey guys! is it possible to use the _eval sorting ...
# community-help
m
Hey guys! is it possible to use the _eval sorting with more than 1 group? Something like:
_eval([(category:shoes):1, (category:shirts):2] && [(brand:nike):1, (brand:adidas):2]):asc
I've only found examples with 1 group. When I tried with 2, I got the error: `Could not find a field named `` in the schema for sorting.`
f
Hey Matheus, Currently,
_eval
sorting doesn't support multiple groups with
&&
. It supports a single group with multiple expressions, like
_eval([(category:shoes):1, (category:shirts):2]):asc
. You can also use
&&
or
||
inside each expression, like
_eval([(brand:nike || brand:air):3, (brand:adidas):2]):desc
. What isn't supported is combining multiple groups with
&&
, like
_eval([(category:shoes):1, (category:shirts):2] && [(brand:nike):1, (brand:adidas):2]):asc
. The parser expects a single group in brackets, then the order. The evaluation logic returns the score of the first matching expression in that list. A workaround is to combine all conditions into one group. For example, if you want category and brand combinations, list them explicitly:
_eval([(category:shoes && brand:nike):1, (category:shoes && brand:adidas):2, (category:shirts && brand:nike):3, (category:shirts && brand:adidas):4]):asc
. This covers all combinations but requires listing each one.
m
Got it. Unfortunately my use case could generate a huge "matrix" if I combine them. I'll find another way as we also could have only 1 _eval per sorting afaik
f
Could you provide a small example of how you would use this feature you're describing?
m
Sorry for the late response. My scenario is: I have a products collection and a prices/offers collection. Each product can have hundreds of sellers, and each seller can have thousands of offers. Each customer only has access to a subset of sellers and offers, based on business rules. I already use _eval to rank sellers per customer (e.g. (sellerA):1, (sellerB):2). Those rankings are very dynamic. Now I have a second independent ranking: a custom product ranking generated from the customer’s cart / recommendations (e.g. (productA):1, (productB):2). (to build a recommendation shelf on the checkout page) Ideally I’d like to apply both rankings at the same time (seller priority + product priority), but combining them using your example, explodes into a big matrix when using a single _eval. That’s why I was wondering if multiple _eval groups (or equivalent) could be supported.
f
That seems like it's too complicated to express in a sorting expression, and even then, it would lead to performance loss. Maybe you could try to do some pre-computation before indexing, to have a score to use for sorting
wrong thread