1 {"slug":"/references/utils/utils.SearchUtils","title":"SearchUtils","frontmatter":{},"toc":[{"title":"Classes","id":"classes","level":2},{"title":"Functions","id":"functions","level":2},{"title":"Interfaces","id":"interfaces","level":2},{"title":"Type Aliases","id":"type-aliases","level":2},{"title":"Variables","id":"variables","level":2},{"title":"Functions","id":"functions-1","level":2},{"title":"defineSearchIndex","id":"definesearchindex","level":3},{"title":"Type Parameters","id":"definesearchindex-type-parameters","level":4},{"title":"Parameters","id":"definesearchindex-parameters","level":4},{"title":"Returns","id":"definesearchindex-returns","level":4},{"title":"extractPrimaryKeyFilter","id":"extractprimarykeyfilter","level":3},{"title":"Parameters","id":"extractprimarykeyfilter-parameters","level":4},{"title":"Returns","id":"extractprimarykeyfilter-returns","level":4},{"title":"graphConsume","id":"graphconsume","level":3},{"title":"Example","id":"example","level":4},{"title":"Type Parameters","id":"graphconsume-type-parameters","level":4},{"title":"Parameters","id":"graphconsume-parameters","level":4},{"title":"Returns","id":"graphconsume-returns","level":4},{"title":"graphSeed","id":"graphseed","level":3},{"title":"Example","id":"example-1","level":4},{"title":"Type Parameters","id":"graphseed-type-parameters","level":4},{"title":"Parameters","id":"graphseed-parameters","level":4},{"title":"Returns","id":"graphseed-returns","level":4},{"title":"projectDocument","id":"projectdocument","level":3},{"title":"Parameters","id":"projectdocument-parameters","level":4},{"title":"Returns","id":"projectdocument-returns","level":4},{"title":"readDocumentPath","id":"readdocumentpath","level":3},{"title":"Parameters","id":"readdocumentpath-parameters","level":4},{"title":"Returns","id":"readdocumentpath-returns","level":4},{"title":"searchValueToBoolean","id":"searchvaluetoboolean","level":3},{"title":"Parameters","id":"searchvaluetoboolean-parameters","level":4},{"title":"Returns","id":"searchvaluetoboolean-returns","level":4},{"title":"searchValueToNumber","id":"searchvaluetonumber","level":3},{"title":"Parameters","id":"searchvaluetonumber-parameters","level":4},{"title":"Returns","id":"searchvaluetonumber-returns","level":4},{"title":"setDocumentPath","id":"setdocumentpath","level":3},{"title":"Parameters","id":"setdocumentpath-parameters","level":4},{"title":"Variables","id":"variables-1","level":2},{"title":"search","id":"search","level":3}],"blocks":[{"kind":"heading","level":2,"text":"Classes","id":"classes"},{"kind":"linkList","items":[{"title":"SearchBuilder","href":"/references/utils/SearchUtils/classes/utils.SearchUtils.SearchBuilder"},{"title":"SearchFieldsSchema","href":"/references/utils/SearchUtils/classes/utils.SearchUtils.SearchFieldsSchema"}]},{"kind":"heading","level":2,"text":"Functions","id":"functions"},{"kind":"linkList","items":[{"title":"defineSearchIndex","href":"/references/utils/utils.SearchUtils#definesearchindex"},{"title":"extractPrimaryKeyFilter","href":"/references/utils/utils.SearchUtils#extractprimarykeyfilter"},{"title":"graphConsume","href":"/references/utils/utils.SearchUtils#graphconsume"},{"title":"graphSeed","href":"/references/utils/utils.SearchUtils#graphseed"},{"title":"projectDocument","href":"/references/utils/utils.SearchUtils#projectdocument"},{"title":"readDocumentPath","href":"/references/utils/utils.SearchUtils#readdocumentpath"},{"title":"searchValueToBoolean","href":"/references/utils/utils.SearchUtils#searchvaluetoboolean"},{"title":"searchValueToNumber","href":"/references/utils/utils.SearchUtils#searchvaluetonumber"},{"title":"setDocumentPath","href":"/references/utils/utils.SearchUtils#setdocumentpath"}]},{"kind":"heading","level":2,"text":"Interfaces","id":"interfaces"},{"kind":"linkList","items":[{"title":"SearchGraphConsumeOptions","href":"/references/utils/SearchUtils/interfaces/utils.SearchUtils.SearchGraphConsumeOptions"},{"title":"SearchGraphSeedOptions","href":"/references/utils/SearchUtils/interfaces/utils.SearchUtils.SearchGraphSeedOptions"},{"title":"SearchGraphSourceOptions","href":"/references/utils/SearchUtils/interfaces/utils.SearchUtils.SearchGraphSourceOptions"}]},{"kind":"heading","level":2,"text":"Type Aliases","id":"type-aliases"},{"kind":"linkList","items":[{"title":"SearchConsumeEvent","href":"/references/utils/SearchUtils/types/utils.SearchUtils.SearchConsumeEvent"},{"title":"SearchGraphQueryContext","href":"/references/utils/SearchUtils/types/utils.SearchUtils.SearchGraphQueryContext"}]},{"kind":"heading","level":2,"text":"Variables","id":"variables"},{"kind":"linkList","items":[{"title":"search","href":"/references/utils/utils.SearchUtils#search"}]},{"kind":"heading","level":2,"text":"Functions","id":"functions-1"},{"kind":"heading","level":3,"text":"defineSearchIndex","id":"definesearchindex"},{"kind":"markdown","html":"Declares a search index. Like `defineLink`, the file registers itself on\nimport: the application loads every file under `search/` and hands what was\nregistered to the Search Module as its `indexes` option, so the module has one\ninput rather than a registry and an option that can disagree.\n\n`fields` must be a schema from `search.define({ ... })`. The documents\n`seed` yields are type-checked against the declared fields."},{"kind":"heading","level":4,"text":"Type Parameters","id":"definesearchindex-type-parameters"},{"kind":"typeList","sectionTitle":"defineSearchIndex","types":[{"name":"Fields","type":"[SearchFieldsSchemaLike](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchFieldsSchemaLike)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":4,"text":"Parameters","id":"definesearchindex-parameters"},{"kind":"typeList","sectionTitle":"defineSearchIndex","types":[{"name":"definition","type":"[SearchIndexDefinitionInput](/references/types/SearchTypes/types/types.SearchTypes.SearchIndexDefinitionInput)&#60;Fields&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"name","type":"`string`","description":"The index's unique name, which is what `query.search({ entity })` resolves\nagainst.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"entity","type":"`string`","description":"The `query.graph` entrypoint used to hydrate non-indexed fields.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"primary_key","type":"`string`","description":"The field whose value keys the index's documents, which is what a hit's `id`\nholds.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"provider","type":"`string`","description":"The identifier of the provider backing this index. Defaults to the module's\nconfigured default provider.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"settings","type":"[SearchIndexSettings](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchIndexSettings)","description":"The settings applied to the index when it's created or migrated.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"typo_tolerance","type":"`object`","description":"How misspelled terms are matched.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"distinct_attribute","type":"`string`","description":"The dotted path of a field that hits are deduplicated by, returning at most\none hit per distinct value. Overridden per query by `search_options.distinct`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_options","type":"`Record<string, Record&#60;string, unknown&#62;>`","description":"Index settings specific to a search engine, keyed by provider identifier.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"events","type":"`string`[]","description":"Events related and that can affect the data for this index.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"Fields","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"seed","type":"(`context`: [SearchSeedContext](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchSeedContext)) => AsyncIterable&#60;[SearchIndexSeedMutation](/references/types/SearchTypes/types/types.SearchTypes.SearchIndexSeedMutation)&#60;Fields&#62;[]&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"consume","type":"(`event`: [Event](/references/types/EventBusTypes/types/types.EventBusTypes.Event)&#60;any&#62;, `context`: [SearchIngestionContext](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchIngestionContext)) => Promise&#60;[SearchIndexSeedMutation](/references/types/SearchTypes/types/types.SearchTypes.SearchIndexSeedMutation)&#60;Fields&#62;[]&#62;","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":4,"text":"Returns","id":"definesearchindex-returns"},{"kind":"typeList","sectionTitle":"defineSearchIndex","types":[{"name":"name","type":"`string`","description":"The index's unique name, which is what `query.search({ entity })` resolves\nagainst.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"entity","type":"`string`","description":"The `query.graph` entrypoint used to hydrate non-indexed fields.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"primary_key","type":"`string`","description":"The field whose value keys the index's documents, which is what a hit's `id`\nholds.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"provider","type":"`string`","description":"The identifier of the provider backing this index. Defaults to the module's\nconfigured default provider.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`Record<string, [SearchFieldDefinition](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchFieldDefinition)>`","description":"The fields the index holds, keyed by their path in the document.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"type","type":"[SearchFieldKind](/references/types/SearchTypes/types/types.SearchTypes.SearchFieldKind)","description":"The field's type.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"array","type":"`boolean`","description":"Whether the field holds an array of the declared `type`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"searchable","type":"`boolean` \\| `object`","description":"Whether the field is matched against a free-text query, optionally with a\n`weight` boosting its relevance. The weight is applied at build time on some\nengines, such as Meilisearch and Algolia, and at query time on others, such\nas Typesense and Elasticsearch.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"weight","type":"`number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"filterable","type":"`boolean`","description":"Whether the field can be used in a query's filters.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"sortable","type":"`boolean`","description":"Whether results can be sorted by the field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"facetable","type":"`boolean` \\| `object`","description":"Whether the field can be faceted, and which facet types it supports.\nDefaults to `[\"value\"]`, or `[\"range\"]` for numeric and date fields.\n`\"stats\"` is opt-in, since implying it would make numeric fields unusable on\nproviders without aggregations.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"types","type":"[SearchFacetKind](/references/types/SearchTypes/types/types.SearchTypes.SearchFacetKind)[]","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"retrievable","type":"`boolean`","description":"Whether the field comes back on hits. `false` for index-only fields, such as a\nblob used purely for matching. `query.search` reads this to decide which\nrequested fields the engine can serve and which need `query.graph`.\n\nVector fields default to not retrievable — embeddings are not useful on\nhits. Set `retrievable: true`, or `.retrievable()` in the DSL, to return\nthem.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`Record<string, [SearchFieldDefinition](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchFieldDefinition)>`","description":"The fields of a nested object, only used when `type` is `object`.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"type","type":"[SearchFieldKind](/references/types/SearchTypes/types/types.SearchTypes.SearchFieldKind)","description":"The field's type.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"array","type":"`boolean`","description":"Whether the field holds an array of the declared `type`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"searchable","type":"`boolean` \\| `object`","description":"Whether the field is matched against a free-text query, optionally with a\n`weight` boosting its relevance. The weight is applied at build time on some\nengines, such as Meilisearch and Algolia, and at query time on others, such\nas Typesense and Elasticsearch.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"filterable","type":"`boolean`","description":"Whether the field can be used in a query's filters.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"sortable","type":"`boolean`","description":"Whether results can be sorted by the field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"facetable","type":"`boolean` \\| `object`","description":"Whether the field can be faceted, and which facet types it supports.\nDefaults to `[\"value\"]`, or `[\"range\"]` for numeric and date fields.\n`\"stats\"` is opt-in, since implying it would make numeric fields unusable on\nproviders without aggregations.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"retrievable","type":"`boolean`","description":"Whether the field comes back on hits. `false` for index-only fields, such as a\nblob used purely for matching. `query.search` reads this to decide which\nrequested fields the engine can serve and which need `query.graph`.\n\nVector fields default to not retrievable — embeddings are not useful on\nhits. Set `retrievable: true`, or `.retrievable()` in the DSL, to return\nthem.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`Record<string, [SearchFieldDefinition](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchFieldDefinition)>`","description":"The fields of a nested object, only used when `type` is `object`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"dimensions","type":"`number`","description":"The dimensionality of the embedding stored in a `type: \"vector\"` field.\nRequired for vector fields; meaningless on any other type. When `embed` is\nomitted, every vector written to the field must have exactly this many\ncomponents.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"embed","type":"`boolean`","description":"When `true` on a vector field, documents pass a string and the engine\nembeds it at write time, and for `search_options.vector.query` at query\ntime. Omit `embed` to supply embeddings yourself as a `number[]`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_options","type":"`Record<string, Record&#60;string, unknown&#62;>`","description":"Field options specific to a search engine, keyed by provider identifier, such\nas `{ meilisearch: { ... } }`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"dimensions","type":"`number`","description":"The dimensionality of the embedding stored in a `type: \"vector\"` field.\nRequired for vector fields; meaningless on any other type. When `embed` is\nomitted, every vector written to the field must have exactly this many\ncomponents.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"embed","type":"`boolean`","description":"When `true` on a vector field, documents pass a string and the engine\nembeds it at write time, and for `search_options.vector.query` at query\ntime. Omit `embed` to supply embeddings yourself as a `number[]`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_options","type":"`Record<string, Record&#60;string, unknown&#62;>`","description":"Field options specific to a search engine, keyed by provider identifier, such\nas `{ meilisearch: { ... } }`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"settings","type":"[SearchIndexSettings](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchIndexSettings)","description":"The settings applied to the index when it's created or migrated.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"typo_tolerance","type":"`object`","description":"How misspelled terms are matched.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"enabled","type":"`boolean`","description":"Whether typo tolerance is enabled at all.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"min_word_size_for_one_typo","type":"`number`","description":"The shortest term length that tolerates a single typo. A provider with a\nhigher floor of its own rejects a shorter length from `upsertIndex`; one\nthat doesn't match by edit distance at all ignores this.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"min_word_size_for_two_typos","type":"`number`","description":"The shortest term length that tolerates two typos. Cannot be lower than\n`min_word_size_for_one_typo`. Ignored by a provider that doesn't match by\nedit distance.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"disabled_on_attributes","type":"`string`[]","description":"The dotted paths of the fields that must always match exactly, such as a\nSKU or a handle. A provider that can't exclude a single field rejects\nthis rather than fuzzy-matching it anyway.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"distinct_attribute","type":"`string`","description":"The dotted path of a field that hits are deduplicated by, returning at most\none hit per distinct value. Overridden per query by `search_options.distinct`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_options","type":"`Record<string, Record&#60;string, unknown&#62;>`","description":"Index settings specific to a search engine, keyed by provider identifier.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"events","type":"`string`[]","description":"Events related and that can affect the data for this index.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"consume","type":"(`event`: [Event](/references/types/EventBusTypes/types/types.EventBusTypes.Event)&#60;any&#62;, `context`: [SearchIngestionContext](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchIngestionContext)) => Promise&#60;[SearchMutation](/references/types/SearchTypes/types/types.SearchTypes.SearchMutation)[]&#62;","description":"Executed on event ingestion to determine the action that needs to be performed on the index.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"seed","type":"(`context`: [SearchSeedContext](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchSeedContext)) => AsyncIterable&#60;[SearchMutation](/references/types/SearchTypes/types/types.SearchTypes.SearchMutation)[]&#62;","description":"Yields mutations in batches — the same shape `consume` returns, so a\nseed can express a delete, not just an upsert. Ran when there is no data\nin the index, on reindex, and for the catch-up pass after a full seed.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":3,"text":"extractPrimaryKeyFilter","id":"extractprimarykeyfilter"},{"kind":"markdown","html":"Recognises a filter that is nothing but primary-key membership, so a delete\ncan go straight to the id lookup instead of compiling the filter tree."},{"kind":"heading","level":4,"text":"Parameters","id":"extractprimarykeyfilter-parameters"},{"kind":"typeList","sectionTitle":"extractPrimaryKeyFilter","types":[{"name":"filters","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"$and","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)[]","description":"Filters that must all match.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"$and","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)[]","description":"Filters that must all match.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"$or","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)[]","description":"Filters of which at least one must match.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"$not","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)","description":"Filters that must not match.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"The free-text query. Sits among the filters so a `query.graph` call converts\nto `query.search` unchanged; the module lifts it out before compiling the\nrest, so a provider never sees `q` as a field.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"$or","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)[]","description":"Filters of which at least one must match.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"$and","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)[]","description":"Filters that must all match.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"$or","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)[]","description":"Filters of which at least one must match.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"$not","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)","description":"Filters that must not match.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"The free-text query. Sits among the filters so a `query.graph` call converts\nto `query.search` unchanged; the module lifts it out before compiling the\nrest, so a provider never sees `q` as a field.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"$not","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)","description":"Filters that must not match.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"$and","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)[]","description":"Filters that must all match.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"$or","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)[]","description":"Filters of which at least one must match.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"$not","type":"[SearchFilters](/references/types/SearchTypes/types/types.SearchTypes.SearchFilters)","description":"Filters that must not match.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"The free-text query. Sits among the filters so a `query.graph` call converts\nto `query.search` unchanged; the module lifts it out before compiling the\nrest, so a provider never sees `q` as a field.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"q","type":"`string`","description":"The free-text query. Sits among the filters so a `query.graph` call converts\nto `query.search` unchanged; the module lifts it out before compiling the\nrest, so a provider never sees `q` as a field.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"plan","type":"`object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"primary_key","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":4,"text":"Returns","id":"extractprimarykeyfilter-returns"},{"kind":"typeList","sectionTitle":"extractPrimaryKeyFilter","types":[{"name":"undefined \\| string[]","type":"`undefined` \\| `string`[]","optional":false,"defaultValue":"","description":"Recognises a filter that is nothing but primary-key membership, so a delete\ncan go straight to the id lookup instead of compiling the filter tree.","expandable":false,"children":[]}]},{"kind":"heading","level":3,"text":"graphConsume","id":"graphconsume"},{"kind":"markdown","html":"Builds an index definition's `consume` from a `query.graph` query.\n\nThe event's IDs are read back through `query.graph` and upserted. An ID the\nread doesn't return, or whose row the `transform` rejects, is deleted\ninstead — which is what keeps a row that was removed, unpublished, or\nfiltered out of the index from lingering in it."},{"kind":"heading","level":4,"text":"Example","id":"example"},{"kind":"markdown","html":"```ts\nexport default defineSearchIndex({\n name: \"product\",\n entity: \"product\",\n fields: productFields,\n events: [\"product.created\", \"product.updated\", \"product.deleted\"],\n consume: graphConsume({ fields: [\"id\", \"title\"] }),\n seed: graphSeed({ fields: [\"id\", \"title\"] }),\n})\n```"},{"kind":"heading","level":4,"text":"Type Parameters","id":"graphconsume-type-parameters"},{"kind":"typeList","sectionTitle":"graphConsume","types":[{"name":"Fields","type":"[SearchFieldsSchemaLike](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchFieldsSchemaLike)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"TRow","type":"[GraphRow](/references/utils/types/utils.GraphRow)","description":"`seed`\n\n and \n\n`consume`\n\n implementations backed by \n\n`query.graph`\n\n.\n\nNearly every index is a projection of an entity that already lives behind\n\n\n`query.graph`\n\n, so the helpers simplify catchup, soft-deletes and similar,\nwhich should be enough for most use cases.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":4,"text":"Parameters","id":"graphconsume-parameters"},{"kind":"typeList","sectionTitle":"graphConsume","types":[{"name":"options","type":"[SearchGraphConsumeOptions](/references/utils/SearchUtils/interfaces/utils.SearchUtils.SearchGraphConsumeOptions)&#60;Fields, TRow&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"entity","type":"`string`","description":"The `query.graph` entrypoint to read from. Defaults to the index\ndefinition's `entity`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`[]","description":"The fields to select from `query.graph`. Without a `transform` the row is\nindexed as-is, so this should then select exactly what the index declares.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"context","type":"[SearchGraphQueryContext](/references/utils/SearchUtils/types/utils.SearchUtils.SearchGraphQueryContext)","description":"The query context `query.graph` reads the rows with, e.g. the pricing\ncontext `variants.calculated_price` needs. Applied to seed, catch-up and\n`consume` alike.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"transform","type":"(`rows`: TRow[], `context`: [SearchIngestionContext](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchIngestionContext)) => [InferSearchDocumentType](/references/types/SearchTypes/types/types.SearchTypes.InferSearchDocumentType)&#60;Fields&#62;[] \\| Promise&#60;[InferSearchDocumentType](/references/types/SearchTypes/types/types.SearchTypes.InferSearchDocumentType)&#60;Fields&#62;[]&#62;","description":"Maps a page of rows to the documents to index, e.g. `rows.map(toDocument)`.\nAsync, and handed the whole page, so reads `query.graph` cannot make in\none pass — prices in several currencies, say — cost a fixed number of\nqueries per page. Every document must carry the row's primary key value\nas `id`; a row with no document is excluded, which `consume` and the\ncatch-up pass turn into a delete so it leaves the index rather than\ngoing stale in it.\n\nDefaults to indexing the rows as-is.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"resolve_ids","type":"(`event`: [Event](/references/medusa/types/medusa.Event), `context`: [SearchIngestionContext](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchIngestionContext)) => `undefined` \\| `string` \\| `string`[] \\| Promise&#60;undefined \\| string \\| string[]&#62;","description":"The IDs of the documents the event affects, which are read back through\n`query.graph` and written to the index. May be async, e.g. to map an\nevent about a variant or a category to the products it belongs to.\n\nDefaults to `event.data.id`, as a single ID or an array of them.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"is_delete","type":"(`event`: [Event](/references/medusa/types/medusa.Event)) => `boolean`","description":"Whether the event removes its documents from the index rather than\nupdating them. A deleted row can't be read back, so it's deleted by ID\nwithout going to `query.graph`.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":4,"text":"Returns","id":"graphconsume-returns"},{"kind":"typeList","sectionTitle":"graphConsume","types":[{"name":"(event: Event&#60;any&#62;, context: SearchIngestionContext) => Promise&#60;SearchIndexSeedMutation&#60;Fields&#62;[]&#62;","type":"(`event`: [Event](/references/medusa/types/medusa.Event)&#60;any&#62;, `context`: [SearchIngestionContext](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchIngestionContext)) => Promise&#60;[SearchIndexSeedMutation](/references/types/SearchTypes/types/types.SearchTypes.SearchIndexSeedMutation)&#60;Fields&#62;[]&#62;","optional":false,"defaultValue":"","description":"Builds an index definition's `consume` from a `query.graph` query.\n\nThe event's IDs are read back through `query.graph` and upserted. An ID the\nread doesn't return, or whose row the `transform` rejects, is deleted\ninstead — which is what keeps a row that was removed, unpublished, or\nfiltered out of the index from lingering in it.","expandable":false,"children":[]}]},{"kind":"heading","level":3,"text":"graphSeed","id":"graphseed"},{"kind":"markdown","html":"Builds an index definition's `seed` from a `query.graph` query.\n\nThe seed pages the entity in ascending order of the index' primary key, so\nthe next page starts after the last row and a run interrupted halfway\nresumes from the context's `last_key` rather than restarting. The catch-up\npass that follows a full seed reads the rows touched since it started with\nsoft-deleted ones included, and turns those — along with any row the\n`transform` rejects — into deletes."},{"kind":"heading","level":4,"text":"Example","id":"example-1"},{"kind":"markdown","html":"```ts\nconst productFields = search.define({\n id: search.keyword().filterable(),\n title: search.text().searchable(),\n})\n\nexport default defineSearchIndex({\n name: \"product\",\n entity: \"product\",\n fields: productFields,\n seed: graphSeed({ fields: [\"id\", \"title\"] }),\n})\n```"},{"kind":"heading","level":4,"text":"Type Parameters","id":"graphseed-type-parameters"},{"kind":"typeList","sectionTitle":"graphSeed","types":[{"name":"Fields","type":"[SearchFieldsSchemaLike](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchFieldsSchemaLike)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"TRow","type":"[GraphRow](/references/utils/types/utils.GraphRow)","description":"`seed`\n\n and \n\n`consume`\n\n implementations backed by \n\n`query.graph`\n\n.\n\nNearly every index is a projection of an entity that already lives behind\n\n\n`query.graph`\n\n, so the helpers simplify catchup, soft-deletes and similar,\nwhich should be enough for most use cases.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":4,"text":"Parameters","id":"graphseed-parameters"},{"kind":"typeList","sectionTitle":"graphSeed","types":[{"name":"options","type":"[SearchGraphSeedOptions](/references/utils/SearchUtils/interfaces/utils.SearchUtils.SearchGraphSeedOptions)&#60;Fields, TRow&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"entity","type":"`string`","description":"The `query.graph` entrypoint to read from. Defaults to the index\ndefinition's `entity`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`[]","description":"The fields to select from `query.graph`. Without a `transform` the row is\nindexed as-is, so this should then select exactly what the index declares.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"context","type":"[SearchGraphQueryContext](/references/utils/SearchUtils/types/utils.SearchUtils.SearchGraphQueryContext)","description":"The query context `query.graph` reads the rows with, e.g. the pricing\ncontext `variants.calculated_price` needs. Applied to seed, catch-up and\n`consume` alike.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"transform","type":"(`rows`: TRow[], `context`: [SearchIngestionContext](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchIngestionContext)) => [InferSearchDocumentType](/references/types/SearchTypes/types/types.SearchTypes.InferSearchDocumentType)&#60;Fields&#62;[] \\| Promise&#60;[InferSearchDocumentType](/references/types/SearchTypes/types/types.SearchTypes.InferSearchDocumentType)&#60;Fields&#62;[]&#62;","description":"Maps a page of rows to the documents to index, e.g. `rows.map(toDocument)`.\nAsync, and handed the whole page, so reads `query.graph` cannot make in\none pass — prices in several currencies, say — cost a fixed number of\nqueries per page. Every document must carry the row's primary key value\nas `id`; a row with no document is excluded, which `consume` and the\ncatch-up pass turn into a delete so it leaves the index rather than\ngoing stale in it.\n\nDefaults to indexing the rows as-is.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"batch_size","type":"`number`","description":"The number of rows read from `query.graph` per page.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":4,"text":"Returns","id":"graphseed-returns"},{"kind":"typeList","sectionTitle":"graphSeed","types":[{"name":"(context: SearchSeedContext) => AsyncIterable&#60;SearchIndexSeedMutation&#60;Fields&#62;[]&#62;","type":"(`context`: [SearchSeedContext](/references/types/SearchTypes/interfaces/types.SearchTypes.SearchSeedContext)) => AsyncIterable&#60;[SearchIndexSeedMutation](/references/types/SearchTypes/types/types.SearchTypes.SearchIndexSeedMutation)&#60;Fields&#62;[]&#62;","optional":false,"defaultValue":"","description":"Builds an index definition's `seed` from a `query.graph` query.\n\nThe seed pages the entity in ascending order of the index' primary key, so\nthe next page starts after the last row and a run interrupted halfway\nresumes from the context's `last_key` rather than restarting. The catch-up\npass that follows a full seed reads the rows touched since it started with\nsoft-deleted ones included, and turns those — along with any row the\n`transform` rejects — into deletes.","expandable":false,"children":[]}]},{"kind":"heading","level":3,"text":"projectDocument","id":"projectdocument"},{"kind":"markdown","html":"Narrows a source document to the requested dotted paths, keeping the shape\nof intermediate objects and arrays."},{"kind":"heading","level":4,"text":"Parameters","id":"projectdocument-parameters"},{"kind":"typeList","sectionTitle":"projectDocument","types":[{"name":"source","type":"`Record<string, unknown>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"paths","type":"`string`[]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":4,"text":"Returns","id":"projectdocument-returns"},{"kind":"typeList","sectionTitle":"projectDocument","types":[{"name":"Record","type":"`Record<string, unknown>`","optional":false,"defaultValue":"","description":"Narrows a source document to the requested dotted paths, keeping the shape\nof intermediate objects and arrays.","expandable":false,"children":[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]},{"name":"unknown","type":"`unknown`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":3,"text":"readDocumentPath","id":"readdocumentpath"},{"kind":"markdown","html":"Walks a dotted path, flattening through arrays encountered on the way —\narrays of objects collapse to per-leaf arrays, which keeps index\ndefinitions portable across providers."},{"kind":"heading","level":4,"text":"Parameters","id":"readdocumentpath-parameters"},{"kind":"typeList","sectionTitle":"readDocumentPath","types":[{"name":"source","type":"`unknown`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"segments","type":"`string`[]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":4,"text":"Returns","id":"readdocumentpath-returns"},{"kind":"typeList","sectionTitle":"readDocumentPath","types":[{"name":"unknown[]","type":"`unknown`[]","optional":false,"defaultValue":"","description":"Walks a dotted path, flattening through arrays encountered on the way —\narrays of objects collapse to per-leaf arrays, which keeps index\ndefinitions portable across providers.","expandable":false,"children":[{"name":"unknown","type":"`unknown`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":3,"text":"searchValueToBoolean","id":"searchvaluetoboolean"},{"kind":"heading","level":4,"text":"Parameters","id":"searchvaluetoboolean-parameters"},{"kind":"typeList","sectionTitle":"searchValueToBoolean","types":[{"name":"value","type":"`unknown`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":4,"text":"Returns","id":"searchvaluetoboolean-returns"},{"kind":"typeList","sectionTitle":"searchValueToBoolean","types":[{"name":"boolean","type":"`boolean`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]},{"kind":"heading","level":3,"text":"searchValueToNumber","id":"searchvaluetonumber"},{"kind":"heading","level":4,"text":"Parameters","id":"searchvaluetonumber-parameters"},{"kind":"typeList","sectionTitle":"searchValueToNumber","types":[{"name":"value","type":"`unknown`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"isDate","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":4,"text":"Returns","id":"searchvaluetonumber-returns"},{"kind":"typeList","sectionTitle":"searchValueToNumber","types":[{"name":"undefined \\| number","type":"`undefined` \\| `number`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]},{"kind":"heading","level":3,"text":"setDocumentPath","id":"setdocumentpath"},{"kind":"markdown","html":"Writes a value at a dotted path, creating intermediate objects."},{"kind":"heading","level":4,"text":"Parameters","id":"setdocumentpath-parameters"},{"kind":"typeList","sectionTitle":"setDocumentPath","types":[{"name":"target","type":"`Record<string, any>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"path","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`unknown`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":2,"text":"Variables","id":"variables-1"},{"kind":"heading","level":3,"text":"search","id":"search"},{"kind":"markdown","html":"`Const` **search**: [SearchBuilder](/references/utils/SearchUtils/classes/utils.SearchUtils.SearchBuilder)"},{"kind":"markdown","html":"Singleton used to define search index field schemas:\n\n```ts\nimport { defineSearchIndex, search } from \"@medusajs/framework/utils\"\n\ndefineSearchIndex({\n name: \"product\",\n entity: \"product\",\n fields: search.define({\n id: search.keyword().filterable(),\n title: search.text().searchable({ weight: 3 }),\n }),\n async *seed() {},\n})\n```"}]}