Solr query to find child and parent documents by concatenation

I need help creating a Solr query that will not only search for child documents and return the parent, but also search in the parent. See my diagram below:

Manufacturer

  • Id
  • Name
  • Comments

Products

  • Id
  • ManufacturerId
  • ProductName

All Solr documents have a unique ID field, but products have a special "ManufacturerId" field that acts as a foreign key.

I would like to find all products named "iPod" and return the parent documents to "Manufacturer". I can accomplish using the following Join statement.

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

      

Also, I would like to cancel the Manufacturers who have iPods in the comments. Therefore, the result will be all manufacturers who have iPod products and the word iPod is in the comment field. I have tried the following with no luck.

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

      

Any help would be greatly appreciated.

Thank!!

UPDATE:

It seems to work correctly when I use the "fq" field for the filter, as opposed to the normal "q" query field. I'm not sure if this is the best solution. Also, I'm wondering if relevance would work the same way. Better solutions are evaluated.

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

      

or

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

      

+3


source to share


2 answers


Using a query tells Solr that another query needs to be made that will affect the list of results.

d =



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

      

0


source


If you are really referring to child (aka nested) documents and parents, I suggest you use a block join:

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



which was specially created for this purpose. Add "OR" for any other condition and you should be fine.

0


source







All Articles