我希望有人可以帮助我尝试使用 MySQL 后端来扁平化 Solr 的一些表。
这是 ERD:ERD for products
我有一个链接到内容表的产品表和一个用于覆盖内容的 market_content 表。文本意义上的内容。产品表通过“content.id”的外键引用内容表,“content.default_content”字段显示与“content.id”相关的内容。该内容可以被表 market_content 覆盖。如果“market_content.id”字段中有一个与“content.id”中的记录匹配的相应ID,那么我希望它从“market_content.content”字段获取内容,而不是使用“content.default_content”。
来自“content.default_content”或“market_content.content”的内容是“洗发水”、“含护发素的洗发水”等文本。
我在尝试从 Solr 返回结果时使结构如下所示,并确保如果 market_content 表中存在与内容表中的 id 相对应的 id,则 Solr 返回覆盖 market_content 表“market.content.content”字段中的内容。
我希望结果的结构如下:
ProductId:1
Market:
GB:
Content_id_description: shampoo
US:
Content_id_description: shampoo
EU:
Content_id_description: Shampoo with conditioner
ProductId:2
Market:
GB:
Content_id_description: shampoo
US:
Content_id_description: shampoo
EU:
Content_id_description: shampoo
产品1;市场;欧洲联盟; Content_id_description(来自内容表的内容):被覆盖为“洗发水和护发素”。
是否有办法让 Solr 在此结构中输出?我将如何展平上面显示的 ERD 以获得 Solr 上的最佳优化搜索?
谢谢
最佳答案
以我的愚见,您不需要两个表来存储内容。您可以简化 ERD,如下所示 link 。在这里,您可以拥有一个带有默认代码的默认市场,该市场可用于没有市场相关描述的产品。
例如
product
id code
--- -----
1 a13d4
2 b453d
market
id code
--- -----
0 default
1 EU
2 GB
3 USA
market_product_details
product_id market_id description
---------- --------- -----------
1 0 Shampoo
1 1 Shampoo
1 2 Shampoo
1 3 Shampoo with Conditioner
2 0 Perfume
因此,上面的 market_id 0 是产品的默认名称。
就查询而言,由于表结构被简化,您可以像下面这样查询 solr:
从 market_product_details mp、market ma 中选择 mp.product_id、mp.market_id、ma.code、mp.description,其中 mp.market_id=ma.market
关于mysql - 如何创建双重嵌套字段,其中一个字段值可以被 Solr 中的另一个字段值覆盖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19490474/