开发者

How to find similar documents

开发者 https://www.devze.com 2023-04-10 13:48 出处:网络
How do you find a similar documents of a given document in Lucene. I do not know w开发者_C百科hat the text is i only know what the document is. Is there a way to find similar documents in lucene. I am

How do you find a similar documents of a given document in Lucene. I do not know w开发者_C百科hat the text is i only know what the document is. Is there a way to find similar documents in lucene. I am a newbie so I may need some hand holding.


you may want to check the MoreLikeThis feature of lucene.

MoreLikeThis constructs a lucene query based on terms within a document to find other similar documents in the index.

http://lucene.apache.org/java/3_0_1/api/contrib-queries/org/apache/lucene/search/similar/MoreLikeThis.html

Sample code example (java reference) -

MoreLikeThis mlt = new MoreLikeThis(reader); // Pass the index reader
mlt.setFieldNames(new String[] {"title", "author"}); // specify the fields for similiarity

Query query = mlt.like(docID); // Pass the doc id 
TopDocs similarDocs = searcher.search(query, 10); // Use the searcher
if (similarDocs.totalHits == 0)
    // Do handling
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号