algolia - How to concatenate results on algolia
问题描述
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
解决方案
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"
(例如,您将获得具有正确颜色的产品图片),但允许您显示所有其他颜色样本可用的颜色。
我希望这有帮助!如果您想更具体地详细说明您的用例,请发表评论:)
推荐阅读
- ruby-on-rails - 如何将 db 中的数据呈现到 ActiveAdmin 生成的仪表板页面中?
- laravel - 本地站点不适用于 ubuntu 上的 Laravel homestead vagrant setup
- networking - Oracle XE 18C Express Edition Ora-12541:TNS:没有监听器
- chart.js - Chart.js 的 y 轴步长从 20 到 1(而不是 1 到 20)
- r - 通过函数在 dplyr 中动态构造 mutate 中的变量名
- javascript - 如何在 js 中使用这个 JSON 字符串
- scala - Json4s DefaultFormats:线程“主”java.lang.AbstractMethodError 中的异常
- azure - 如何查看有关 Azure Blob 容器租约的其他详细信息?
- java - 使用h2数据库和eclipse转换varchar的数据转换错误
- firebase - 有没有办法以编程方式为 Firebase 中的自定义存储桶设置安全规则?