@magento/search-sdk
馃摎 JavaScript library for querying the Live Search API.
Last updated a day ago by bradgarropy .
MITRepositoryBugsOriginal npmTarballpackage.json
$ cnpm install @magento/search-sdk 
SYNC missed versions from official npm registry.

Live Search SDK

???? JavaScript library for querying Magento's Live Search API.

Table of Contents

Installation

This SDK can be loaded from a <script> tag or installed with a package manager.

CDN

<script src="https://search-sdk.magento-ds.com/sdk.js"></script>

NPM

npm install @magento/search-sdk

Usage

Create a client

import MagentoLiveSearch from "@magento/search-sdk"

const search = new MagentoLiveSearch({
    environmentId: "beb38e17-2969-46bb-b294-e140ec60c212",
    websiteCode: "base",
    storeCode: "main_website_store",
    storeViewCode: "default",
    apiKey: "search_gql",
})

Product search

search.productSearch({phrase: "yoga"})

Category search

search.categorySearch({phrase: "yoga"})

Quick search

search.quickSearch({phrase: "yoga"})

API Reference

Documentation on each of the methods exposed by the Search SDK.

MagentoLiveSearch

Creates a search client for querying the Live Search API.

Populate all fields with information specific to your Magento account and storefront. The apiKey parameter should be hard coded to search_gql for now. More advanced API keys are coming soon.

Parameter Type Required Example
environmentId string beb38e17-2969-46bb-b294-e140ec60c212
websiteCode string base
storeCode string main_website_store
storeViewCode string default
apiKey string search_gql

productSearch

Best used on a search page to retrieve products and facets for filtering.

Parameter Type Required Default Example
phrase string yoga
page_size number 20 10
current_page string 1 2
filter [] [] [{attribute: "color", eq: "red"}]
sort [] [] [{attribute: "price", direction: "ASC"}]
<summary> Response</summary>
{
    "extensions": {
        "request-id": "Y0g2lhSafEQfQx0Kt9ewCjHObG6yWF8r"
    },
    "data": {
        "productSearch": {
            "total_count": 58,
            "items": [
                {
                    "product": {
                        "__typename": "SimpleProduct",
                        "uid": null,
                        "name": "Yoga Adventure",
                        "sku": "240-LV06",
                        "description": null,
                        "short_description": null,
                        "attribute_set_id": null,
                        "meta_title": null,
                        "meta_keyword": null,
                        "meta_description": null,
                        "image": {
                            "url": "//master-7rqtwti-eragxvhtzr4am.us-4.magentosite.cloud/media/catalog/product/l/t/lt03.jpg",
                            "label": null,
                            "position": null,
                            "disabled": null
                        },
                        "small_image": null,
                        "thumbnail": null,
                        "new_from_date": null,
                        "new_to_date": null,
                        "created_at": null,
                        "updated_at": null,
                        "price_range": {
                            "minimum_price": {
                                "fixed_product_taxes": null,
                                "regular_price": {
                                    "value": null,
                                    "currency": "USD"
                                },
                                "final_price": {
                                    "value": 22,
                                    "currency": "USD"
                                },
                                "discount": null
                            },
                            "maximum_price": null
                        },
                        "gift_message_available": null,
                        "canonical_url": "//master-7rqtwti-eragxvhtzr4am.us-4.magentosite.cloud/yoga-adventure.html",
                        "media_gallery": null,
                        "custom_attributes": null
                    },
                    "highlights": [
                        {
                            "attribute": "name",
                            "value": "Yoga Adventure",
                            "matched_words": []
                        }
                    ]
                }
            ],
            "facets": [
                {
                    "title": "Price zz",
                    "attribute": "price",
                    "buckets": [
                        {
                            "__typename": "ScalarBucket",
                            "title": "32.0",
                            "id": "32.0",
                            "count": 5
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "29.0",
                            "id": "29.0",
                            "count": 4
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "45.0",
                            "id": "45.0",
                            "count": 4
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "0.0",
                            "id": "0.0",
                            "count": 3
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "24.0",
                            "id": "24.0",
                            "count": 3
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "39.0",
                            "id": "39.0",
                            "count": 3
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "19.0",
                            "id": "19.0",
                            "count": 2
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "28.0",
                            "id": "28.0",
                            "count": 2
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "38.4",
                            "id": "38.4",
                            "count": 2
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "42.0",
                            "id": "42.0",
                            "count": 2
                        },
                        {
                            "__typename": "StatsBucket",
                            "title": "",
                            "min": 0,
                            "max": 92
                        }
                    ]
                },
                {
                    "title": "Color",
                    "attribute": "color",
                    "buckets": [
                        {
                            "__typename": "ScalarBucket",
                            "title": "Blue",
                            "id": "Blue",
                            "count": 22
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Black",
                            "id": "Black",
                            "count": 17
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Red",
                            "id": "Red",
                            "count": 13
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Green",
                            "id": "Green",
                            "count": 12
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Purple",
                            "id": "Purple",
                            "count": 11
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Gray",
                            "id": "Gray",
                            "count": 9
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Orange",
                            "id": "Orange",
                            "count": 8
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "White",
                            "id": "White",
                            "count": 6
                        }
                    ]
                },
                {
                    "title": "Categories",
                    "attribute": "categories",
                    "buckets": [
                        {
                            "__typename": "ScalarBucket",
                            "title": "collections",
                            "id": "collections",
                            "count": 41
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "collections/yoga-new",
                            "id": "collections/yoga-new",
                            "count": 32
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "women",
                            "id": "women",
                            "count": 23
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "gear",
                            "id": "gear",
                            "count": 20
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "women/tops-women",
                            "id": "women/tops-women",
                            "count": 17
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "promotions",
                            "id": "promotions",
                            "count": 15
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "men",
                            "id": "men",
                            "count": 11
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "men/bottoms-men",
                            "id": "men/bottoms-men",
                            "count": 11
                        }
                    ]
                },
                {
                    "title": "Activity",
                    "attribute": "activity",
                    "buckets": [
                        {
                            "__typename": "ScalarBucket",
                            "title": "Gym",
                            "id": "Gym",
                            "count": 16
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Yoga",
                            "id": "Yoga",
                            "count": 15
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Athletic",
                            "id": "Athletic",
                            "count": 9
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Sports",
                            "id": "Sports",
                            "count": 6
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Recreation",
                            "id": "Recreation",
                            "count": 4
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "School",
                            "id": "School",
                            "count": 4
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Outdoor",
                            "id": "Outdoor",
                            "count": 3
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Travel",
                            "id": "Travel",
                            "count": 3
                        }
                    ]
                },
                {
                    "title": "Material",
                    "attribute": "material",
                    "buckets": [
                        {
                            "__typename": "ScalarBucket",
                            "title": "Polyester",
                            "id": "Polyester",
                            "count": 23
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Nylon",
                            "id": "Nylon",
                            "count": 15
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Spandex",
                            "id": "Spandex",
                            "count": 13
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "CoolTech鈩",
                            "id": "CoolTech鈩",
                            "count": 9
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Cotton",
                            "id": "Cotton",
                            "count": 8
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Organic Cotton",
                            "id": "Organic Cotton",
                            "count": 8
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Rayon",
                            "id": "Rayon",
                            "count": 7
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Wool",
                            "id": "Wool",
                            "count": 7
                        }
                    ]
                },
                {
                    "title": "Size",
                    "attribute": "size",
                    "buckets": [
                        {
                            "__typename": "ScalarBucket",
                            "title": "L",
                            "id": "L",
                            "count": 17
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "M",
                            "id": "M",
                            "count": 17
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "S",
                            "id": "S",
                            "count": 17
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "XL",
                            "id": "XL",
                            "count": 16
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "XS",
                            "id": "XS",
                            "count": 16
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "32",
                            "id": "32",
                            "count": 14
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "33",
                            "id": "33",
                            "count": 11
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "34",
                            "id": "34",
                            "count": 11
                        }
                    ]
                }
            ],
            "suggestions": [
                "yoga",
                "yoga adventure",
                "yoga bag",
                "yoga brick",
                "yoga companion kit"
            ],
            "related_terms": null,
            "page_info": {
                "current_page": 1,
                "page_size": 1,
                "total_pages": 58
            }
        }
    }


categorySearch

Best used on search page to retrieve categories for filtering.

Parameter Type Required Default Example
phrase string yoga
category_size number 5 10
<summary> Response</summary>
{
    "extensions": {
        "request-id": "kl60cC8p4YV3aPdgDQQvadU9b6ozRcX4"
    },
    "data": {
        "categorySearch": {
            "categories": [
                {
                    "name": "collections",
                    "url": "collections.html"
                },
                {
                    "name": "collections/yoga-new",
                    "url": "collections/yoga-new.html"
                },
                {
                    "name": "women",
                    "url": "women.html"
                },
                {
                    "name": "women/tops-women",
                    "url": "women/tops-women.html"
                },
                {
                    "name": "promotions",
                    "url": "promotions.html"
                }
            ]
        }
    }
}

quickSearch

Best used in a search bar to return product and category matches, as well as search suggestions.

Parameter Type Required Default Example
phrase string yoga
category_size number 10 20
page_size number 10 20
current_page string 1 2
filter [] [] [{attribute: "color", eq: "red"}]
sort [] [] [{attribute: "price", direction: "ASC"}]
<summary> Response</summary>
{
    "extensions": {
        "request-id": "CWgQGQRHwZ7lZy9iyAepxahg8RuoC7RV"
    },
    "data": {
        "productSearch": {
            "total_count": 58,
            "items": [
                {
                    "product": {
                        "__typename": "SimpleProduct",
                        "uid": null,
                        "name": "Yoga Adventure",
                        "sku": "240-LV06",
                        "description": null,
                        "short_description": null,
                        "attribute_set_id": null,
                        "meta_title": null,
                        "meta_keyword": null,
                        "meta_description": null,
                        "image": {
                            "url": "//example.com/media/catalog/product/l/t/lt03.jpg",
                            "label": null,
                            "position": null,
                            "disabled": null
                        },
                        "small_image": null,
                        "thumbnail": null,
                        "new_from_date": null,
                        "new_to_date": null,
                        "created_at": null,
                        "updated_at": null,
                        "price_range": {
                            "minimum_price": {
                                "fixed_product_taxes": null,
                                "regular_price": {
                                    "value": null,
                                    "currency": "USD"
                                },
                                "final_price": {
                                    "value": 22,
                                    "currency": "USD"
                                },
                                "discount": null
                            },
                            "maximum_price": null
                        },
                        "gift_message_available": null,
                        "canonical_url": "//example.com/yoga-adventure.html",
                        "media_gallery": null,
                        "custom_attributes": null,
                        "weight": null
                    },
                    "highlights": [
                        {
                            "attribute": "name",
                            "value": "Yoga Adventure",
                            "matched_words": []
                        }
                    ]
                }
            ],
            "facets": [
                {
                    "title": "Price zz",
                    "attribute": "price",
                    "buckets": [
                        {
                            "__typename": "ScalarBucket",
                            "title": "32.0",
                            "id": "32.0",
                            "count": 5
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "29.0",
                            "id": "29.0",
                            "count": 4
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "45.0",
                            "id": "45.0",
                            "count": 4
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "0.0",
                            "id": "0.0",
                            "count": 3
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "24.0",
                            "id": "24.0",
                            "count": 3
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "39.0",
                            "id": "39.0",
                            "count": 3
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "19.0",
                            "id": "19.0",
                            "count": 2
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "28.0",
                            "id": "28.0",
                            "count": 2
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "38.4",
                            "id": "38.4",
                            "count": 2
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "42.0",
                            "id": "42.0",
                            "count": 2
                        },
                        {
                            "__typename": "StatsBucket",
                            "title": "",
                            "min": 0,
                            "max": 92
                        }
                    ]
                },
                {
                    "title": "Color",
                    "attribute": "color",
                    "buckets": [
                        {
                            "__typename": "ScalarBucket",
                            "title": "Blue",
                            "id": "Blue",
                            "count": 22
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Black",
                            "id": "Black",
                            "count": 17
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Red",
                            "id": "Red",
                            "count": 13
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Green",
                            "id": "Green",
                            "count": 12
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Purple",
                            "id": "Purple",
                            "count": 11
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Gray",
                            "id": "Gray",
                            "count": 9
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Orange",
                            "id": "Orange",
                            "count": 8
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "White",
                            "id": "White",
                            "count": 6
                        }
                    ]
                },
                {
                    "title": "Categories",
                    "attribute": "categories",
                    "buckets": [
                        {
                            "__typename": "ScalarBucket",
                            "title": "collections",
                            "id": "collections",
                            "count": 41
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "collections/yoga-new",
                            "id": "collections/yoga-new",
                            "count": 32
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "women",
                            "id": "women",
                            "count": 23
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "gear",
                            "id": "gear",
                            "count": 20
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "women/tops-women",
                            "id": "women/tops-women",
                            "count": 17
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "promotions",
                            "id": "promotions",
                            "count": 15
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "men",
                            "id": "men",
                            "count": 11
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "men/bottoms-men",
                            "id": "men/bottoms-men",
                            "count": 11
                        }
                    ]
                },
                {
                    "title": "Activity",
                    "attribute": "activity",
                    "buckets": [
                        {
                            "__typename": "ScalarBucket",
                            "title": "Gym",
                            "id": "Gym",
                            "count": 16
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Yoga",
                            "id": "Yoga",
                            "count": 15
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Athletic",
                            "id": "Athletic",
                            "count": 9
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Sports",
                            "id": "Sports",
                            "count": 6
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Recreation",
                            "id": "Recreation",
                            "count": 4
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "School",
                            "id": "School",
                            "count": 4
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Outdoor",
                            "id": "Outdoor",
                            "count": 3
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Travel",
                            "id": "Travel",
                            "count": 3
                        }
                    ]
                },
                {
                    "title": "Material",
                    "attribute": "material",
                    "buckets": [
                        {
                            "__typename": "ScalarBucket",
                            "title": "Polyester",
                            "id": "Polyester",
                            "count": 23
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Nylon",
                            "id": "Nylon",
                            "count": 15
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Spandex",
                            "id": "Spandex",
                            "count": 13
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "CoolTech鈩",
                            "id": "CoolTech鈩",
                            "count": 9
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Cotton",
                            "id": "Cotton",
                            "count": 8
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Organic Cotton",
                            "id": "Organic Cotton",
                            "count": 8
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Rayon",
                            "id": "Rayon",
                            "count": 7
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "Wool",
                            "id": "Wool",
                            "count": 7
                        }
                    ]
                },
                {
                    "title": "Size",
                    "attribute": "size",
                    "buckets": [
                        {
                            "__typename": "ScalarBucket",
                            "title": "L",
                            "id": "L",
                            "count": 17
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "M",
                            "id": "M",
                            "count": 17
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "S",
                            "id": "S",
                            "count": 17
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "XL",
                            "id": "XL",
                            "count": 16
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "XS",
                            "id": "XS",
                            "count": 16
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "32",
                            "id": "32",
                            "count": 14
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "33",
                            "id": "33",
                            "count": 11
                        },
                        {
                            "__typename": "ScalarBucket",
                            "title": "34",
                            "id": "34",
                            "count": 11
                        }
                    ]
                }
            ],
            "suggestions": [
                "yoga",
                "yoga adventure",
                "yoga bag",
                "yoga brick",
                "yoga companion kit"
            ],
            "related_terms": null,
            "page_info": {
                "current_page": 1,
                "page_size": 1,
                "total_pages": 58
            }
        },
        "categorySearch": {
            "categories": [
                {
                    "name": "collections",
                    "url": "collections.html"
                },
                {
                    "name": "collections/yoga-new",
                    "url": "collections/yoga-new.html"
                },
                {
                    "name": "women",
                    "url": "women.html"
                },
                {
                    "name": "women/tops-women",
                    "url": "women/tops-women.html"
                },
                {
                    "name": "promotions",
                    "url": "promotions.html"
                }
            ]
        }
    }
}

Current Tags

  • 0.7.1                                ...           latest (a day ago)

16 Versions

  • 0.7.1                                ...           a day ago
  • 0.7.0                                ...           3 days ago
  • 0.6.0                                ...           a month ago
  • 0.5.1                                ...           2 months ago
  • 0.5.0                                ...           2 months ago
  • 0.4.0                                ...           2 months ago
  • 0.3.0                                ...           2 months ago
  • 0.2.1                                ...           2 months ago
  • 0.2.0                                ...           3 months ago
  • 0.1.1                                ...           3 months ago
  • 0.1.0                                ...           3 months ago
  • 0.0.5                                ...           4 months ago
  • 0.0.4                                ...           5 months ago
  • 0.0.3                                ...           5 months ago
  • 0.0.2                                ...           5 months ago
  • 0.0.1                                ...           5 months ago
Downloads
Today 0
This Week 15
This Month 15
Last Day 9
Last Week 0
Last Month 17
Dependencies (1)
Dev Dependencies (17)
Dependents (0)
None

Copyright 2014 - 2016 漏 taobao.org |