Search Index by Two or More Fields
Hello, I'm trying to retrive a query using searchIndex.
I need it to query documents by two or more fields.
This is what I tried so far, but is only retriving results for legalName.
9 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!
The best we have for now is to create an additional field to query against - in your case that field would combine legal name and alias into a single string, and search against that.
You would keep the field up to date by updating it every time either of the other two fields are updated. Best way to do this is to have a helper function that's solely responsible for any updates to the record (or at least to these two fields), so you can be sure the computed field is always accurate.
I understand, so will have to concatenate to a big string.
So I can only define one searchIndex per table?
No you can have multiple, but I believe only one per field
I have one per field
I can't use 2 .withSearchIndex in the same query function?
No, only one
No special limits it seems, I thought there were
So I can only define one searchIndex per table?You can define multiple per table, but still can only use one per query
Sorry, I think my query is working fine
I think I have an error in my front end code
Let me see..
I remove the duplicates like this...
The results are logging in the console, I must have a bug that is not getting into my combobox
Can't find it yet