sonandmjy
sonandmjy2mo ago

search index multiple chained filter fields behaviour not as expected

Hi there, I have a schema that looks like this
export const Destinations = Table("destinations", {
type: VDestinationTypes,
contactId: v.optional(v.id("contacts")),
value: v.string(),
isDeleted: v.boolean(),
organizationId: v.id("organizations"),
lastMessageId: v.optional(v.record(v.id("channels"), v.id("messages"))),
lastInboundMessageId: v.optional(
v.record(v.id("channels"), v.id("messages")),
),
lastOutboundMessageId: v.optional(
v.record(v.id("channels"), v.id("messages")),
),
});
export const Destinations = Table("destinations", {
type: VDestinationTypes,
contactId: v.optional(v.id("contacts")),
value: v.string(),
isDeleted: v.boolean(),
organizationId: v.id("organizations"),
lastMessageId: v.optional(v.record(v.id("channels"), v.id("messages"))),
lastInboundMessageId: v.optional(
v.record(v.id("channels"), v.id("messages")),
),
lastOutboundMessageId: v.optional(
v.record(v.id("channels"), v.id("messages")),
),
});
and I am trying to add a searchIndex like this
Destinations.table
.index("by_contact_id", [
"organizationId",
"contactId",
"isDeleted",
"type",
])
.index("by_value", ["organizationId", "type", "value", "isDeleted"])
.searchIndex("by_search_value", {
searchField: "value",
filterFields: ["organizationId", "type", "isDeleted", "contactId"],
})
Destinations.table
.index("by_contact_id", [
"organizationId",
"contactId",
"isDeleted",
"type",
])
.index("by_value", ["organizationId", "type", "value", "isDeleted"])
.searchIndex("by_search_value", {
searchField: "value",
filterFields: ["organizationId", "type", "isDeleted", "contactId"],
})
but when I try to filter it using a query
ctx.db
.query("destinations")
.withSearchIndex("by_search_value", (q) => {
return q
.search("value", args.searchQuery)
.eq("organizationId", ctx.user.defaultOrganizationId!)
.eq("type", "phone_number")
.eq("isDeleted", false)
.eq("contactId", undefined);
})
.take(20)
ctx.db
.query("destinations")
.withSearchIndex("by_search_value", (q) => {
return q
.search("value", args.searchQuery)
.eq("organizationId", ctx.user.defaultOrganizationId!)
.eq("type", "phone_number")
.eq("isDeleted", false)
.eq("contactId", undefined);
})
.take(20)
it seems that it is still returning results where contactId IS defined. Also when I change .eq("type", "phone_number") => .eq("type", "email") it is still returning results where the type is of phone_number. When I only have 1 .eq the filter seems to be working fine but when I chain them they are not. Just want to check if I am misunderstanding some limitations of how to use this filter or if it is a bug
3 Replies
Convex Bot
Convex Bot2mo ago
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!
sonandmjy
sonandmjyOP2mo ago
Not sure why but after a while it started working but I didn't change anything... not sure if convex has a cache or something that was causing it not to reflect the changes immediately
erquhart
erquhart2mo ago
Changes would reflect as soon as your local convex dev service reports "Convex functions ready!"

Did you find this page helpful?