从值字符串创建refinementList

时间:2016-11-16 13:26:54

标签: algolia

我的数据结构如下:

{
  "id": 12345,
  "name": "Brother PJ-663 Direct A4 Thermal Mobile Printer",
  "type": "Thermal printer",
  "features": "USB, Mobile Print"
}, 

我试图根据功能字符串(爆炸)中的值创建一个refinementList小部件,就像我对类型一样,但是我不确定这是否是正确的方法甚至是可能的。

如何格式化数据以便能够创建单个instantsearch.widgets.refinementList小部件?

此外,我使用_tags代替并将每个功能添加为标记,是否可以实现此目标?

1 个答案:

答案 0 :(得分:5)

最好的方法是在编制索引之前重新格式化(按,分割)数据,并将featurestype索引为数组:

{
  "id": 12345,
  "name": "Brother PJ-663 Direct A4 Thermal Mobile Printer",
  "type": [
    "Thermal printer"
  ],
  "features": [
    "USB", 
    "Mobile Print"
  ]
}

然后将这些属性设置为Algolia设置中的分面属性,你就可以了。您可以使用instantsearch.js' refinementList widget根据这些属性过滤结果。

我不会在这里_tags,因为您有2个不同的属性要用于过滤,而_tags不允许您以简单的方式执行此操作。< / p>