预测搜索

你可以通过搜索商品 Ajax API,在前端界面上对店铺内存在的内容进行搜索

请求信息

GET https://{handle}.myshopline.com/search/suggest.json


请求参数:

参数名参数类型是否数组是否必填示例描述
qString衬衫搜索内容
fieldStringtitle,product_type需要命中的搜索字段和操作
- title
- product_type
- tag
- variants.sku
- brand
resource_typeStringproduct指定请求的结果类型:
- product
- collection
- page
- article
- query
available_typeStringshow用于指定返回的产品类型,支持的参数有: show、hide
limitString10【1,30】的整数,不传或非法的设置为30
limit_scopeStringeacheach: 表示返回每个 resource_type 的前 limit 行记录
all: 表示按照以下优先级返回的前 limit 行记录
- query
- product
- collections
- article
- page

响应信息

响应body:

一级参数名二级参数名三级参数名参数类型是否数组示例描述
messageString
descriptionString
productsObject产品数组
idString产品ID
titleString产品标题
handleString产品的handle
urlString产品的相对路径,格式为: /products/handle
descriptionString产品的描述
brandString品牌名称
tagsList<String>产品标签数组
imagesList<String>产品主图数组
featured_imageString产品的特色图,等同于images[0]
mediasObject
resourceString以 URL 形式表示的资源位置
coverString以 URL 形式表示的封面图位置
typeString媒体资源类型
altString具有图像特征或内容的单词或短语
sold_outBoolean产品是否售罄
priceLong产品售价,等同于price_min
price_minLong产品的最小售价
price_maxLong产品的最大售价
price_variesBoolean表明产品变体的最小售价和最大售价是否一致
compare_at_priceLong变体的原价,等同于 compareAtPriceMin
compare_at_price_minLong变体的最小原价
compare_at_price_maxLong变体的最大原价
compare_at_price_variesBoolean表明产品变体的最小原价和最大原价是否一致
created_atDate产品创建时间
published_atDate产品发布时间
optionsObject选项数组
nameString选项名称
valuesList<String>选项值数组
values_imagesMap<String,String>选项值和选项值图片的映射字典
variantsObject变体数组
idString变体ID
barcodeString条形码
titleString变体标题
option1String变体的第1个选项值
option2String变体的第2个选项值
option3String变体的第3个选项值
option4String变体的第4个选项值
option5String变体的第5个选项值
skuString变体的SKU码
featured_imageString变体图片
nameString变体名称,格式为:产品标题 · 变体标题
public_titleString公共标题,等同于 variant.title
optionsList<String>变体选项数组
weightBigDecimal重量
weight_unitString重量单位
priceLong变体售价,单位为:最小货币精度
compare_at_priceLong变体原价,单位为:最小货币精度
inventory_policyString是否允许超卖,continue:允许,deny:不允许
inventory_trackerBoolean是否追踪库存,默认为false
collectionsList<Object>分类数组
idString分类ID
handleString分类的handle
titleString分类标题
urlString分类的相对路径,格式为:/collections/handle
published_atString发布到在线商店渠道的时间
bodyString分类的描述
featured_image分类的特色图
altString具有图像特征或内容的单词或短语
heightInteger图片高度
widthInteger图片宽度
urlString以 URL 形式表示的图像位置
queriesList<Object>推荐的词条数组
textString推荐的词条
urlString词条对应的搜索结果页链接
pagesList<Object>自定义页面数组
idString页面ID
handleString页面的handle
titleString页面标题
urlString页面的相对路径,格式为:/pages/handle
authorString页面作者
bodyString页面内容
published_atString发布到在线商店渠道的时间
articlesList<Object>博客数组
idString博客ID
handleString博客的handle
titleString博客的标题
urlString博客的相对路径,格式为:/blogs/handle
summary_htmlString博客的摘要
published_atString发布到在线商店渠道的时间
featured_imageObject博客的特色图
altString具有图像特征或内容的单词或短语
heightInteger图片高度
widthInteger图片宽度
urlString以 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_idString使用预测搜索结果渲染指定的 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&section_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>
这篇文章对你有帮助吗?