From f89cda6dde7b0137e7f8041987272a329f72a2c3 Mon Sep 17 00:00:00 2001 From: Grant Ingersoll Date: Wed, 4 Jun 2008 10:41:41 +0000 Subject: [PATCH] LUCENE-1298: Allow MLT to use custom similarity git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@663054 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../lucene/search/similar/MoreLikeThis.java | 20 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 72e43d2055b..28b93ad8b48 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -177,6 +177,8 @@ New features 15. LUCENE-1295: Added new method to MoreLikeThis for retrieving interesting terms and made retrieveTerms(int) public. (Grant Ingersoll) +16. LUCENE-1298: MoreLikeThis can now accept a custom Similarity (Grant Ingersoll) + Optimizations 1. LUCENE-705: When building a compound file, use diff --git a/contrib/queries/src/java/org/apache/lucene/search/similar/MoreLikeThis.java b/contrib/queries/src/java/org/apache/lucene/search/similar/MoreLikeThis.java index af715818ae4..e97f0696704 100644 --- a/contrib/queries/src/java/org/apache/lucene/search/similar/MoreLikeThis.java +++ b/contrib/queries/src/java/org/apache/lucene/search/similar/MoreLikeThis.java @@ -276,7 +276,7 @@ public final class MoreLikeThis { /** * For idf() calculations. */ - private Similarity similarity = new DefaultSimilarity(); + private Similarity similarity;// = new DefaultSimilarity(); /** * IndexReader to use @@ -287,10 +287,24 @@ public final class MoreLikeThis { * Constructor requiring an IndexReader. */ public MoreLikeThis(IndexReader ir) { - this.ir = ir; + this(ir, new DefaultSimilarity()); } - /** + public MoreLikeThis(IndexReader ir, Similarity sim){ + this.ir = ir; + this.similarity = sim; + } + + + public Similarity getSimilarity() { + return similarity; + } + + public void setSimilarity(Similarity similarity) { + this.similarity = similarity; + } + + /** * Returns an analyzer that will be used to parse source doc with. The default analyzer * is the {@link #DEFAULT_ANALYZER}. *