oscklm
oscklm12mo ago

Weird behaviour with search, all of a sudden my search result is not the same with same search term

I just came back after about and hour, and continued working on my app. Now the search results are not the same as before? I've doubled checked all the obvious things that could be wrong, like the query indexes not being met etc.
export const search = query({
args: {
search: v.string(),
},
handler: async (ctx, args) => {
const videos = await ctx.db
.query('video')
.withSearchIndex('search_title', (q) =>
q
.search('details.title', args.search)
.eq('isApproved', true)
.eq('privacy', 'public'),
)
.take(20)

return videos
},
})
export const search = query({
args: {
search: v.string(),
},
handler: async (ctx, args) => {
const videos = await ctx.db
.query('video')
.withSearchIndex('search_title', (q) =>
q
.search('details.title', args.search)
.eq('isApproved', true)
.eq('privacy', 'public'),
)
.take(20)

return videos
},
})
The search index:
.searchIndex('search_title', {
searchField: 'details.title',
filterFields: ['isApproved', 'privacy'],
})
.searchIndex('search_title', {
searchField: 'details.title',
filterFields: ['isApproved', 'privacy'],
})
Here is a snippet from the specific video document i'm no longer able to get a search result for, even though i was 1 hour ago, when i searched for example for "10 ting" or "pap & lim" which worked perfectly before?
{
"_creationTime": 1705061346057.3284,
"_id": "rx7d7yd7v2xdgzmyxnr7ht4ghh6hcjqb",
"details": {
"category": "Underholdning",
"description": "Sådan laver du fede ting med pap og lim",
"tags": ["wow", "pap", "og", "lim", "diy", "kreativ"],
"title": "10 ting du kan lave med pap & lim og en masse"
},
"isApproved": true,
"privacy": "public"
}
{
"_creationTime": 1705061346057.3284,
"_id": "rx7d7yd7v2xdgzmyxnr7ht4ghh6hcjqb",
"details": {
"category": "Underholdning",
"description": "Sådan laver du fede ting med pap og lim",
"tags": ["wow", "pap", "og", "lim", "diy", "kreativ"],
"title": "10 ting du kan lave med pap & lim og en masse"
},
"isApproved": true,
"privacy": "public"
}
10 Replies
oscklm
oscklmOP12mo ago
Alright, so now i resolved it by changing the title of the document in the dashboard. And switching isApproved to false and back to true. But i'd still like to know, if its known what could've caused this? I wouldn't want certain docs all of a sudden be unable to appear in search results, out of nowhere
Michal Srb
Michal Srb12mo ago
That sounds unexpected, @Sam J can you tell what's going on?
Sam J
Sam J12mo ago
Thanks for the report. Search indexes are periodically rebuilt with updated documents. I expect the rebuild is what I expect triggered the change. That should not change the results though, so assuming nothing else about your query, document or index definition changed, it sounds like a bug on our part. I'll look in to it. Can you provide your instance name?
oscklm
oscklmOP12mo ago
Gotcha, I sent you a dm with some more info. Ping me if you need anything else
Sam J
Sam J12mo ago
Thanks - one more question, how many results do you get when you run searches for those queries? Oh disregard, saw your DM. As long as it's always basically just the document that's useful (rules out ranking issues)
oscklm
oscklmOP12mo ago
Just returning to this, so since searchIndex isn't working as expected. Can you recommend any alternative approach for making a search query in the meanwhile?
Michal Srb
Michal Srb12mo ago
I think we'll resolve the underlying issue here, but we're observing a holiday in the US, so you'll have to wait until tomorrow (+ however long it'll take to fix). I'd continue using the search API while you're developing, unless you need to ship it to production today.
oscklm
oscklmOP12mo ago
Gotcha. Then we can definitely wait, we aren’t looking shipping this to production and testing it in a closed beta before around the 26th this month. Thanks Michael
Sam J
Sam J12mo ago
Sorry for the delay, the fix for this should now be deployed!
oscklm
oscklmOP12mo ago
Thanks a lot for resolving the issue. I can confirm it's working as expected now.

Did you find this page helpful?