Search on shopifyProduct is broken

This screenshot tells me the search index was never generated on this new merchant who just installed our app. Verified the product with title contains "OCEAN" is in our database
await api.shopifyProduct.findMany({
filter: { shop: { equals: 7492XXXX } },
select: { id: true, title: true, handle: true },

})


OUTPUT:
GadgetRecord_{
__typename:"ShopifyProduct"
handle:"ocean-wave-cube-lamp-16-color-ambient-led-light"
id:"8992814727412"
title:"Ocean Wave Cube Lamp - 16-Color Ambient LED Light"
};
await api.shopifyProduct.findMany({
filter: { shop: { equals: 7492XXXX } },
select: { id: true, title: true, handle: true },

})


OUTPUT:
GadgetRecord_{
__typename:"ShopifyProduct"
handle:"ocean-wave-cube-lamp-16-color-ambient-led-light"
id:"8992814727412"
title:"Ocean Wave Cube Lamp - 16-Color Ambient LED Light"
};
Verified Gadget's search index is broken
await api.shopifyProduct.findMany({
filter: { shop: { equals: 74920165620 } },
select: { id: true, title: true, handle: true },
search: "Ocean",
})

OUTPUT:
Array(0)[];
await api.shopifyProduct.findMany({
filter: { shop: { equals: 74920165620 } },
select: { id: true, title: true, handle: true },
search: "Ocean",
})

OUTPUT:
Array(0)[];
How can I debug the search index's status for the shopifyProduct table?
No description
17 Replies
ljspoor94
ljspoor94•5mo ago
Pretty certain the following won't work, you're trying to do related filtering and search at the same time and this isn't supported. You should just filter directly on shopId which you should have on the shopifyProduct model.
await api.shopifyProduct.findMany({
filter: { shop: { equals: 74920165620 } },
select: { id: true, title: true, handle: true },
search: "Ocean",
})
await api.shopifyProduct.findMany({
filter: { shop: { equals: 74920165620 } },
select: { id: true, title: true, handle: true },
search: "Ocean",
})
evidanary
evidanaryOP•5mo ago
So somethign like this? Instead of: filter: { shop: { equals: 74920165620 } }, Have: filter: { shopId: 74920165620 }, AND filter: { shopId: { equals: 74920165620 } }, Both give me an error . Perhaps I got your recommendation wrong @ljspoor94 ?
ljspoor94
ljspoor94•5mo ago
What error?
evidanary
evidanaryOP•5mo ago
First one gve me CombinedError:"[GraphQL] Variable "$filter" got invalid value 74920165620 at "filter.shopId"; Expected type "IDFilter" to be an object Second one didnt give an error but returned empty. So still not doing what I want.
ljspoor94
ljspoor94•5mo ago
Thats expected for the first one, you have to pass an object against the field
evidanary
evidanaryOP•5mo ago
For the second one, I passed the shopId instead of Shop as you recommended, but search still not working.
Chocci_Milk
Chocci_Milk•5mo ago
Please note that searching is done on a completely separate database than what filter is run on (ElasticSearch). For that reason you can't search and filter at the same time. I would recommend that you add some functionality to search with a startsWith filter. I typically recommend that you have a lowercase version of the searched on field so that your users don't need to have an exactly match
evidanary
evidanaryOP•5mo ago
is there a "contains" ? startsWith wont work for our use case as merchants often ONLY know keywords in the product and are often not sure of the first few letters.
Chocci_Milk
Chocci_Milk•5mo ago
No, there isn't a contains, yet
evidanary
evidanaryOP•5mo ago
😦 for my own future reference - is there a doc on gadget I can read that lists all teh filter options? Anotine, I want to implement a simple product search box. To reiterate what you said, the CANONICAL way of searching for products in Gadget is to: 1. Lowercase the product title and store it in a separate field on shopifyProduct 2. In the product UI jsx make a call like this:
api.shopifyProduct.findMany({
filter: { shop: { equals: shop }, lowercasetitle: {startsWith: "Ocean"} }, },
select: { id: true, title: true, handle: true },
}),
api.shopifyProduct.findMany({
filter: { shop: { equals: shop }, lowercasetitle: {startsWith: "Ocean"} }, },
select: { id: true, title: true, handle: true },
}),
Did I get that correct Antoine? Ideally if we can do something like then it'd be awesome.
api.shopifyProduct.findMany({
select: { id: true, title: true, handle: true },
search: "Ocean",
}),
api.shopifyProduct.findMany({
select: { id: true, title: true, handle: true },
search: "Ocean",
}),
Here I'm assuming that the api object has inbuilt mechanisms to filter based on the shop from the session. But not sure if the latter is possible.
ljspoor94
ljspoor94•5mo ago
Are you doing this on the front-end or back? Because if its the front-end, you don't need to filter by shopId as tenancy will handle that for you, and you can just use search then.
evidanary
evidanaryOP•5mo ago
Yes doing it on front end @ljspoor94 This solves my problem. Thanks! Antoine, is it ever possible that the database used for searching is behind / not in sync with the regular database? I ask because I’d like to know the most reliable method for the merchant to search their products immediately after app installation. Do you see a risk to use search in this case? For eg if there is index generation work that typically takes a while then we should not use the search feature. In that case we should use the startswith that you recommended.
Chocci_Milk
Chocci_Milk•5mo ago
Do you seem to have a model thats behind? The database should typically be pretty in sync
evidanary
evidanaryOP•5mo ago
This happened yesterday. See screenshot above. It seems to have caught up. Did you folks have a backlog yesterday? Anyhow, if this doesn’t typically happen then I will feel much relieved to use the search database.
Chocci_Milk
Chocci_Milk•5mo ago
I would be surprised that the database was out of date yesterday as people aren't typically working over the weekend so no database or infra errors should have popped up
evidanary
evidanaryOP•5mo ago
Ok. I hope there is some sort of a log that shows the sync delays?
Chocci_Milk
Chocci_Milk•5mo ago
There shouldn't be any sync delays. If you see anything weird, please let us know

Did you find this page helpful?