Skip to content

Commit d1421c0

Browse files
Erik MarrErik Marr
authored andcommitted
Adding logic behind suggestions
1 parent b311bee commit d1421c0

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/pages/graphql/schema/live-search/queries/product-search.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,25 @@ The `items` object can also optionally return highlighted text that shows the ma
555555
The query response can also contain the following top-level fields and objects:
556556

557557
- `page_info` - An object that lists the `page_size` and `current_page` input arguments and the total number of pages available.
558-
- `suggestions` - An array of strings that include the names of products and categories that exist in the catalog that are similar to the search query.
558+
- `suggestions` - An array of strings that include the names of products and categories that exist in the catalog that are similar to the search query. See **Logic used for `suggestions`** to learn more.
559559
- `total_count` - The number of products returned.
560560

561+
**Logic used for `suggestions`**
562+
563+
- Data from name and category path fields are used.
564+
- Name: `Supernova Sport Pant` will be stored in three phrases:
565+
- `Supernova Sport Pant`
566+
- `Sport Pant`
567+
- `Pant`
568+
- Category path: tokenized by /, so "products/electronics/mobiles-and-accessories" will be stored as:
569+
- `products`
570+
- `electronics`
571+
- `mobiles-and-accessories`
572+
573+
When a search is made, the "suggestion" field is searched using a "prefix" based search and the matching phrase is returned.
574+
575+
**Example** - If "sport" is searched, then "sport pant" will be one suggestion.
576+
561577
## Endpoints
562578

563579
import StorefrontAPIEndpoints from '/src/_includes/graphql/endpoints.md'
@@ -906,9 +922,25 @@ Field | Data Type | Description
906922
`items` | [[ProductSearchItem]](#productsearchitem-data-type) | An array of products returned by the query
907923
`page_info` | [SearchResultPageInfo](#searchresultpageinfo-data-type) | Contains information for rendering pages of search results
908924
`related_terms` | [String] | Reserved for future use
909-
`suggestions` | [String] | An array of product URL keys that are similar to the search query. A maximum of five items are returned
925+
`suggestions` | [String] | An array of product URL keys that are similar to the search query. A maximum of five items are returned. See **Logic used for `suggestions`** to learn more.
910926
`total_count` | Int | The total number of items returned
911927

928+
**Logic used for `suggestions`**
929+
930+
- Data from name and category path fields are used.
931+
- Name: `Supernova Sport Pant` will be stored in three phrases:
932+
- `Supernova Sport Pant`
933+
- `Sport Pant`
934+
- `Pant`
935+
- Category path: tokenized by /, so "products/electronics/mobiles-and-accessories" will be stored as:
936+
- `products`
937+
- `electronics`
938+
- `mobiles-and-accessories`
939+
940+
When a search is made, the "suggestion" field is searched using a "prefix" based search and the matching phrase is returned.
941+
942+
**Example** - If "sport" is searched, then "sport pant" will be one suggestion.
943+
912944
#### Aggregation data type
913945

914946
Field | Data Type | Description

0 commit comments

Comments
 (0)