#community-help

Prioritizing and Sorting Document Searches by Specific Fields

TLDR Robert inquired on sorting document searches by specific fields. Jason advised on using 'sort_by' for ranking, addressed 'per_page' limit's application, and confirmed unsupported "optional filtering".

Powered by Struct AI
9
23mo
Solved
Join the chat
Oct 07, 2021 (23 months ago)
Robert
Photo of md5-a0aba3e46685345ae57c342a8130989f
Robert
04:28 PM
How can I search for some documents by a specific keyword and have documents with a specific value for a field be more important (rank higher) than the rest? For example we are searching users but want to prioritize the badge verified ones
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
04:50 PM
Robert If you set verified as an integer, you can then use it in the sort_by parameter like this:

sort_by: verified:desc,_text_match:desc
Robert
Photo of md5-a0aba3e46685345ae57c342a8130989f
Robert
05:07 PM
When does ‘per_page’ limit apply? Before or after documents are sorted?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:08 PM
After
Robert
Photo of md5-a0aba3e46685345ae57c342a8130989f
Robert
05:08 PM
thanks
05:42
Robert
05:42 PM
Can you sort_by something like field1:32:desc ? Meaning the value 32 for that field would be rank 1, if it was found based on the query/keyword?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:57 PM
No it's not possible to do that. You're referring to what's called "optional filtering" which we plan to support in the future
05:57
Jason
05:57 PM
Could you create a Github issue for this?
Oct 08, 2021 (23 months ago)
Robert
Photo of md5-a0aba3e46685345ae57c342a8130989f
Robert
09:31 AM
thanks for letting me know