solr join - return parent and child document

2019-04-10 18:38发布

问题:

I am using Solr's (4.0.0-beta) join capability to query an index that has documents with parent/child relationships. The join query works great, but I only get the parent documents in the search results. I believe this is the expected behavior.

Is it possible, though, to get both the parent and the child documents to be returned in the search results? (as separate search hits).

For example:

Parents:

SolrDocument{uid=m_1, media_id=1}<br/>
SolrDocument{uid=m_2, media_id=2}<br/>
SolrDocument{uid=m_3, media_id=3}

Children:

SolrDocument(uid=p_1, page_id=1, fk_media_id=[1], partNumber=[abc, def, xyz]}<br/>
SolrDocument(uid=p_2, page_id=2, fk_media_id=[1,2], partNumber=[123, 456]}<br/>
SolrDocument(uid=p_3, page_id=3, fk_media_id=[1,3], partNumber=[100, 101]}

I query by partNumber like this:

{!join from=fk_media_id to=media_id}partNumber:abc

and I get the parent document (uid=m_1) in the results, as expected. But I would like, in this case, both the parent and the child to be returned in the results. Is that possible?

回答1:

No, It´s not posible. According to Solr Wiki:

For people who are used to SQL, it's important to note that Joins in Solr are not really equivalent to SQL Joins because no information about the table being joined "from" is carried forward into the final result. A more appropriate SQL analogy would be an "inner query""

http://wiki.apache.org/solr/Join

You have to denormalize all your data to do that or run two different querys.



标签: join solr