This is a patch I made to be able to boost the terms with a specific factor
beside the relevancy returned by MoreLikeThis. This is helpful when having
more then 1 MoreLikeThis in the query, so words in the field A (i.e. Title)
can be boosted more than words in the field B (i.e. Description).

Any feedback?

Jonathan
Index: 
/home/developer/workspace/lucene/contrib/queries/src/java/org/apache/lucene/search/similar/MoreLikeThis.java
===================================================================
--- 
/home/developer/workspace/lucene/contrib/queries/src/java/org/apache/lucene/search/similar/MoreLikeThis.java
        (revision 651048)
+++ 
/home/developer/workspace/lucene/contrib/queries/src/java/org/apache/lucene/search/similar/MoreLikeThis.java
        (working copy)
@@ -284,6 +284,11 @@
     private final IndexReader ir;
 
     /**
+     * Boost factor to use when boosting the terms
+     */
+    private int boostFactor = 1;
+    
+    /**
      * Constructor requiring an IndexReader.
      */
     public MoreLikeThis(IndexReader ir) {
@@ -574,7 +579,7 @@
                 }
                 float myScore = ((Float) ar[2]).floatValue();
 
-                tq.setBoost(myScore / bestScore);
+                tq.setBoost(boostFactor * myScore / bestScore);
             }
 
             try {
@@ -921,6 +926,22 @@
             x = 1;
         }
     }
+
+    /**
+     * Returns the boost factor used when boosting terms
+     * @return the boost factor used when boosting terms
+     */
+       public int getBoostFactor() {
+               return boostFactor;
+       }
+
+       /**
+        * Sets the boost factor to use when boosting terms
+        * @param boostFactor
+        */
+       public void setBoostFactor(int boostFactor) {
+               this.boostFactor = boostFactor;
+       }
     
     
 }

Reply via email to