从值字符串创建refinementList

Str*_*rnm 1 algolia

我的数据结构如下:

{
  "id": 12345,
  "name": "Brother PJ-663 Direct A4 Thermal Mobile Printer",
  "type": "Thermal printer",
  "features": "USB, Mobile Print"
}, 
Run Code Online (Sandbox Code Playgroud)

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

我应该如何格式化数据以创建单个instantsearch.widgets.refinementList小部件?

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

小智 6

最好的方法是,在索引和索引之前重新格式化(拆分)数据featurestype作为数组:

{
  "id": 12345,
  "name": "Brother PJ-663 Direct A4 Thermal Mobile Printer",
  "type": [
    "Thermal printer"
  ],
  "features": [
    "USB", 
    "Mobile Print"
  ]
}
Run Code Online (Sandbox Code Playgroud)

然后将这些属性设置为Algolia设置中的构面属性,您就可以了.您可以使用instantsearch.jsrefinementList小部件根据这些属性过滤结果.

我不会在_tags这里,因为你有2个不同的属性要用于过滤,并且_tags不允许你以简单的方式做到这一点.