预测搜索
你可以通过搜索商品 Ajax API,在前端界面上对店铺内存在的内容进行搜索
请求信息
GET
https://{handle}.myshopline.com/search/suggest.json
请求参数:
参数名 | 参数类型 | 是否数组 | 是否必填 | 示例 | 描述 |
---|---|---|---|---|---|
q | String | 否 | 是 | 衬衫 | 搜索内容 |
field | String | 否 | 是 | title,product_type | 需要命中的搜索字段和操作 - title - product_type - tag - variants.sku - brand |
resource_type | String | 否 | 是 | product | 指定请求的结果类型: - product - collection - page - article - query |
available_type | String | 否 | 是 | show | 用于指定返回的产品类型,支持的参数有: show、hide |
limit | String | 否 | 否 | 10 | 【1,30】的整数,不传或非法的设置为30 |
limit_scope | String | 否 | 否 | each | each : 表示返回每个 resource_type 的前 limit 行记录all : 表示按照以下优先级返回的前 limit 行记录- query - product - collections - article - page |
响应信息
响应body:
一级参数名 | 二级参数名 | 三级参数名 | 参数类型 | 是否数组 | 示例 | 描述 |
---|---|---|---|---|---|---|
message | String | 否 | ||||
description | String | 否 | ||||
products | Object | 产品数组 | ||||
id | String | 否 | 产品ID | |||
title | String | 否 | 产品标题 | |||
handle | String | 否 | 产品的handle | |||
url | String | 否 | 产品的相对路径,格式为: /products/handle | |||
description | String | 否 | 产品的描述 | |||
brand | String | 否 | 品牌名称 | |||
tags | List<String> | 否 | 产品标签数组 | |||
images | List<String> | 否 | 产品主图数组 | |||
featured_image | String | 否 | 产品的特色图,等同于images[0] | |||
medias | Object | |||||
resource | String | 否 | 以 URL 形式表示的资源位置 | |||
cover | String | 否 | 以 URL 形式表示的封面图位置 | |||
type | String | 否 | 媒体资源类型 | |||
alt | String | 否 | 具有图像特征或内容的单词或短语 | |||
sold_out | Boolean | 否 | 产品是否售罄 | |||
price | Long | 否 | 产品售价,等同于price_min | |||
price_min | Long | 否 | 产品的最小售价 | |||
price_max | Long | 否 | 产品的最大售价 | |||
price_varies | Boolean | 否 | 表明产品变体的最小售价和最大售价是否一致 | |||
compare_at_price | Long | 否 | 变体的原价,等同于 compareAtPriceMin | |||
compare_at_price_min | Long | 否 | 变体的最小原价 | |||
compare_at_price_max | Long | 否 | 变体的最大原价 | |||
compare_at_price_varies | Boolean | 否 | 表明产品变体的最小原价和最大原价是否一致 | |||
created_at | Date | 否 | 产品创建时间 | |||
published_at | Date | 否 | 产品发布时间 | |||
options | Object | 选项数组 | ||||
name | String | 否 | 选项名称 | |||
values | List<String> | 否 | 选项值数组 | |||
values_images | Map<String,String> | 否 | 选项值和选项值图片的映射字典 | |||
variants | Object | 变体数组 | ||||
id | String | 否 | 变体ID | |||
barcode | String | 否 | 条形码 | |||
title | String | 否 | 变体标题 | |||
option1 | String | 否 | 变体的第1个选项值 | |||
option2 | String | 否 | 变体的第2个选项值 | |||
option3 | String | 否 | 变体的第3个选项值 | |||
option4 | String | 否 | 变体的第4个选项值 | |||
option5 | String | 否 | 变体的第5个选项值 | |||
sku | String | 否 | 变体的SKU码 | |||
featured_image | String | 否 | 变体图片 | |||
name | String | 否 | 变体名称,格式为:产品标题 · 变体标题 | |||
public_title | String | 否 | 公共标题,等同于 variant.title | |||
options | List<String> | 否 | 变体选项数组 | |||
weight | BigDecimal | 否 | 重量 | |||
weight_unit | String | 否 | 重量单位 | |||
price | Long | 否 | 变体售价,单位为:最小货币精度 | |||
compare_at_price | Long | 否 | 变体原价,单位为:最小货币精度 | |||
inventory_policy | String | 否 | 是否允许超卖,continue:允许,deny:不允许 | |||
inventory_tracker | Boolean | 否 | 是否追踪库存,默认为false | |||
collections | List<Object> | 否 | 分类数组 | |||
id | String | 是 | 分类ID | |||
handle | String | 是 | 分类的handle | |||
title | String | 是 | 分类标题 | |||
url | String | 是 | 分类的相对路径,格式为:/collections/handle | |||
published_at | String | 是 | 发布到在线商店渠道的时间 | |||
body | String | 否 | 分类的描述 | |||
featured_image | 分类的特色图 | |||||
alt | String | 否 | 具有图像特征或内容的单词或短语 | |||
height | Integer | 否 | 图片高度 | |||
width | Integer | 否 | 图片宽度 | |||
url | String | 是 | 以 URL 形式表示的图像位置 | |||
queries | List<Object> | 否 | 推荐的词条数组 | |||
text | String | 是 | 推荐的词条 | |||
url | String | 是 | 词条对应的搜索结果页链接 | |||
pages | List<Object> | 否 | 自定义页面数组 | |||
id | String | 是 | 页面ID | |||
handle | String | 是 | 页面的handle | |||
title | String | 是 | 页面标题 | |||
url | String | 是 | 页面的相对路径,格式为:/pages/handle | |||
author | String | 否 | 页面作者 | |||
body | String | 否 | 页面内容 | |||
published_at | String | 否 | 发布到在线商店渠道的时间 | |||
articles | List<Object> | 否 | 博客数组 | |||
id | String | 是 | 博客ID | |||
handle | String | 是 | 博客的handle | |||
title | String | 否 | 博客的标题 | |||
url | String | 是 | 博客的相对路径,格式为:/blogs/handle | |||
summary_html | String | 否 | 博客的摘要 | |||
published_at | String | 否 | 发布到在线商店渠道的时间 | |||
featured_image | Object | 否 | 博客的特色图 | |||
alt | String | 否 | 具有图像特征或内容的单词或短语 | |||
height | Integer | 否 | 图片高度 | |||
width | Integer | 否 | 图片宽度 | |||
url | String | 是 | 以 URL 形式表示的图像位置 |
请求、响应示例
场景:搜索商品名称包含dress的商品
请求
fetch("https://{handle}.myshopline.com/search/suggest.json?q=dress&field=title&resource_type=product&available_type=show&limit=1")
响应
"queries": [
{
"text": "100",
"url": "/search?keyword=100"
}
],
"products": [
{
"id": "16060168376183564632570904",
"title": "评分100.99--商品002",
"handle": "评分100.99--商品002",
"description": null,
"brand": null,
"vendor": null,
"tags": null,
"images": null,
"price": 11100,
"options": [
{
"name": "Color",
"values": [
"red",
"blue"
],
"values_images": {
"red": null,
"blue": null
}
}
],
"variants": [
{
"id": "18060168376188765569600904",
"barcode": null,
"title": "red",
"option1": "red",
"option2": null,
"option3": null,
"option4": null,
"option5": null,
"sku": null,
"name": "评分100.99--商品002 · red",
"options": [
"red"
],
"weight": null,
"price": 11100,
"available": true,
"featured_image": null,
"public_title": "red",
"weight_unit": null,
"compare_at_price": 22200,
"inventory_policy": "deny",
"inventory_tracker": true,
"requires_selling_plan": false,
"selling_plan_alloactions": [
],
"featured_image_v2": null
},
{
"id": "18060168376188765569640904",
"barcode": null,
"title": "blue",
"option1": "blue",
"option2": null,
"option3": null,
"option4": null,
"option5": null,
"sku": "",
"name": "评分100.99--商品002 · blue",
"options": [
"blue"
],
"weight": null,
"price": 11100,
"available": true,
"featured_image": null,
"public_title": "blue",
"weight_unit": null,
"compare_at_price": 22200,
"inventory_policy": "deny",
"inventory_tracker": true,
"requires_selling_plan": false,
"selling_plan_alloactions": [
],
"featured_image_v2": null
}
],
"visible": true,
"url": "/products/评分100.99--商品002",
"featured_image": null,
"medias": [
],
"sold_out": false,
"price_min": 11100,
"price_max": 11100,
"price_varies": true,
"compare_at_price": 22200,
"compare_at_price_min": 22200,
"compare_at_price_max": 22200,
"compare_at_price_varies": true,
"created_at": "2023-07-10T11:26:18.087+08:00",
"published_at": "2023-07-10T11:26:18.148+08:00",
"requires_selling_plan": false,
"selling_plan_groups": [
],
"featured_image_v2": null,
"custom_category_name": ""
}
],
"collections": [
{
"body": "更新智能分类一并修改分类描述信息002",
"handle": "新增智能分类条件为标题等于--001--1061392384",
"id": "12260161333887589518440904",
"title": "更新分类修改为小数大于100-商品关联小数99-100-101-只有101在范围内-007",
"url": "/collections/新增智能分类条件为标题等于--001--1061392384",
"featured_image": {
"alt": "cover",
"width": 1154,
"height": 642,
"url": "https://d2n979dmt31clo.cloudfront.net/image/store/4200012610/1625907878650/d7614fad260b448a810ce7de0a524997.png?w=1154&h=642",
"aspect_ratio": null
},
"published_at": "2023-07-09T23:46:42.691+08:00"
}
],
"pages": [
{
"author": "4200012610",
"handle": "111自定义页",
"id": "5980852662048395303",
"title": "111自定义页",
"url": "/pages/111自定义页",
"published_at": "2023-06-15T15:38:00.000+08:00"
}
],
"articles": [
{
"author": "新加坡店铺",
"handle": "news/123",
"id": "648ab1a0f301e236c33c9d69",
"title": "123",
"url": "/blogs/news/123",
"featured_image": null,
"published_at": "2023-06-15T14:37:00.000+08:00",
"summary_html": "123"
}
]
}
请求信息
通过搜索商品 Ajax API,取得指定查询条件的预测搜索结果的 HTML
GET
https://{handle}.myshopline.com/search/suggest
请求参数:
/search/suggest 接口支持与 /search/suggest.json 接口相同的请求参数,此外还支持以下参数
参数名 | 参数类型 | 是否数组 | 是否必填 | 示例 | 描述 |
---|---|---|---|---|---|
section_id | String | 否 | 是 | 使用预测搜索结果渲染指定的 section 的 id |
请求、响应示例
场景:搜索商品名称包含 dress 的商品,并返回之相关的 predictive-search
section
请求
fetch("https://{handle}.myshopline.com/search/suggest?q=dress&field=title&resource_type=product&limit=5&available_type=show§ion_id=predictive-search")
响应
<div id="shopline-section-predictive-search" class="shopline-section"><link rel="dns-prefetch" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.googleapis.com" crossorigin>
<link rel="dns-prefetch" href="https://fonts.gstatic.com">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat:500|Poppins:300&display=swap" media="all"><div class="predictive-search-results">
<h2 class="predictive-search__head body5">
Products
<span class="predictive-search__rusults">
1 Results
</span>
<span class="predictive-search__spinner">
<svg class="icon icon-loading" width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M18.3337 9.99984C18.3337 14.6022 14.6027 18.3332 10.0003 18.3332C5.39795 18.3332 1.66699 14.6022 1.66699 9.99984C1.66699 5.39746 5.39795 1.6665 10.0003 1.6665" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/>
</svg>
</span>
</h2>
<ul class="predictive-search__results-list list-unstyled" data-predictive-search>
<li class="predictive-search__list-item">
<a class="predictive-search__item link" href="/products/dress">
<img src="https://d2n979dmt31clo.cloudfront.net/image/store/1655365532096/-.jpeg?w=275&h=183" alt="dress" width="275" height="183" fetchpriority="high" decoding="async" data-scale="hover-scale" loading="eager" class="predictive-search__item-image">
<div class="predictive-search__item-content">
<p class="predictive-search__item-head body3">dress</p>
<p class="predictive-search__item-price">
<span class="body3">$0.00</span>
<span class="body5 line-through">$0.00</span>
</p>
</div>
</a>
</li>
</ul>
<button class="predictive-search__term button body3">
Search for “__QUERY_KEY__”
</button>
</div></div>
这篇文章对你有帮助吗?