Sort by number + doing text search
I have a table of an item with a name, and a number field contaiing a score.
I want to create logic that will get me all the items matching a specific string for the name (no need vector search, just regular text search is good) sorted by the heights score descending.
Is this possible in convex? It is very basic functionlity but I couldn't find it in the docs.
8 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
Right here: https://docs.convex.dev/search/text-search
Full Text Search | Convex Developer Hub
Run search queries over your Convex documents
So from what I understand it is not possible ?
How you will suggest to implement such a feature ?
In a SQL DB I would just do a like query and then order by
There are examples in the linked doc, if something is unclear let me know
In the doc it state that you cannot change the relevane order of the returned docs when using a search index.
So how can you do something like searching for a text in a record and then order it out by another value (let say a number).
I couldn't find any document or examples of such implementation. Can you share any if exists?
The only thing I thought about was to get about 1000 records from the search index and then order it in the code by the number column. However this approach doesn't really give my the order I need, if there is 1 million records in the DB, this kind of ordering will be pretty inaccurate.
Is this something convex thought about, because it seem pretty trivial feature that is used in a lot of systems.
Thanks for the help!
Ah right, good point. Streams can be used for this: https://stack.convex.dev/merging-streams-of-convex-data
Merging Streams of Convex data
New convex-helpers are available now for fetching streams of documents, merging them together, filtering them them out, and paginating the results. Wi...
You would be implementing your own sorting via some js lib like fuzzy
Regarding built in support, search in Convex is meant to serve simple use cases currently, the recommendation being to either roll something like I mentioned or use a service like Algolia.
Thanks for the help!
You cannot use stream with search index.. it is throwing an error that it is not allowed.
Do you know if this is in the roadmap? It is very basic feature. Using something like Algolia is annoying.
And I would suggest adding a section about this in the docs to make it clearer to users