typesense / typesense

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Home Page:https://typesense.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: Handling multiple matches in collection joins for sorting

TatuUlmanen opened this issue · comments

Description

Regarding joins in the newest 0.26 RC. I have a products collection that joins prices from a product_prices collection. A product might have multiple prices available, e.g. when ordering in bulk. When I try to sort the results by price, I get this error:

Multiple references found to sort by on product_prices.price_net.

I understand that this is because Typesense can't decide on which price to use for sorting. But in this case I'd just want to sort by the cheapest price available.

In this case I can not add a "min_price" to the products collection, as I have also customer specific prices that are available for logged in users. So the min_price wouldn't work when the customer is logged in and more product_prices become available.

There seems to be no workarounds for this problem as of time being. This currently prevents me from adding a "sort by cheapest" feature on my eCommerce storefront. So a feature is needed to help Typesense solve this ambiguity and reduce the multiple references to one for sorting.

Ideally, when I specify $product_prices(price_net:asc) as the sort_by parameter, when Typesense encounters products with multiple prices, it should first sort the prices of that single product by price net ascending, and then select the first result from that set, thus resolving the ambiguity.

Conversely, if I want to sort by most expensive, I would set the sort_by to $product_prices(price_net:desc), then the prices inside each product would be sorted price descending and the first one returned.

Could this even be the default functionality for sorting in joins?

Metadata

Typesense Version: 0.26.0.rc58

OS: any

Need this feature +1

+1

For my use case, I have a record like this:

# users
{ id: 1, name: 'Test' }
{ id: 2, name: 'Test' }
{ id: 3, name: 'Test' }

Which has associations like this:

# connections_to_companies
{ id: 1, user_id: 1, company_id: 2, connected_at: XXX}
{ id: 1, user_id: 1, company_id: 3, connected_at: XXX }
{ id: 1, user_id: 1, company_id: 4, connected_at: XXX }

I want to sort by the earliest connected_at for that user.