Hugo Dias
Hugo Dias•5mo ago

Anyone has had issues with search

Anyone has had issues with search indexes filtering on 2 fields ?
.withSearchIndex('by_searchAmount', (q) =>
q
.search('search', args.search)
.eq('teamId', args.teamId)
.eq('amount', args.amount * -1)
)
.withSearchIndex('by_searchAmount', (q) =>
q
.search('search', args.search)
.eq('teamId', args.teamId)
.eq('amount', args.amount * -1)
)
seems to ignore the second filter
21 Replies
Hugo Dias
Hugo DiasOP•5mo ago
actually i think if the full text seach return an entry that is equal to args.amount it actually filters but if not it ignores the filter and return entries with amount != args.ammount very strange
Sara
Sara•5mo ago
q doesn't have .search on it
Hugo Dias
Hugo DiasOP•5mo ago
? q .search('search', args.search) .eq('teamId', args.teamId) .eq('amount', args.amount * -1)
Sara
Sara•5mo ago
like what i mean is you only use these methods on type q
No description
Hugo Dias
Hugo DiasOP•5mo ago
its a search index!
Sara
Sara•5mo ago
oh! my bad! my eyes didn't read the search 🤣 can you share how you indexed the table in your schema?
Hugo Dias
Hugo DiasOP•5mo ago
.searchIndex('by_searchAmount', {
searchField: 'search',
filterFields: ['teamId', 'amount'],
}),
.searchIndex('by_searchAmount', {
searchField: 'search',
filterFields: ['teamId', 'amount'],
}),
amount is a number
Sara
Sara•5mo ago
yep that is strange, I've never encountered this before
Hugo Dias
Hugo DiasOP•5mo ago
any chance i can get a convex eng to look at this?
Sara
Sara•5mo ago
lol I am not one
Hugo Dias
Hugo DiasOP•5mo ago
any way to ping them on this thread?
Hmza
Hmza•5mo ago
@erquhart can you chip in here please?
erquhart
erquhart•5mo ago
Can you log the actual inputs and the result and share here
Hugo Dias
Hugo DiasOP•5mo ago
Hey not right now, but it's literally amount==30 and there no entry with 30 it get ignore and search returns other entries with 26, 29 etc In other queries where theres actual entries with the amount I'm filtering it works
erquhart
erquhart•5mo ago
The logging is important - it basically allows us to determine definitively whether there’s a bug in your code or Convex. Both are understood to work as expected. The logs reveal all 🙂
Hugo Dias
Hugo DiasOP•5mo ago
console.log('SEARCH', args.search)
console.log('TEAM ID', args.teamId)
console.log('AMOUNT', args.amount, 'typeof', typeof args.amount)

const result = ctx.db
.query('transactions')
.withSearchIndex('by_searchAmount', (q) => {
if (args.amount) {
console.log('Negative amount', args.amount * -1)
return q
.search('search', args.search)
.eq('teamId', args.teamId)
.eq('amount', args.amount * -1)
}
return q.search('search', args.search).eq('teamId', args.teamId)
})


const result2 = await result.collect()

for (const tx of result2) {
console.log('OUTPUT', tx.teamId, tx.amount)
}
console.log('SEARCH', args.search)
console.log('TEAM ID', args.teamId)
console.log('AMOUNT', args.amount, 'typeof', typeof args.amount)

const result = ctx.db
.query('transactions')
.withSearchIndex('by_searchAmount', (q) => {
if (args.amount) {
console.log('Negative amount', args.amount * -1)
return q
.search('search', args.search)
.eq('teamId', args.teamId)
.eq('amount', args.amount * -1)
}
return q.search('search', args.search).eq('teamId', args.teamId)
})


const result2 = await result.collect()

for (const tx of result2) {
console.log('OUTPUT', tx.teamId, tx.amount)
}
schema
.searchIndex('by_searchAmount', {
searchField: 'search',
filterFields: ['teamId', 'amount'],
}),
.searchIndex('by_searchAmount', {
searchField: 'search',
filterFields: ['teamId', 'amount'],
}),
Logs
7/14/2025, 12:15:12 PM [CONVEX Q(transactions:matchReceiptQuery)] [LOG] 'SEARCH' 'Polar B88598C1-0002'
7/14/2025, 12:15:12 PM [CONVEX Q(transactions:matchReceiptQuery)] [LOG] 'TEAM ID' 'k5792971v04xrp519e06kjydm57ghxtx'
7/14/2025, 12:15:12 PM [CONVEX Q(transactions:matchReceiptQuery)] [LOG] 'AMOUNT' 30 'typeof' 'number'
7/14/2025, 12:15:12 PM [CONVEX Q(transactions:matchReceiptQuery)] [LOG] 'Negative amount' -30
7/14/2025, 12:15:12 PM [CONVEX Q(transactions:matchReceiptQuery)] [LOG] 'OUTPUT' 'k5792971v04xrp519e06kjydm57ghxtx' -27.58
7/14/2025, 12:15:12 PM [CONVEX Q(transactions:matchReceiptQuery)] [LOG] 'OUTPUT' 'k5792971v04xrp519e06kjydm57ghxtx' -26.45
7/14/2025, 12:15:12 PM [CONVEX Q(transactions:matchReceiptQuery)] [LOG] 'SEARCH' 'Polar B88598C1-0002'
7/14/2025, 12:15:12 PM [CONVEX Q(transactions:matchReceiptQuery)] [LOG] 'TEAM ID' 'k5792971v04xrp519e06kjydm57ghxtx'
7/14/2025, 12:15:12 PM [CONVEX Q(transactions:matchReceiptQuery)] [LOG] 'AMOUNT' 30 'typeof' 'number'
7/14/2025, 12:15:12 PM [CONVEX Q(transactions:matchReceiptQuery)] [LOG] 'Negative amount' -30
7/14/2025, 12:15:12 PM [CONVEX Q(transactions:matchReceiptQuery)] [LOG] 'OUTPUT' 'k5792971v04xrp519e06kjydm57ghxtx' -27.58
7/14/2025, 12:15:12 PM [CONVEX Q(transactions:matchReceiptQuery)] [LOG] 'OUTPUT' 'k5792971v04xrp519e06kjydm57ghxtx' -26.45
request id : ff4ddcd93357ba21 @erquhart let me know if this is enough
erquhart
erquhart•5mo ago
Perfect, I’ll try to repro in a bit Yep, looks like only the last .eq filter is honored. Digging into this a bit more.
erquhart
erquhart•5mo ago
GitHub
Only final filter field is honored in search index · Issue #56 · ...
Support thread reference: https://discord.com/channels/1019350475847499849/1393596083506253915 Given this schema: export default defineSchema({ numbers: defineTable({ search: v.optional(v.string())...
erquhart
erquhart•5mo ago
This is being looked at, will update when there's more.

Did you find this page helpful?