简体   繁体   English

Solr Query通过join搜索子文档和父文档

[英]Solr Query to search child and parent documents by join

I need help constructing a Solr query that will not only search child documents and return the parent, but also search on the parent. 我需要帮助构建一个Solr查询,它不仅会搜索子文档并返回父文档,还会搜索父文档。 Please see my example schema below: 请参阅下面的示例架构:

Manufacturer 生产厂家

  • Id ID
  • Name 名称
  • Comments 评论

Products 制品

  • Id ID
  • ManufacturerId ManufacturerId
  • ProductName 产品名称

All Solr documents have a unique ID field, but Products have a special field "ManufacturerId" that acts as a foreign key. 所有Solr文档都有唯一的ID字段,但Products有一个特殊字段“ManufacturerId”作为外键。

I would like to search all products that have the name "iPod" and return the parent "Manufacturer" documents. 我想搜索所有名为“iPod”的产品,并返回父“制造商”文档。 I can accomplish by using the following Join statement. 我可以通过使用以下Join语句来完成。

{!join from=ManufacturerId to=Id}ProductName:iPod

In addition, I would like to pull back Manufacturers that have iPod in Comments. 此外,我想撤回评论中有iPod的制造商。 Therefore the result would include all manufacturers that have iPod products and have the word iPod in it's comments field. 因此,结果将包括所有拥有iPod产品且在其评论字段中包含iPod字样的制造商。 I've tried the following with no luck. 我试过以下没有运气。

{!join from=ManufacturerId to=Id}ProductName:iPod OR Comments:iPod

Any help would be greatly appreciated. 任何帮助将不胜感激。

Thanks!! 谢谢!!

UPDATE: 更新:

It seems to work correctly when I use the filter query 'fq' field as opposed to the regular query field 'q'. 当我使用过滤器查询'fq'字段而不是常规查询字段'q'时,它似乎正常工作。 I'm unsure if this is the best solution. 我不确定这是否是最佳解决方案。 Also, I wonder if relevancy will work the same way. 此外,我想知道相关性是否会以相同的方式工作。 Better solutions appreciated. 更好的解决方案。

Comments:iPod {!join from=RouteId to=Id}ProductName:iPod

or 要么

iPod {!join from=RouteId to=Id}ProductName:iPod

Using query tells Solr that another query should be made that will affect the result list. 使用查询告诉Solr应该进行另一个将影响结果列表的查询。

q= q =

_query_:"{!join from=ManufacturerId to=Id}ProductName:iPod" OR Comments:iPod

If you are really referring to child (aka nested) documents and parents I suggest you to use block join: 如果你真的指的是孩子(又名嵌套)文件和父母,我建议你使用块连接:

https://cwiki.apache.org/confluence/display/solr/Other+Parsers#OtherParsers-BlockJoinQueryParsers https://cwiki.apache.org/confluence/display/solr/Other+Parsers#OtherParsers-BlockJoinQueryParsers

which has been specifically created with that purpose. 这是专门为此目的而创建的。 Add an 'OR' for any other condition and you should be all ok. 为任何其他条件添加'OR',你应该没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM