lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r829002 - in /lucene/java/trunk: ./ src/java/org/apache/lucene/search/ src/test/org/apache/lucene/index/ src/test/org/apache/lucene/search/ src/test/org/apache/lucene/search/payloads/
Date Fri, 23 Oct 2009 11:25:48 GMT
Author: uschindler
Date: Fri Oct 23 11:25:48 2009
New Revision: 829002

URL: http://svn.apache.org/viewvc?rev=829002&view=rev
Log:
LUCENE-1973: Remove Similarity deprecations

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/common-build.xml
    lucene/java/trunk/src/java/org/apache/lucene/search/MultiPhraseQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/Similarity.java
    lucene/java/trunk/src/java/org/apache/lucene/search/SimilarityDelegator.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestOmitTf.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestSimilarity.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestTermVectors.java
    lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=829002&r1=829001&r2=829002&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Fri Oct 23 11:25:48 2009
@@ -92,6 +92,8 @@
   is no backwards-break, only a change of the super class. Parameter
   was deprecated and will be removed in a later version.
   (DM Smith, Uwe Schindler)
+  
+ * LUCENE-1973: Remove deprecated Similarity methods. (Uwe Schindler)
 
 Bug fixes
 

Modified: lucene/java/trunk/common-build.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/common-build.xml?rev=829002&r1=829001&r2=829002&view=diff
==============================================================================
--- lucene/java/trunk/common-build.xml (original)
+++ lucene/java/trunk/common-build.xml Fri Oct 23 11:25:48 2009
@@ -42,7 +42,7 @@
   <property name="Name" value="Lucene"/>
   <property name="dev.version" value="3.0-dev"/>
   <property name="version" value="${dev.version}"/>
-  <property name="compatibility.tag" value="lucene_2_9_back_compat_tests_20091022"/>
+  <property name="compatibility.tag" value="lucene_2_9_back_compat_tests_20091023"/>
   <property name="spec.version" value="${version}"/>	
   <property name="year" value="2000-${current.year}"/>
   <property name="final.name" value="lucene-${name}-${version}"/>

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/MultiPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/MultiPhraseQuery.java?rev=829002&r1=829001&r2=829002&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/MultiPhraseQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/MultiPhraseQuery.java Fri Oct 23 11:25:48
2009
@@ -134,9 +134,10 @@
       this.similarity = getSimilarity(searcher);
 
       // compute idf
+      final int maxDoc = searcher.maxDoc();
       for(final Term[] terms: termArrays) {
         for (Term term: terms) {
-          idf += getSimilarity(searcher).idf(term, searcher);
+          idf += this.similarity.idf(searcher.docFreq(term), maxDoc);
         }
       }
     }

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/Similarity.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/Similarity.java?rev=829002&r1=829001&r2=829002&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/Similarity.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/Similarity.java Fri Oct 23 11:25:48
2009
@@ -704,27 +704,6 @@
    */
   public abstract float tf(float freq);
 
-  /** Computes a score factor for a simple term.
-   *
-   * <p>The default implementation is:<pre>
-   *   return idf(searcher.docFreq(term), searcher.maxDoc());
-   * </pre>
-   *
-   * Note that {@link Searcher#maxDoc()} is used instead of
-   * {@link org.apache.lucene.index.IndexReader#numDocs() IndexReader#numDocs()} because
also 
-   * {@link Searcher#docFreq(Term)} is used, and when the latter 
-   * is inaccurate, so is {@link Searcher#maxDoc()}, and in the same direction.
-   * In addition, {@link Searcher#maxDoc()} is more efficient to compute
-   *
-   * @param term the term in question
-   * @param searcher the document collection being searched
-   * @return a score factor for the term
-   * @deprecated see {@link #idfExplain(Term, Searcher)}
-   */
-  public float idf(Term term, Searcher searcher) throws IOException {
-    return idf(searcher.docFreq(term), searcher.maxDoc());
-  }
-  
   /**
    * Computes a score factor for a simple term and returns an explanation
    * for that score factor.
@@ -749,19 +728,6 @@
    * @throws IOException
    */
   public IDFExplanation idfExplain(final Term term, final Searcher searcher) throws IOException
{
-    if(supportedMethods.overridesTermIDF) {
-      final float idf = idf(term, searcher);
-      return new IDFExplanation() {
-        @Override
-        public float getIdf() {
-          return idf;
-        }
-        @Override
-        public String explain() {
-          return "Inexplicable";
-        }
-      };
-    }
     final int df = searcher.docFreq(term);
     final int max = searcher.maxDoc();
     final float idf = idf(df, max);
@@ -777,25 +743,6 @@
         }};
    }
 
-  /** Computes a score factor for a phrase.
-   *
-   * <p>The default implementation sums the {@link #idf(Term,Searcher)} factor
-   * for each term in the phrase.
-   *
-   * @param terms the terms in the phrase
-   * @param searcher the document collection being searched
-   * @return idf score factor
-   * @deprecated see {@link #idfExplain(Collection, Searcher)}
-   */
-  public float idf(Collection<Term> terms, Searcher searcher) throws IOException {
-    float idf = 0.0f;
-
-    for(final Term term: terms) {
-      idf += idf(term, searcher);
-    }
-    return idf;
-  }
-  
   /**
    * Computes a score factor for a phrase.
    * 
@@ -811,19 +758,6 @@
    * @throws IOException
    */
   public IDFExplanation idfExplain(Collection<Term> terms, Searcher searcher) throws
IOException {
-    if(supportedMethods.overridesCollectionIDF) {
-      final float idf = idf(terms, searcher);
-      return new IDFExplanation() {
-        @Override
-        public float getIdf() {
-          return idf;
-        }
-        @Override
-        public String explain() {
-          return "Inexplicable";
-        }
-      };
-    }
     final int max = searcher.maxDoc();
     float idf = 0.0f;
     final StringBuilder exp = new StringBuilder();
@@ -877,31 +811,6 @@
    */
   public abstract float coord(int overlap, int maxOverlap);
 
-
-
-
-  /**
-   * Calculate a scoring factor based on the data in the payload.  Overriding implementations
-   * are responsible for interpreting what is in the payload.  Lucene makes no assumptions
about
-   * what is in the byte array.
-   * <p>
-   * The default implementation returns 1.
-   *
-   * @param fieldName The fieldName of the term this payload belongs to
-   * @param payload The payload byte array to be scored
-   * @param offset The offset into the payload array
-   * @param length The length in the array
-   * @return An implementation dependent float to be used as a scoring factor
-   *
-   * @deprecated See {@link #scorePayload(int, String, int, int, byte[], int, int)}
-   */
-  //TODO: When removing this, set the default value below to return 1.
-  public float scorePayload(String fieldName, byte [] payload, int offset, int length)
-  {
-    //Do nothing
-    return 1;
-  }
-
   /**
    * Calculate a scoring factor based on the data in the payload.  Overriding implementations
    * are responsible for interpreting what is in the payload.  Lucene makes no assumptions
about
@@ -921,46 +830,7 @@
    */
   public float scorePayload(int docId, String fieldName, int start, int end, byte [] payload,
int offset, int length)
   {
-    //TODO: When removing the deprecated scorePayload above, set this to return 1
-    return scorePayload(fieldName, payload, offset, length);
-  }
-  
-  /** @deprecated Remove this when old API is removed! */
-  private final MethodSupport supportedMethods = getSupportedMethods(this.getClass());
-  
-    /** @deprecated Remove this when old API is removed! */
-  private static final class MethodSupport implements Serializable {
-    final boolean overridesCollectionIDF, overridesTermIDF;
-
-    MethodSupport(Class<? extends Similarity> clazz) {
-      overridesCollectionIDF = isMethodOverridden(clazz, "idf", Collection.class, Searcher.class);
-      overridesTermIDF = isMethodOverridden(clazz, "idf", Term.class, Searcher.class);
-    }
-    
-    private static boolean isMethodOverridden(Class<?> clazz, String name, Class...
params) {
-      try {
-        return clazz.getMethod(name, params).getDeclaringClass() != Similarity.class;
-      } catch (NoSuchMethodException e) {
-        // should not happen
-        throw new RuntimeException(e);
-      }
-    }
-  }
-  
-  /** @deprecated Remove this when old API is removed! */
-  private static final IdentityHashMap<Class<? extends Similarity>,MethodSupport>
knownMethodSupport
-    = new IdentityHashMap<Class<? extends Similarity>,MethodSupport>();
-  
-  /** @deprecated Remove this when old API is removed! */
-  private static MethodSupport getSupportedMethods(Class<? extends Similarity> clazz)
{
-    MethodSupport supportedMethods;
-    synchronized(knownMethodSupport) {
-      supportedMethods = (MethodSupport) knownMethodSupport.get(clazz);
-      if (supportedMethods == null) {
-        knownMethodSupport.put(clazz, supportedMethods = new MethodSupport(clazz));
-      }
-    }
-    return supportedMethods;
+    return 1;
   }
   
   /** The Similarity implementation used by default. 

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/SimilarityDelegator.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/SimilarityDelegator.java?rev=829002&r1=829001&r2=829002&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/SimilarityDelegator.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/SimilarityDelegator.java Fri Oct 23
11:25:48 2009
@@ -62,7 +62,7 @@
     return delegee.coord(overlap, maxOverlap);
   }
 
-  public float scorePayload(String fieldName, byte[] payload, int offset, int length) {
-    return delegee.scorePayload(fieldName, payload, offset, length);
+  public float scorePayload(int docId, String fieldName, int start, int end, byte [] payload,
int offset, int length) {
+    return delegee.scorePayload(docId, fieldName, start, end, payload, offset, length);
   }
 }

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestOmitTf.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestOmitTf.java?rev=829002&r1=829001&r2=829002&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestOmitTf.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestOmitTf.java Fri Oct 23 11:25:48
2009
@@ -36,23 +36,32 @@
 import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.MockRAMDirectory;
+import org.apache.lucene.search.Explanation.IDFExplanation;
 
 
 public class TestOmitTf extends LuceneTestCase {
     
   public static class SimpleSimilarity extends Similarity {
-    public float lengthNorm(String field, int numTerms) { return 1.0f; }
-    public float queryNorm(float sumOfSquaredWeights) { return 1.0f; }
-    
-    public float tf(float freq) { return freq; }
-    
-    public float sloppyFreq(int distance) { return 2.0f; }
-    public float idf(Collection terms, Searcher searcher) { return 1.0f; }
-    public float idf(int docFreq, int numDocs) { return 1.0f; }
-    public float coord(int overlap, int maxOverlap) { return 1.0f; }
+    @Override public float lengthNorm(String field, int numTerms) { return 1.0f; }
+    @Override public float queryNorm(float sumOfSquaredWeights) { return 1.0f; }
+    @Override public float tf(float freq) { return freq; }
+    @Override public float sloppyFreq(int distance) { return 2.0f; }
+    @Override public float idf(int docFreq, int numDocs) { return 1.0f; }
+    @Override public float coord(int overlap, int maxOverlap) { return 1.0f; }
+    @Override public IDFExplanation idfExplain(Collection<Term> terms, Searcher searcher)
throws IOException {
+      return new IDFExplanation() {
+        @Override
+        public float getIdf() {
+          return 1.0f;
+        }
+        @Override
+        public String explain() {
+          return "Inexplicable";
+        }
+      };
+    }
   }
 
-
   // Tests whether the DocumentWriter correctly enable the
   // omitTermFreqAndPositions bit in the FieldInfo
   public void testOmitTermFreqAndPositions() throws Exception {

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestSimilarity.java?rev=829002&r1=829001&r2=829002&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestSimilarity.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestSimilarity.java Fri Oct 23 11:25:48
2009
@@ -29,6 +29,7 @@
 import org.apache.lucene.analysis.SimpleAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
+import org.apache.lucene.search.Explanation.IDFExplanation;
 
 /** Similarity unit test.
  *
@@ -41,13 +42,24 @@
   }
   
   public static class SimpleSimilarity extends Similarity {
-    public float lengthNorm(String field, int numTerms) { return 1.0f; }
-    public float queryNorm(float sumOfSquaredWeights) { return 1.0f; }
-    public float tf(float freq) { return freq; }
-    public float sloppyFreq(int distance) { return 2.0f; }
-    public float idf(Collection terms, Searcher searcher) { return 1.0f; }
-    public float idf(int docFreq, int numDocs) { return 1.0f; }
-    public float coord(int overlap, int maxOverlap) { return 1.0f; }
+    @Override public float lengthNorm(String field, int numTerms) { return 1.0f; }
+    @Override public float queryNorm(float sumOfSquaredWeights) { return 1.0f; }
+    @Override public float tf(float freq) { return freq; }
+    @Override public float sloppyFreq(int distance) { return 2.0f; }
+    @Override public float idf(int docFreq, int numDocs) { return 1.0f; }
+    @Override public float coord(int overlap, int maxOverlap) { return 1.0f; }
+    @Override public IDFExplanation idfExplain(Collection<Term> terms, Searcher searcher)
throws IOException {
+      return new IDFExplanation() {
+        @Override
+        public float getIdf() {
+          return 1.0f;
+        }
+        @Override
+        public String explain() {
+          return "Inexplicable";
+        }
+      };
+    }
   }
 
   public void testSimilarity() throws Exception {
@@ -80,7 +92,7 @@
            this.scorer = scorer; 
          }
          public final void collect(int doc) throws IOException {
-           assertTrue(scorer.score() == 1.0f);
+           assertEquals(1.0f, scorer.score());
          }
          public void setNextReader(IndexReader reader, int docBase) {}
          public boolean acceptsDocsOutOfOrder() {
@@ -100,7 +112,7 @@
          }
          public final void collect(int doc) throws IOException {
            //System.out.println("Doc=" + doc + " score=" + score);
-           assertTrue(scorer.score() == (float)doc+base+1);
+           assertEquals((float)doc+base+1, scorer.score());
          }
          public void setNextReader(IndexReader reader, int docBase) {
            base = docBase;
@@ -114,8 +126,7 @@
     pq.add(a);
     pq.add(c);
     //System.out.println(pq.toString("field"));
-    searcher.search
-      (pq,
+    searcher.search(pq,
        new Collector() {
         private Scorer scorer;
         public void setScorer(Scorer scorer) throws IOException {
@@ -123,7 +134,7 @@
         }
          public final void collect(int doc) throws IOException {
            //System.out.println("Doc=" + doc + " score=" + score);
-           assertTrue(scorer.score() == 1.0f);
+           assertEquals(1.0f, scorer.score());
          }
          public void setNextReader(IndexReader reader, int docBase) {}
          public boolean acceptsDocsOutOfOrder() {
@@ -140,7 +151,7 @@
         }
          public final void collect(int doc) throws IOException {
            //System.out.println("Doc=" + doc + " score=" + score);
-           assertTrue(scorer.score() == 2.0f);
+           assertEquals(2.0f, scorer.score());
          }
          public void setNextReader(IndexReader reader, int docBase) {}
          public boolean acceptsDocsOutOfOrder() {

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestTermVectors.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestTermVectors.java?rev=829002&r1=829001&r2=829002&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestTermVectors.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestTermVectors.java Fri Oct 23 11:25:48
2009
@@ -258,7 +258,7 @@
           //System.out.println("Doc Id: " + docId + " freq " + freq);
           TermFreqVector vector = knownSearcher.reader.getTermFreqVector(docId, "field");
           float tf = sim.tf(freq);
-          float idf = sim.idf(term, knownSearcher);
+          float idf = sim.idf(knownSearcher.docFreq(term), knownSearcher.maxDoc());
           //float qNorm = sim.queryNorm()
           //This is fine since we don't have stop words
           float lNorm = sim.lengthNorm("field", vector.getTerms().length);

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java?rev=829002&r1=829001&r2=829002&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java
(original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java
Fri Oct 23 11:25:48 2009
@@ -41,6 +41,7 @@
 import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.util.English;
 import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.search.Explanation.IDFExplanation;
 
 
 public class TestPayloadNearQuery extends LuceneTestCase {
@@ -223,35 +224,45 @@
   // must be static for weight serialization tests 
   static class BoostingSimilarity extends DefaultSimilarity {
 
-    // TODO: Remove warning after API has been finalized
-    public float scorePayload(int docId, String fieldName, int start, int end, byte[] payload,
int offset, int length) {
+    @Override public float scorePayload(int docId, String fieldName, int start, int end,
byte[] payload, int offset, int length) {
       //we know it is size 4 here, so ignore the offset/length
       return payload[0];
     }
+    
     //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     //Make everything else 1 so we see the effect of the payload
     //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    public float lengthNorm(String fieldName, int numTerms) {
-      return 1;
+    @Override public float lengthNorm(String fieldName, int numTerms) {
+      return 1.0f;
     }
 
-    public float queryNorm(float sumOfSquaredWeights) {
-      return 1;
+    @Override public float queryNorm(float sumOfSquaredWeights) {
+      return 1.0f;
     }
 
-    public float sloppyFreq(int distance) {
-      return 1;
+    @Override public float sloppyFreq(int distance) {
+      return 1.0f;
     }
 
-    public float coord(int overlap, int maxOverlap) {
-      return 1;
+    @Override public float coord(int overlap, int maxOverlap) {
+      return 1.0f;
     }
-    public float tf(float freq) {
-      return 1;
+    @Override public float tf(float freq) {
+      return 1.0f;
     }
+    
     // idf used for phrase queries
-    public float idf(Collection terms, Searcher searcher) {
-      return 1;
+    @Override public IDFExplanation idfExplain(Collection<Term> terms, Searcher searcher)
throws IOException {
+      return new IDFExplanation() {
+        @Override
+        public float getIdf() {
+          return 1.0f;
+        }
+        @Override
+        public String explain() {
+          return "Inexplicable";
+        }
+      };
     }
   }
 }



Mime
View raw message