In my last blog, I explained how to use the ExpandComponent to expand the groups that were collapsed with the CollapsingQParserPlugin. In this blog I’ll explain how to expand the parent/child relationship of a Solr block join.
First the data:
ISBN1_MASTER Solr On Fire parent ISBN1 ISBN1_page1 child ISBN1 Welcome to Solr On Fire ISBN1_page2 child ISBN1 Setting up Solr ISBN2_MASTER Mastering Solr parent ISBN2 ISBN2_page1 child ISBN2 Welcome to Mastering Solr ISBN2_page2 child ISBN2 Setting up Solr Masterfully
In the Solr documents above, there a two books. Each book has two pages, which will be loaded as a block with the master book records.
After loading we can issue the following parent block join query:
http://localhost:8983/solr/collection1/select?q={!parent which='type_s:parent'}text_t:solr&wt=xml&indent=true
This parent block join returns the parent book records for books where the child documents contain “solr” in the text_t field.
With the ExpandComponent, we can expand the results to include the children of the book records returned by the block join. For exmaple:
http://localhost:8983/solr/collection1/select?q={!parent which='type_s:parent'}text_t:solr&wt=xml&indent=true&expand=true&expand.field=ISBN_s&expand.q=*:*
The query above turns on the ExpandComponent with the expand=true parameter. The expand.field=ISBN_s parameter tells the ExpandComponent to group the expanded documents by the ISBN_s field. The expand.q=*:* tells the ExpandComponent to match all of the documents within the group. This is needed because by default the ExpandComponent uses the main query to determine which documents to match, which in this case was the block join.
With the ExpandComponent on, the results will have a new “expanded” section that contains the expanded child documents from the block join.
Notice the “expanded” results section below shows the pages grouped by ISBN.
0 2 true {!parent which='type_s:parent'}text_t:solr *:* true xml ISBN_s ISBN1_MASTER Solr On Fire parent ISBN1 1465668524599934976 ISBN2_MASTER Mastering Solr parent ISBN2 1465668524603080704 ISBN2_page1 child ISBN2 Welcome to Mastering Solr ISBN2_page2 child ISBN2 Setting up Solr Masterfully ISBN1_page1 child ISBN1 Welcome to Solr On Fire ISBN1_page2 child ISBN1 Setting up Solr