3

I need help constructing a Solr query that will not only search child documents and return the parent, but also search on the parent. Please see my example schema below:

Manufacturer

  • Id
  • Name
  • Comments

Products

  • Id
  • ManufacturerId
  • ProductName

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

I would like to search all products that have the name "iPod" and return the parent "Manufacturer" documents. I can accomplish by using the following Join statement.

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

In addition, I would like to pull back Manufacturers that have iPod in Comments. Therefore the result would include all manufacturers that have iPod products and have the word iPod in it's comments field. 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'. 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
Abhijit Bashetti
  • 8,518
  • 7
  • 35
  • 47
Nathan Hall
  • 409
  • 2
  • 8
  • 17

2 Answers2

0

Using query tells Solr that another query should be made that will affect the result list.

q=

_query_:"{!join from=ManufacturerId to=Id}ProductName:iPod" OR Comments:iPod
Nathan Hall
  • 409
  • 2
  • 8
  • 17
0

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

which has been specifically created with that purpose. Add an 'OR' for any other condition and you should be all ok.

Bereng
  • 724
  • 4
  • 5
  • Sorry for any confusion. I should have mentioned they are not part of a single document, but rather separate documents. The relation exists due to the Product's ManufacturerId field but there's not a true defined relationship as there would be if it was a single "Manufacturer" document containing child "Products". Also I'm using Solr 4.3 which doesn't support Block join. – Nathan Hall Jun 23 '15 at 01:31