3

The question is applied for the following nested documents:

<doc>
  <field name="id">1</field>
  <field name="title">Solr has block join support</field>
  <field name="content_type">parentDocument</field>
  <doc>
    <field name="id">11</field>  
    <field name="type">comment</field>  
    <field name="comments">SolrCloud supports it too!</field>
  </doc>
  <doc>
    <field name="id">12</field>  
    <field name="type">publisher</field>  
    <field name="address">England</field>
    ....
  </doc>
</doc>
....

My question is, how to write the Block Join Parent Query which allows to have constraints on multiple nested children documents? I did try the following, but it did not work:

{!parent which="content_type:accommodation"}
(
  (+type:comment +comments:SolrCloud) AND
  (+type:publisher +address:England)
) 

0 was returned as result!

Tim Long
  • 2,039
  • 1
  • 22
  • 25

1 Answers1

9

For your use case you can just multiple block join filters:

q=*:*&
fq={!parent which="content_type:accommodation"}(+type:comment +comments:SolrCloud)&
fq={!parent which="content_type:accommodation"}(+type:publisher +address:England)

the first filter clouse will find which parent documents have a child which satisfies condition (+type:comment +comments:SolrCloud).

The second filter clouse will operate over subset of parent documents that satisfy the first filter. And it will find in this subset the parent documents that satisfy condition (+type:publisher +address:England).

Molecular Man
  • 22,277
  • 3
  • 72
  • 89
  • I'll try your solution when i come back to the company! – Tim Long Jan 26 '16 at 20:33
  • Your suggestion doesn't work! Even with only one fq-query-clause! The query must be put in the clause, which starts with q={!parent which=....}. But as said, I still don't know how to write the query! – Tim Long Feb 10 '16 at 15:52
  • Hi Molecular Man, it works now! But the main query must be one of those block join queries OR the main query must return everything, like: q=*:* Please update your answer so that it could be marked as the right answer! – Tim Long Feb 15 '16 at 16:44
  • Hello Tim Long , Thanks a lot for your solution as i was breaking my head over this very thing for some time . I guess you should mark this question as resolved using the self answering feature – redeemed Nov 19 '16 at 08:24
  • @TimLong, sure. Updated the answer – Molecular Man Nov 19 '16 at 10:16
  • The same can be done only using q param , q=({!parent which="content_type:accommodation"}(+type:comment +comments:SolrCloud)) AND ({!parent which="content_type:accommodation"}(+type:publisher +address:England)) – redeemed Nov 23 '16 at 02:52
  • @redeemed q and fq may behave differently. Also fq normally is much more performant. http://stackoverflow.com/questions/8730898/solr-filter-query-vs-main-query – Molecular Man Nov 23 '16 at 12:26
  • Yes , so long as the results match am good for the time being . – redeemed Nov 23 '16 at 14:26
  • 1
    Btw , wats the problem with this query ({!parent which="doc_type:parent"}Abc AND Def) , the moment i group the query inside paranthesis and include an AND condition in the child query condition it fails to work . Why is that so – redeemed Nov 23 '16 at 14:41
  • I would need to use q at times when i would need an OR between two block joins right ? Can that work with fq's ? – redeemed Nov 23 '16 at 14:59