Skip to content

Commit

Permalink
Merge pull request #32 from decentraland/fix/search-not-working
Browse files Browse the repository at this point in the history
fix: search not working
  • Loading branch information
juanmahidalgo committed Aug 10, 2023
2 parents 2b6972d + 1d4a296 commit ccaae8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions src/ports/catalog/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ export async function createCatalogComponent(components: Pick<AppComponents, 'da
const reducedSchemas = schemas.reduce((acc, curr) => ({ ...acc, ...curr }), {})

if (filters.search) {
let searchResullts: CollectionsItemDBResult[] = []
for (const schema of Object.values(reducedSchemas)) {
const filteredItemsById = await client.query<CollectionsItemDBResult>(getItemIdsBySearchTextQuery(schema, filters.search))
if (filteredItemsById.rowCount === 0) {
// if no items matched the search text, return empty result
return { data: [], total: 0 }
}
filters.ids = [...(filters.ids ?? []), ...filteredItemsById.rows.map(({ id }) => id)]
const searchQuery = getItemIdsBySearchTextQuery(schema, filters.search)
const filteredItemsById = await client.query<CollectionsItemDBResult>(searchQuery)
searchResullts = [...searchResullts, ...filteredItemsById.rows]
}
if (!searchResullts.length) {
// if no items matched the search text, return empty result
return { data: [], total: 0 }
}
filters.ids = [...(filters.ids ?? []), ...searchResullts.map(({ id }) => id)]
}
const query = getCatalogQuery(reducedSchemas, filters)
console.log('query: ', query.text)
Expand Down
4 changes: 2 additions & 2 deletions src/ports/catalog/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const getItemIdsBySearchTextQuery = (schemaVersion: string, search: Catal
const query = SQL`SELECT items.id`
.append(' FROM ')
.append(schemaVersion)
.append('.item AS items WHERE ')
.append('.items AS items WHERE ')
.append(getSearchWhere({ search }))

return query
Expand Down Expand Up @@ -201,7 +201,7 @@ export const getEmotePlayModeWhere = (filters: CatalogFilters) => {
}

export const getSearchWhere = (filters: CatalogFilters) => {
return SQL`items.search_text ILIKE '%' || ${filters.search} || '%'`
return SQL`items.raw_metadata ILIKE '%' || ${filters.search} || '%'`
}

export const getIsSoldOutWhere = () => {
Expand Down

0 comments on commit ccaae8e

Please sign in to comment.