I needed this for one of my projects and wanted to keep SolrNet managed via nuget so here is what worked for me (YMMV):
create a BlockJoinResultParser class
public class BlockjoinResponseParser<T> : ISolrAbstractResponseParser<T>
{
private readonly ISolrDocumentResponseParser<T> docParser;
public BlockjoinResponseParser(ISolrDocumentResponseParser<T> docParser)
{
this.docParser = docParser;
}
public void Parse(XDocument xml, AbstractSolrQueryResults<T> results)
{
var expandedNode = xml.Element("response")
.Elements("lst")
.FirstOrDefault(X.AttrEq("name", "expanded"));
if (expandedNode != null)
{
foreach(var parent in expandedNode.Elements())
{
var lst = this.docParser.ParseResults(parent);
results.AddRange(lst);
}
}
}
basically this happens to docs in the "expanded" section to the query results. this means:
- your document model needs to accommodate the possible different structures of the 2 types of documents.
- your application logic must keep that in mind and process the doc accordingly (e.g. detect a content_type value)
at run time unregister the default document parser and register a new one which is an aggregate of the defaultdocumentresponseparser and the new blockjoinresponseparser
// unregister the *incomplete* default document parser
SolrNet.Startup.Container.Remove<ISolrAbstractResponseParser<myDocumentType>>();
// register my document parser which is an aggregate of the default one and the extra BlockJoinResponseParser
SolrNet.Startup.Container.Register<ISolrAbstractResponseParser<myDocumentType>>(c => new AggregateResponseParser<myDocumentType>(new ISolrAbstractResponseParser<myDocumentType>[] {
new DefaultResponseParser<myDocumentType>(c.GetInstance<ISolrDocumentResponseParser<myDocumentType>>()),
new BlockjoinResponseParser<myDocumentType>(c.GetInstance<ISolrDocumentResponseParser<myDocumentType>>())
}));
that's pretty much it. if you're willing to get back to the source, it would probably a definite option return the joined documents in a specific field of results modeled like the facets are.
Hoping this helps
Philippe