获取单个 SOLR 文档所属的多个组/类别
我们正在使用 SOLR 为电子商务应用程序索引产品,我们的产品按类别和子类别分组,同一产品可以出现在多个子类别中,我们需要检索它所属的所有子类别中的产品并希望使用一个查询即可实现这一目标。任何指示都会非常有帮助。示例如下 -
假设产品 p1 属于子类别 sc1,而 sc2 属于父类别 c1
c1 ----- sc1 ----- p1
c1 ----- sc2 ----- p1
我们的方式对产品进行索引是为了在产品 p1 中具有类别路径信息, p1 - (c1->sc1 和 c1->sc2) 的类别路径
当用户浏览类别 c1 时,产品应在按子类别 sc1 和 sc2 分组的页面上出现两次,如下所示
c1 ----- sc1
p1
----- sc2
p1
我们希望从 solr 进行查询,以便它返回分为 2 个不同子类别的相同产品,从而有效地重复结果。我们可以在从 solr 获取结果后以编程方式完成此操作,但我们有分页和排序顺序逻辑,这很难在代码中维护。
We are using SOLR to index products for an eCommerce application, we have products grouped by category and subcategories and the same product can appear in more than one subcategory, We need to retrieve the products in all the subcategories it belongs to and would like to use one single query to achieve this objective. Any pointers would be really helpful. Example illustrated below -
Assume that a product p1 belongs to subcategory sc1 and sc2 which belongs to parent category c1
c1 ----- sc1 ----- p1
c1 ----- sc2 ----- p1
The way we have indexed the product is to have category path information in product p1,
p1 - Category path of (c1->sc1 and c1->sc2)
When the user browses through the category c1 the product should appear twice on the page grouped by subcategory sc1 and sc2 as shown below
c1 ----- sc1
p1
----- sc2
p1
We want to query from solr so that it returns the same product grouped in 2 different subcategories, effectively duplicating in the result. We could do it programatically after fetching the result from solr but we have pagination and sort order logic which would be hard to maintain in the code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就像标签。您知道,当您为事物添加标签时,单个项目可以有多个标签。在 SOLR 中,您可以将其表示为多值字段,即值数组。
您需要将“子类别”设为多值字段。我认为您对路径的引用意味着在多个不相关的类别中使用相同的子类别标识符,因此您将类别和子类别组合在一起以获得唯一的键。
在这种情况下,您可能会:
当您检索子类别匹配 c1 的所有产品时
This is like tags. You know that when you tag things, a single item can have more than one tag. In SOLR you would represent that as a multivalued field, i.e. an array of values.
You need to make "subcategory" into a multivalued field. I think that your reference to path means that the same subcategory identifier is used in multiple unrelated categories thus you are combining category and subcategory together to get unique keys.
In that case you might have:
When you retrieve all products with subcategory matching c1
为了实际多次返回产品,您需要在该产品的 Solr 索引中包含多个记录。我怀疑这会使更新单个产品记录变得有点困难——假设您使用唯一的密钥,您将需要一个基于产品 ID 和子类别的密钥。
我同意 Michael Dillon 的建议,即将“子类别”设为多值字段,然后适当地格式化结果。
In order to actually return the product multiple times, you would need multiple records in your Solr index for that product. I suspect that would make updating individual product records a bit difficult however -- assuming you're using a unique key, you would need a key based on both product ID and subcategory.
I agree with Michael Dillon's suggestion of making "subcategory" a multiValued field and then formatting the results appropriately.