How to filter based on a field while also using search index?
How can I narrow a table on a certain field and then also search based on a field?
For example, say I have a
I've considered just doing a regular index on
Thank you.
registrations
table where each one will belong to a different organization
and each has name
. How can I effectively query based on an index for organization
and then also filter them based on a search parameter for name
? It doesn't appear we can use an index and a searchIndex at the same time.I've considered just doing a regular index on
organization
and then doing a filter on name
, but I might have to do some sort of fuzzy lookup manually. I also thought of using a search index on the name
field and then filtering on the organization
. I'm not sure what pattern to adopt here.
Any advice on how to structure this effectively? I'm going to try and call paginate
on the resulting list and showing these results in a table .Thank you.
3 Replies
you would do this with a
searchIndex("by_name", {searchField: "name", filterFields: ["organization"]})
and q.search("name", args.name).eq("organization", args.organization)
Oh, this makes total sense. Thanks! 🎉
the problem with this is filtering with numbers q.search() doesn't have gtq or lte function
but still can be extend by filter after the withSearchIndex