3

场景:

我有以下(简化的)数据库表场景:

ID   ProductName          ProductCategory   Colour   Price
----------------------------------------------------------
1    BatmanTShirt         T-Shirt           Black    22
2    BatmanTShirt         T-Shirt           Blue     20
3    SupermanTShirt       T-Shirt           Blue     19
4    SpidermanTrousers    Trousers          Red      28
5    SpidermanTrousers    Trousers          Black    30

我的希望:

在 SOLR 索引中,我希望以规范化的方式映射这些数据,以便只创建 3 个 SOLR 文档(如下所示)而不是 5 个。

<doc1>
  <ID>1</ID>
  <ProductName>BatmanTShirt</ProductName>
  <ProductCategory>T-Shirt</ProductCategory>
  <OtherDetails>{ {1, Black, 22}, {2, Blue, 20} }</OtherDetails>
</doc1>
<doc2>
  <ID>3</ID>
  <ProductName>SupermanTShirt</ProductName>
  <ProductCategory>T-Shirt</ProductCategory>
  <OtherDetails>{ {3, Blue, 19} }</OtherDetails>
</doc2>
<doc3>
  <ID>4</ID>
  <ProductName>SpidermanTrousers</ProductName>
  <ProductCategory>Trousers</ProductCategory>
  <OtherDetails>{ {4, Red, 28}, {5, black, 30} }</OtherDetails>
</doc3>

一些注意事项:

  • <ID>将包含组中的最小 ID
  • <OtherDetails>将包含唯一 ID 以及分组时遗漏的其他详细信息。这将是一个数据类型为 List 的多值字段,其中包含另一个详细信息列表 {ID、颜色、价格}。

问题:

任何人都知道这怎么可能?

附言

进行此“分组”移动的原因是我想在 ProductCategory 上进行分面。如果我在 ProductCategory 上使用 faceting,目前生成的计数将是:

T-Shirt (3)
Trousers (2)

现在我想要的是在没有颜色和价格数据的 ProductCategory 上进行分面,这样我就想要只有 2 件 T 恤(蝙蝠侠和超人之一)和只有 1 条裤子(蜘蛛侠)。因此,我想展示的是:

T-Shirt (2)
Trousers (1)

我做了一些研究,发现这个功能(称为 Post-Group Faceting 或 Matrix counts)目前是 WIP,如SOLR 补丁中所述。所以我想要一个临时的解决方法,因为这可能需要一段时间才能完成。

4

1 回答 1

1

该补丁适用于单值字段,因此使用此补丁和分组是最好的方法。

只需像在数据库中一样索引数据,因此您不需要使用多值字段。

您可以使用 TortoiseSVN 下载最新的代码并应用补丁。在 Eclipse 中构建 WAR(或 JAR)非常容易。只需使用刚刚下载的代码启动新项目,然后运行根目录和 solr 目录中 build.xml 中的 ant 脚本。

于 2012-01-08T23:48:14.907 回答