Question

I am using SOLRNET and am using SOLR's MoreLikeThis functionality to get similar documents to those that are being returned. My code looks a little something like this (in this case I am doing a lookup on ID as I already know the specific document I would like to load):

var solr = ServiceLocator.Current.GetInstance<ISolrOperations<MyDocument>>();

var queryOptions = new QueryOptions()
{
    MoreLikeThis = new MoreLikeThisParameters(new[] { "text" })
    {
        MinDocFreq = 1, // minimum document frequency
        MinTermFreq = 1, // minimum term frequency
    },
};

var document = solr.Query(new SolrQuery(string.Concat("id:", id)),queryOptions);

When I execute my query everything works exactly as it should and my document is retrieved as type MyDocument. I can iterate through SOLRNET's SimilarResults dictionary and see that similar documents are indeed returned. What I am wondering is if there is a native way to map a field in my MyDocument class so that it is populated with an collection of type MyDocument, representing the similar documents that are returned.

If I have to loop through the SimilarDocuments one by one that is fine, but I'm guessing there is a straightforward way to do this. I've tried the obvious tricks, like mapping using an attribute in my MyDocument class

   [SolrField("moreLikeThis")]
   public IDictionary<string,IList<MyDocument>> SimilarResults { get; set; }

Any help would be greatly appreciated,

Thanks in advance

JP

Was it helpful?

Solution

Similar results are not part of a document, and the can actually change whenever you update the index.

Anyway, solr.Query returns a ISolrQueryResults object, not just a document, so you will have a list of similar documents in document.SimilarResults that you can assign to any property you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top