Skip to main content

⚙️ getSearchResult() Options

Complete reference for all available options when using getSearchResult().


🔍 Basic Options

query (required)

  • Type: string
  • Description: The search term to query for
  • Example: "solar panels", "renewable energy"
await getSearchResult({
query: "solar kit 9kw",
});

limit

  • Type: number
  • Default: 12
  • Description: Number of results to return per page
  • Range: 1-250
await getSearchResult({
query: "solar panels",
limit: 24,
});

cursor

  • Type: string
  • Description: Pagination cursor for fetching next/previous page
  • Usage: Use pageInfo.endCursor from previous response
await getSearchResult({
query: "solar panels",
cursor: "eyJsYXN0X2lkIjo...",
});

🎯 Search Configuration

types

  • Type: SearchType[]
  • Default: ["PRODUCT"]
  • Options: "PRODUCT", "ARTICLE", "PAGE"
  • Description: Types of content to search
// Search only products (default)
await getSearchResult({
query: "solar",
types: ["PRODUCT"],
});

// Search products and articles
await getSearchResult({
query: "installation guide",
types: ["PRODUCT", "ARTICLE"],
});

unavailableProducts

  • Type: SearchUnavailableProductsType
  • Default: "LAST"
  • Options: "SHOW", "HIDE", "LAST"
  • Description: How to handle unavailable products
// Hide unavailable products
await getSearchResult({
query: "solar panels",
unavailableProducts: "HIDE",
});

prefix

  • Type: SearchPrefixQueryType
  • Default: "LAST"
  • Options: "LAST", "NONE"
  • Description: Search prefix behavior

📊 Sorting Options

sortKey

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

reverse

  • Type: boolean
  • Default: false
  • Description: Reverse the sort order
// Sort by price, lowest first
await getSearchResult({
query: "solar panels",
sortKey: "PRICE",
reverse: false,
});

// Sort by price, highest first
await getSearchResult({
query: "solar panels",
sortKey: "PRICE",
reverse: true,
});

🎛️ Product Filters

productFilters

  • Type: SearchProductFilter[]
  • Description: Array of filters to apply to product results

Available Filter Types:

Availability Filter:

{
available: true;
} // Only available products
{
available: false;
} // Only unavailable products

Price Range Filter:

{ price: { min: 100, max: 1000 } }  // Between $100-$1000
{ price: { min: 500 } } // $500 and above
{ price: { max: 200 } } // $200 and below

Product Tag Filter:

{
productTag: "renewable-energy";
}
{
productTag: "solar";
}

Product Type Filter:

{
productType: "Solar Panel";
}
{
productType: "Inverter";
}

Variant Option Filter:

{ variantOption: { name: "Color", value: "Black" } }
{ variantOption: { name: "Size", value: "Large" } }

Product Metafield Filter:

{ productMetafield: {
namespace: "custom",
key: "category",
value: "residential"
}
}

Complete Filter Example:

await getSearchResult({
query: "solar kit",
productFilters: [
{ available: true },
{ price: { min: 500, max: 2000 } },
{ productTag: "complete-kit" },
{ productType: "Solar Kit" },
{ variantOption: { name: "Power", value: "9kW" } },
{
productMetafield: {
namespace: "custom",
key: "installation",
value: "residential",
},
},
],
});

🏷️ Metafields

productMetafields

  • Type: CustomMetafieldDefinition[]
  • Description: Product metafields to include in results

variantMetafields

  • Type: CustomMetafieldDefinition[]
  • Description: Variant metafields to include in results
await getSearchResult({
query: "solar panels",
productMetafields: [
{ field: "custom.warranty_years", type: "number_integer" },
{ field: "custom.efficiency_rating", type: "number_decimal" },
{ field: "custom.installation_guide", type: "rich_text" },
],
variantMetafields: [
{ field: "custom.power_output", type: "number_integer" },
{ field: "custom.dimensions", type: "single_line_text" },
],
});

🔧 Processing Options

options

  • Type: object
  • Description: Additional processing options
await getSearchResult({
query: "solar panels",
options: {
camelizeKeys: true, // Convert keys to camelCase
resolveFiles: true, // Resolve file metafields
renderRichTextAsHtml: true, // Convert rich text to HTML
transformProductMetafields: (raw, casted) => ({
...casted,
summary: `${casted["custom.brand"]} - ${casted["custom.power"]}W`,
}),
transformVariantMetafields: (raw, casted) => ({
...casted,
displayName: `${casted["custom.power"]}W ${casted["custom.color"]}`,
}),
},
});

Processing Options Details:

  • camelizeKeys: Convert metafield keys from custom.field_name to customFieldName
  • resolveFiles: Automatically resolve file metafields to full URLs
  • renderRichTextAsHtml: Convert rich text metafields to HTML strings
  • transformProductMetafields: Custom function to transform product metafields
  • transformVariantMetafields: Custom function to transform variant metafields

✅ Next: Examples →