Lucene.NET MoreLikeThis Example

2019-04-13 01:43发布

问题:

Could anyone give an example of how to use the MoreLikeThis feature in Lucene.NET. I have searched online and cannot find a single example.

回答1:

(Resurrecting an old question!)

As an example for Lucene.Net 2.9.4g:

var moreLikeThis = new Lucene.Net.Search.Similar.MoreLikeThis(indexReader);
moreLikeThis.SetAnalyzer(analyzer);
moreLikeThis.SetFieldNames(fieldNames);
moreLikeThis.SetStopWords(stopWords);
moreLikeThis.SetMinWordLen(2);
var query = moreLikeThis.Like(new System.IO.StringReader(similarity));

This generates a Lucene.Net.Search.Query object that can be used to search for documents that are similar to the text passed into the StringReader object.