Hey! I’m wondering if anyone has experience sorting results dynamically. We’re trying to sort by hotel price but the prices can be different depending on the day. Any ideas would be appreciated!
j
Jason Bosco
09/04/2024, 4:08 AM
Could you elaborate on what the issue is?
a
Anthony Bachour
09/04/2024, 5:25 PM
Hi Jason,
Anthony Bachour
09/05/2024, 3:42 PM
We have properties collection in Typesense. Depending on the date range searched the properties have rates that differ per night (stored in object called nightly_rates) we would want to sort by the average of those rates per respective dates.
j
Jason Bosco
09/05/2024, 11:34 PM
Typesense doesn't have the ability to do computations on fields dynamically. So at indexing time, you would have to create a new field with this averaged value and then use that to sort
a
Anthony Bachour
09/06/2024, 2:34 PM
hey yes exactly my thoughts but any ideas to make that efficient? dates can range (sometimes 1 week, 5 days, 2 weeks etc) I thought of making an average for every week over 2 years and sorting by one of those fields depending on the closest period. then transform results on the returned properties again to get it closer.
j
Jason Bosco
09/06/2024, 3:09 PM
That sounds like domain-specific business logic to me, to decide how to compute the avg price. It's hard to make a recommendation because I'm not too familiar with the underlying intricacies