Prioritising Email in Collections Using Typesense
TLDR Pankaj had an issue ranking user emails first in a collection. Jason explained how 'sort_by' works and suggested using the new filter-based sorting mechanism, specifically "sort_by": "_eval(has_email:true):asc,id:desc"
. Pankaj agreed to try this solution.
Oct 26, 2022 (14 months ago)
Pankaj
03:47 PMmy example collection
email
id
description
i want to rank the result where users with having email are ranked first with id desc
tried doing sort_by
email(missing_values:last):desc,
_text_match:desc,
id:desc
but looks like missing_values is last one to sort so it always like email desc any other ways this can be done ? thanks in advance
Jason
04:42 PMYou could use the new filter-based sorting mechanism we’ve added in 0.24.0.rcn25 to implement your use case. Something like:
"sort_by": "_eval(has_email:true):asc,id:desc"
where
has_email
is a new boolean field you’ll have to create at indexing time to each recordOct 27, 2022 (14 months ago)
Pankaj
06:07 PMTypesense
Indexed 3005 threads (79% resolved)
Similar Threads
Document Weighting and Sorting Discussion
SamHendley asked how to weight a document based on age and offered a sorting method. Jason clarified the method and suggested an RC for use. SamHendley tested and confirmed the solution. User Kishore Nallan assisted when an error occurred with a new feature.
Troubleshooting Typesense API Sorting Error in Item Collections
Nikhil encountered a sorting error when using Typesense API due to an optional reference field in the items collection schema. Harpreet and Jason helped debug and identified a bug with sorting in general for 2 fields with the first one being the join field, promising a fix in a forthcoming build.
Resolve Facets and Sorting Issues with Typesense
Ethan needed assistance with getting all facet values and sorting results by date using Typesense. Jason provided guidance on how to use Typesense properties to accomplish these tasks, and resolved issues related to specific use-cases provided by Ethan and Rushil.