@6thstreetdotcom/algolia-sdk 中文文档教程

发布于 3年前 浏览 25 更新于 3年前

Algolia SDK

用于移动应用程序和网络的 Algolia 包装器。

Methods

Init

使用 SDK 时应调用的第一个函数。 此函数将根据 Algolia 键设置 Algolia 对象。

  • appID - Algolia application ID
  • searchKey - Algolia search Key
  • options - This is an optional object, with the following keys:
    • customIndices This is a list of custom indices grouped by locale, that will override the default values from config

例如:

{
  customIndices: {
    "en-ae": {
      default: 'uat_english_products',
      latest: 'uat_english_products_created_at_desc',
      price_low: 'uat_english_products_price_default_asc',
      price_high: 'uat_english_products_price_default_desc',
      discount: 'uat_english_products_discount_desc'
    }
  }
}
import AlgoliaSDK from '@6thstreetdotcom/algolia-sdk';

AlgoliaSDK.init(appID, searchKey);

SetIndex

此函数将根据语言环境和环境设置设置 Algolia 索引。

setIndex(locale, env);
  • locale - environment used for getting the right indexes
  • default: 'en-ae'
  • env - environment used for getting the right indexes
  • default: 'production'
  • values: ENUM = ('staging', 'production')
import AlgoliaSDK from 'Algolia-sdk';

AlgoliaSDK.setIndex('en-ae', 'production');

使用任何可用的 facet 进行搜索。 每个构面的多个值使用逗号 , 分隔值。

要使用搜索查询进行搜索,请使用 q 参数,如下所述。

AlgoliaSDK.search({
  q: 'Adidas',
  hitsPerPage: 4,
  'categories.level1': 'Women /// Shoes',
  gender: 'Women'
});

响应:search-data.json

GetBrands

按查询字符串搜索

getBrands(gender);
  • gender - String
  • default: ''
  • if left empty -> response will contain all brands
// to get all brands
AlgoliaSDK.getBrands();

// to get specific gender brand
AlgoliaSDK.getBrands('Women');

响应: brands-data.json

GetPDP

返回给定 SKU 的产品详细信息。

getPDP(params);
  • params - Object
  • sku - String: product's sku
    • default: ''
  • highlights - Array: list of attributes to highlight
    • if not set, all searchable attributes are highlighted
    • response contains highlighted_attributes attribute which contains the list of highlighted attributes
AlgoliaSDK.getPDP({
  sku: 'VAMTFRYIH-BLACK',
  highlights: ['brand_name', 'color', 'gender']
});

响应:pdp-data.json

GetPLP

返回 PLP 屏幕的产品。

getPLP(URL);
  • URL - String: URL for the Product list

URL Params & Structure:

  • params in URL should have the following form:

/...?key=value&key=value1,value2,value3

  • custom params:
  • all the Algolia facet filters (q - query param, brandname - Brands param, categories.levelX - categories param, categorieswithout_path etc.)
  • example 1: brand_name=Adidas,Aldo,Nike
  • example 2: categories.level0=Women
  • example 3: categories.level1=Women /// Shoes
  • example 4: categories.level2=Women /// Shoes /// Sandals
  • example 5: categories.level1=Men /// Shirts,Women /// Shoes
  • special params:
  • gender - mandatory = ENUM('Women', 'Men', 'Kids')
  • locale - mandatory = ENUM('en-ae', 'ar-ae', 'en-sa', 'ar-sa', 'en-kw', 'ar-kw', 'en-qa', 'ar-qa', 'en-om', 'ar-om', 'en-bh', 'ar-bh')
  • sort = String: ENUM('recommended', pricelow', 'pricehigh', 'discount')
    • 'recommended' - default sorting
    • 'price_low'' - sort products by price ASC
    • 'price_high'' - sort products by price DESC
    • 'discount'' - sort products by highest discount
  • price.[currency].default - filter products by price
    • example 1: price.AED.default=gte50,lte700 - filter products with the price in interval >= 50 AED and <= 700 AED
    • example 2: price.SAR.default=lt100 - filter products with the price less than 100 SAR
  • discount - filter products by discount
    • example 1: discount=gt20,lte70 - filter products with the discount in range > 20% and <= 70%
    • example 2: discount=gte40 - filter products with the discount >= 40%

注意:对于 pricediscount 键过滤器,而不是 (> ;, <, >=, <=) 您应该使用以下符号:

  • 'lt' : <
  • 'lte' : <=
  • 'gt' : >
  • 'gte' : >=
  • 'eq' : =

我们不能使用运算符,因为会干扰 URL

AlgoliaSDK.getPLP(
  '/women/outlet.html?q=Women%20Outlet&page=0&brand_name=Adidas,Aldo&categories.level0=Women&categories.level1=Women /// Shoes&discount=gt20,lte900&price.AED.default=gte50,lte1500&visibility_catalog=1&gender=Women&locale=en-ae'
);

响应中的查询参数:plp-data.json

GetPopularBrands

返回流行品牌。

getPopularBrands(limit);
  • limit - Int: results limit
  • default: 10
AlgoliaSDK.getPopularBrands(5);

回复

{
  "data": ["Adidas", "Aldo", "Adidas Originals", "Charles & Keith", "Nike"]
}

Algolia SDK

Algolia wrapper to be used on both mobile-app and web.

Methods

Init

The first function that should be called when using the SDK. This function will set the Algolia object based on Algolia keys.

  • appID - Algolia application ID
  • searchKey - Algolia search Key
  • options - This is an optional object, with the following keys:
    • customIndices This is a list of custom indices grouped by locale, that will override the default values from config

E.g:

{
  customIndices: {
    "en-ae": {
      default: 'uat_english_products',
      latest: 'uat_english_products_created_at_desc',
      price_low: 'uat_english_products_price_default_asc',
      price_high: 'uat_english_products_price_default_desc',
      discount: 'uat_english_products_discount_desc'
    }
  }
}
import AlgoliaSDK from '@6thstreetdotcom/algolia-sdk';

AlgoliaSDK.init(appID, searchKey);

SetIndex

This function will set the Algolia index based on locale and env settings.

setIndex(locale, env);
  • locale - environment used for getting the right indexes
  • default: 'en-ae'
  • env - environment used for getting the right indexes
  • default: 'production'
  • values: ENUM = ('staging', 'production')
import AlgoliaSDK from 'Algolia-sdk';

AlgoliaSDK.setIndex('en-ae', 'production');

Search using any available facet. Use comma , separated values for multiple values per facet.

To search using a search query, use the q param, as described below.

AlgoliaSDK.search({
  q: 'Adidas',
  hitsPerPage: 4,
  'categories.level1': 'Women /// Shoes',
  gender: 'Women'
});

Response: search-data.json

GetBrands

Search by a query string

getBrands(gender);
  • gender - String
  • default: ''
  • if left empty -> response will contain all brands
// to get all brands
AlgoliaSDK.getBrands();

// to get specific gender brand
AlgoliaSDK.getBrands('Women');

Response: brands-data.json

GetPDP

Returns a product's details for the given SKU.

getPDP(params);
  • params - Object
  • sku - String: product's sku
    • default: ''
  • highlights - Array: list of attributes to highlight
    • if not set, all searchable attributes are highlighted
    • response contains highlighted_attributes attribute which contains the list of highlighted attributes
AlgoliaSDK.getPDP({
  sku: 'VAMTFRYIH-BLACK',
  highlights: ['brand_name', 'color', 'gender']
});

Response: pdp-data.json

GetPLP

Returns products for a PLP Screen.

getPLP(URL);
  • URL - String: URL for the Product list

URL Params & Structure:

  • params in URL should have the following form:

/...?key=value&key=value1,value2,value3

  • custom params:
  • all the Algolia facet filters (q - query param, brandname - Brands param, categories.levelX - categories param, categorieswithout_path etc.)
  • example 1: brand_name=Adidas,Aldo,Nike
  • example 2: categories.level0=Women
  • example 3: categories.level1=Women /// Shoes
  • example 4: categories.level2=Women /// Shoes /// Sandals
  • example 5: categories.level1=Men /// Shirts,Women /// Shoes
  • special params:
  • gender - mandatory = ENUM('Women', 'Men', 'Kids')
  • locale - mandatory = ENUM('en-ae', 'ar-ae', 'en-sa', 'ar-sa', 'en-kw', 'ar-kw', 'en-qa', 'ar-qa', 'en-om', 'ar-om', 'en-bh', 'ar-bh')
  • sort = String: ENUM('recommended', pricelow', 'pricehigh', 'discount')
    • 'recommended' - default sorting
    • 'price_low'' - sort products by price ASC
    • 'price_high'' - sort products by price DESC
    • 'discount'' - sort products by highest discount
  • price.[currency].default - filter products by price
    • example 1: price.AED.default=gte50,lte700 - filter products with the price in interval >= 50 AED and <= 700 AED
    • example 2: price.SAR.default=lt100 - filter products with the price less than 100 SAR
  • discount - filter products by discount
    • example 1: discount=gt20,lte70 - filter products with the discount in range > 20% and <= 70%
    • example 2: discount=gte40 - filter products with the discount >= 40%

Notes: for price and discount key filters, instead of (>, <, >=, <=) symbols you should use the following:

  • 'lt' : <
  • 'lte' : <=
  • 'gt' : >
  • 'gte' : >=
  • 'eq' : =

We cannot use operators because will interfere with the query params in a URL

AlgoliaSDK.getPLP(
  '/women/outlet.html?q=Women%20Outlet&page=0&brand_name=Adidas,Aldo&categories.level0=Women&categories.level1=Women /// Shoes&discount=gt20,lte900&price.AED.default=gte50,lte1500&visibility_catalog=1&gender=Women&locale=en-ae'
);

Response: plp-data.json

GetPopularBrands

Returns popular brands.

getPopularBrands(limit);
  • limit - Int: results limit
  • default: 10
AlgoliaSDK.getPopularBrands(5);

Response

{
  "data": ["Adidas", "Aldo", "Adidas Originals", "Charles & Keith", "Nike"]
}
更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文