Searchkick 聚合或
Searchkick Aggregation OR
我正在使用 Searchkick 搜索产品。它工作得很好,但现在我要添加过滤器。由于产品的性质,我总是想为选定的过滤器显示,而不是使用 AND,它总是需要使用 OR。
我正在构建这样的搜索:
Product.search(
"shower",
fields: [:name]
where: {showers_ids: [46,41], accessories_ids: [104, 102]},
aggs: [: showers_ids, : accessories_ids, : bath_ids]
)
正在尝试查询:
其中在(46 或 41)和(104 或 102)中
这将永远不会带回任何产品,因为产品只属于一个类别。但我想展示所有类别的产品,因此它需要像:
其中在(46 或 41)或(104 或 102)
您应该能够在您的 where 子句中使用 or_
参数来获得您想要的结果。 Searchkick docs 中有一个这样的示例,但对于您的特定情况,以下内容应该有效:
Product.search(
"shower",
fields: [:name],
aggs: [:showers_ids, :accessories_ids, :bath_ids],
where: {
_or: [
{showers_ids: [46, 41]},
{accessories_ids: [104, 102]}
]
}
)
我正在使用 Searchkick 搜索产品。它工作得很好,但现在我要添加过滤器。由于产品的性质,我总是想为选定的过滤器显示,而不是使用 AND,它总是需要使用 OR。
我正在构建这样的搜索:
Product.search(
"shower",
fields: [:name]
where: {showers_ids: [46,41], accessories_ids: [104, 102]},
aggs: [: showers_ids, : accessories_ids, : bath_ids]
)
正在尝试查询:
其中在(46 或 41)和(104 或 102)中
这将永远不会带回任何产品,因为产品只属于一个类别。但我想展示所有类别的产品,因此它需要像:
其中在(46 或 41)或(104 或 102)
您应该能够在您的 where 子句中使用 or_
参数来获得您想要的结果。 Searchkick docs 中有一个这样的示例,但对于您的特定情况,以下内容应该有效:
Product.search(
"shower",
fields: [:name],
aggs: [:showers_ids, :accessories_ids, :bath_ids],
where: {
_or: [
{showers_ids: [46, 41]},
{accessories_ids: [104, 102]}
]
}
)