Paul Savoldelli
04/02/2025, 6:22 AMsort_by
(currently limited to only 3 clauses). I understand this is a deliberate constraint.
However, we're looking to replace Algolia's Merch Studio (premium), and being able to do this directly through curations would be a real game-changer for us. Of course, merchandising rules often involve multiple fields.
If it were possible to allow more than three clauses (perhaps via a server-side configuration, even at the cost of some performance), it would definitely be a strong advantage.
This would allow us to apply complex merchandising rules to e-commerce catalogs without having to create additional indexes — enabling real-time execution of merch rules via curation, directly by business teams.
Don't hesitate to forward me elsewhere if it's not the right place to open this discussion.Fanis Tharropoulos
04/02/2025, 6:50 AMPaul Savoldelli
04/02/2025, 7:07 AMbrandOrder
,
• price
,
• analyticsProductViews
,
• catalog
array field (which is a list of `catalog_id`s the product belongs to),
• and a product_id
, of course
In Algolia Merch Studio, you can create merchandising rules that get triggered under certain conditions (for example: catalog.id := 123
, or more complex triggers based on filter_by for example), and apply a set of merchandising actions dynamically — such as sorting by price
, brandOrder
, pinning specific `product_id`s, hiding others, etc.
So when a query is made (e.g. for a given catalog ID), if a configured trigger applies, the merchandising rules are applied on the fly. This gives business teams a lot of autonomy — as long as the data is clean and indexing is complete, they can work independentlyPaul Savoldelli
04/02/2025, 7:10 AMfilter_by
on curations uses exact match only.
But honestly, that's not really an issue in our case, since we can leverage curation tags, and maintain a reference table on our side to determine whether to apply a single curation or multiple curationsPaul Savoldelli
04/02/2025, 7:12 AMFanis Tharropoulos
04/02/2025, 7:14 AMPaul Savoldelli
04/02/2025, 7:16 AMsort_by
options — even though we'll enforce some constraints to keep things manageable.
Right now, what I’m experimenting with (and it’s working fairly well) is indexing a separate collection, where a ranking score is precomputed based on the business rule. Then, I create a curation rule that joins with this new collection to apply the custom sorting.
The downside, though, is that the whole process — and especially the rule configuration interface — becomes less real-time. Since I need to reindex this rule at creation time, it prevents me from offering immediate preview capabilities in the business admin interface, for instanceFanis Tharropoulos
04/02/2025, 7:18 AMPaul Savoldelli
04/02/2025, 7:20 AMPaul Savoldelli
04/02/2025, 7:21 AMPaul Savoldelli
04/02/2025, 7:24 AMfilter_by
condition — in Typesense currently only work with exact matches.
For example, a curation with a rule like filter_by: catalog_id:=2746
won’t apply if the user-side query includes something like catalog_id:=2746 & random_attributes:="user choice"
Fanis Tharropoulos
04/02/2025, 7:25 AMsort_by
fields are tie-breaking, meaning that each one is going to be applied if there are two or more documents with the same value on that sort field.
You could look into using the _eval
clause to sort based on filter conditions:
https://typesense.org/docs/guide/ranking-and-relevance.html#ranking-based-on-conditions
Or just have one popularity / aggregated score field based on that order you mentioned, at indexing time. No need to copy the data to another collection and JOIN for thisPaul Savoldelli
04/02/2025, 7:26 AMFanis Tharropoulos
04/02/2025, 7:26 AMfilter_by
condition — in Typesense currently only work with exact matches.
We've taken note of that, yeah. It's a bit more nuanced than that though, sadly, since filters can be complex and include arrays etc, so there's still planning needed to be done if we do end up implementing this featurePaul Savoldelli
04/02/2025, 7:27 AMFanis Tharropoulos
04/02/2025, 7:30 AMAs the product collection is quite important, that's why if put it in other collection.
and also because we want to abstract merch rules from product indexation (because the last one could quite complex, based on product offering)Then a one-to-many relationship with that collection would be ideal, without any redundancy in terms of product details (not saving the title or description twice, just saving the score and the reference to the id of the product). Although this will have a performance cost, since joining is done at search time, not during indexing time
Paul Savoldelli
04/02/2025, 7:30 AMeval
mechanism — it won't work in this case, since we're actually dealing with tie-breaking, not strict filtering.
In fact, I do not try to search anything, but display full catalog page views, so without any search query but with specific merchandisingPaul Savoldelli
04/02/2025, 7:31 AMKishore Nallan
04/02/2025, 9:30 AMdef combine_to_64bit(val1, val2):
"""
Combine two 32-bit integers into a single 64-bit integer using bit shifting.
Args:
val1 (int): First value that will occupy the high 32 bits
val2 (int): Second value that will occupy the low 32 bits
Returns:
int: 64-bit integer combining both values
"""
# Shift first value left by 32 bits
high_bits = val1 << 32
# Combine with second value using bitwise OR
result = high_bits | val2
return result
Using this approach you can actually "pack" stockQuantity
and productViews
into a single field and it will also preserve the sorting order like you would get with 4 sorting fields.
This computed field can be indexed as part of the document and used in sort_by clause.Paul Savoldelli
04/02/2025, 11:57 AM