Skip to main content

🏷️ GetSearchResultOptions

TypeScript interface defining all available options for the getSearchResult() function.


📋 Interface Definition

interface GetSearchResultOptions {
query: string;
limit?: number;
cursor?: string;
reverse?: boolean;
sortKey?: SearchSortKey;
types?: SearchType[];
productFilters?: SearchProductFilter[];
prefix?: SearchPrefixQueryType;
unavailableProducts?: SearchUnavailableProductsType;
productMetafields?: CustomMetafieldDefinition[];
variantMetafields?: CustomMetafieldDefinition[];
options?: {
camelizeKeys?: boolean;
resolveFiles?: boolean;
renderRichTextAsHtml?: boolean;
transformProductMetafields?: MetafieldTransformFn;
transformVariantMetafields?: MetafieldTransformFn;
};
}

🔍 Core Properties

query (required)

  • Type: string
  • Description: The search term to query for
  • Example: "solar panels", "renewable energy kit"

limit

  • Type: number
  • Default: 12
  • Range: 1-250
  • Description: Maximum number of results to return

cursor

  • Type: string
  • Description: Pagination cursor for fetching subsequent pages
  • Usage: Use pageInfo.endCursor from previous response

reverse

  • Type: boolean
  • Default: false
  • Description: Whether to reverse the sort order

🎯 Search Configuration

sortKey

  • Type: SearchSortKey
  • Default: "RELEVANCE"
  • Options: "RELEVANCE" | "PRICE" | "CREATED_AT" | "UPDATED_AT"

types

  • Type: SearchType[]
  • Default: ["PRODUCT"]
  • Options: "PRODUCT" | "ARTICLE" | "PAGE"

prefix

  • Type: SearchPrefixQueryType
  • Default: "LAST"
  • Options: "LAST" | "NONE"

unavailableProducts

  • Type: SearchUnavailableProductsType
  • Default: "LAST"
  • Options: "SHOW" | "HIDE" | "LAST"

🎛️ Filter Types

SearchProductFilter

Union type supporting multiple filter options:

type SearchProductFilter =
| { available?: boolean }
| { variantOption?: { name: string; value: string } }
| { productMetafield: { namespace: string; key: string; value: string } }
| { productTag: string }
| { productType: string }
| { price: { min?: number; max?: number } };

Filter Examples:

// Availability filter
{ available: true }

// Price range filter
{ price: { min: 100, max: 1000 } }

// Product tag filter
{ productTag: "renewable-energy" }

// Product type filter
{ productType: "Solar Panel" }

// Variant option filter
{ variantOption: { name: "Color", value: "Black" } }

// Product metafield filter
{ productMetafield: {
namespace: "custom",
key: "category",
value: "residential"
}
}

🏷️ Metafield Configuration

productMetafields

  • Type: CustomMetafieldDefinition[]
  • Description: Array of product metafields to include in results

variantMetafields

  • Type: CustomMetafieldDefinition[]
  • Description: Array of variant metafields to include in results

CustomMetafieldDefinition

interface CustomMetafieldDefinition {
field: string; // e.g., "custom.brand"
type: MetafieldType; // e.g., "single_line_text"
}

Supported Metafield Types:

  • "single_line_text"
  • "multi_line_text"
  • "rich_text"
  • "number_integer"
  • "number_decimal"
  • "date"
  • "date_time"
  • "boolean"
  • "url"
  • "json"
  • "color"
  • "weight"
  • "volume"
  • "dimension"
  • "rating"
  • "file_reference"
  • "page_reference"
  • "product_reference"
  • "variant_reference"
  • "collection_reference"

🔧 Processing Options

options.camelizeKeys

  • Type: boolean
  • Default: true
  • Description: Convert metafield keys from snake_case to camelCase

options.resolveFiles

  • Type: boolean
  • Default: true
  • Description: Automatically resolve file metafields to full URLs

options.renderRichTextAsHtml

  • Type: boolean
  • Default: false
  • Description: Convert rich text metafields to HTML strings

options.transformProductMetafields

  • Type: MetafieldTransformFn
  • Description: Custom function to transform product metafields

options.transformVariantMetafields

  • Type: MetafieldTransformFn
  • Description: Custom function to transform variant metafields

MetafieldTransformFn

type MetafieldTransformFn = (
raw: Record<string, any>,
casted: Record<string, any>
) => Record<string, any>;

Example:

transformProductMetafields: (raw, casted) => ({
...casted,
summary: `${casted["custom.brand"]} - ${casted["custom.power"]}W`,
displayPrice: `$${casted["custom.price"] || 0}`,
});

✅ Next: Result Types →