1

I would like to be able to concatenate data. Here is an example :

[ { "type": "pen", "color": "blue", }, { "type": "glass", "color": "red", }, { "type": "pen", "color": "green", }, { "type": "glass", "color": "violet", }, { "type": "pen", "color": "yellow", }, { "type": "glass", "color": "orange", } ]

Then, if I search for pen, I will get 3 results, one result for each colors. I would like only one result.

I tried to use a distinct but the algolia distinct is more like a filter, and not a concat. If I do a distinct on the attribute pen, i will get one result that might look like :

{ "type": "pen", "color": "blue", },

What I would like to obtain is :

{ "type": "pen", "color_list": ["blue", "green", "yellow"] },

I cannot find anything like that in the algolia/instant-search doc, so I wonder how to do it. Is there a real tool that can do this, or at least a hacky solution that could do the trick ?

Thanks

4

1 回答 1

1

Algolia 不会为您连接,但通常所做的是让您的记录保存两个信息:

  • 这个特定记录代表什么颜色
  • 此产品类型还有哪些其他颜色

结果是:

[{
  "type": "pen",
  "color": "red",
  "color_list": ["red", "blue", "green"]
},
{
  "type": "pen",
  "color": "green",
  "color_list": ["red", "blue", "green"]
},
...]

设置color为可搜索属性并用于distinct删除重复结果;然后,您可以获得非常相关的搜索结果,例如“green pen”,这将返回笔记录"color": "green"(例如,您将获得具有正确颜色的产品图片),但允许您显示所有其他颜色样本可用的颜色。

我希望这有帮助!如果您想更具体地详细说明您的用例,请发表评论:)

于 2019-01-14T17:22:57.777 回答