Skip to content

MedusaSearchQueryAdapter

Adapter in @evolve-framework/medusa

Product search answered by Medusa's own Search module, through POST /store/search, against the index @evolve-framework/medusa-plugin-search declares.

import { MedusaSearchQueryAdapter } from "@evolve-framework/medusa/search";
new MedusaSearchQueryAdapter(options: MedusaSearchQueryAdapterOptions)
OptionTypeDescription
clientFactory?ClientFactory

Resolves a Store API client per store and locale.

matching?MedusaSearchMatching

How a typed term is matched. Left out, the last term is a prefix and a term that finds nothing is asked again with typos forgiven.

facetLabels?FacetLabels

Labels for attribute facets, by attribute name without attr_.

categoryFacet?boolean

Count products per category, under commercetools' categories key. Off until the index declares category_ids facetable; Medusa refuses to count a field it was not told to.

maxResults?number

The most hits the Search module's provider can page through. Medusa sets no limit itself; a provider backed by a search engine has that engine's.

client?Medusa

One Store API client, for a caller that already holds the right one.

MedusaSearchMatching2The fields of matching.
FieldTypeDescription
prefix?boolean
Default: true

Read the last term as a prefix, since it is the one still being typed: "mountain bik" finds the mountain bikes. Off, every term has to be a complete word.

typoFallback?boolean | { fields: (locale: string) => string[]; }
Default: true

Ask again, forgiving a typo, when a term finds nothing. false turns the second attempt off. fields names what it matches on instead of the title in the request's locale — the base title, say, for an index that does not hold every locale the storefront serves.

More

It reads few fields on purpose. The Postgres provider matches a typo by trigram similarity over everything it is pointed at, with a fixed threshold: against descriptions a five-letter word resembles a fifth of a catalogue, and the query takes seconds. Against a title it stays a correction.

MethodDescription
init(): Promise<void>Nothing to connect: every search is one request to Medusa.
search( query: ProductSearchQuery, ): Promise<SearchResponse<ProductDocument>>Run a query and return the documents that matched.