lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1062927 [2/2] - in /lucene/dev/trunk: lucene/ lucene/contrib/instantiated/src/java/org/apache/lucene/store/instantiated/ lucene/contrib/memory/src/java/org/apache/lucene/index/memory/ lucene/contrib/misc/src/java/org/apache/lucene/index/ l...
Date Mon, 24 Jan 2011 19:13:33 GMT
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestOmitTf.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestOmitTf.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestOmitTf.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestOmitTf.java Mon Jan 24 19:13:31
2011
@@ -35,13 +35,11 @@ import org.apache.lucene.search.Explanat
 
 public class TestOmitTf extends LuceneTestCase {
   
-  public static class SimpleSimilarity extends Similarity {
+  public static class SimpleSimilarity extends Similarity implements SimilarityProvider {
     @Override public float computeNorm(String field, FieldInvertState state) { return state.getBoost();
}
-    @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, IndexSearcher
searcher) throws IOException {
       return new IDFExplanation() {
         @Override
@@ -54,6 +52,11 @@ public class TestOmitTf extends LuceneTe
         }
       };
     }
+    public float queryNorm(float sumOfSquaredWeights) { return 1.0f; }
+    public float coord(int overlap, int maxOverlap) { return 1.0f; }
+    public Similarity get(String field) {
+      return this;
+    }
   }
 
   // Tests whether the DocumentWriter correctly enable the
@@ -251,7 +254,7 @@ public class TestOmitTf extends LuceneTe
         dir,
         newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer).
             setMaxBufferedDocs(2).
-            setSimilarity(new SimpleSimilarity()).
+            setSimilarityProvider(new SimpleSimilarity()).
             setMergePolicy(newLogMergePolicy(2))
     );
         
@@ -281,7 +284,7 @@ public class TestOmitTf extends LuceneTe
      * Verify the index
      */         
     IndexSearcher searcher = new IndexSearcher(dir, true);
-    searcher.setSimilarity(new SimpleSimilarity());
+    searcher.setSimilarityProvider(new SimpleSimilarity());
         
     Term a = new Term("noTf", term);
     Term b = new Term("tf", term);

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestParallelReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestParallelReader.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestParallelReader.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestParallelReader.java Mon Jan
24 19:13:31 2011
@@ -147,7 +147,8 @@ public class TestParallelReader extends 
     
     assertTrue(pr.isCurrent());
     IndexReader modifier = IndexReader.open(dir1, false);
-    modifier.setNorm(0, "f1", Similarity.getDefault().encodeNormValue(100f));
+    SimilarityProvider sim = new DefaultSimilarity();
+    modifier.setNorm(0, "f1", sim.get("f1").encodeNormValue(100f));
     modifier.close();
     
     // one of the two IndexReaders which ParallelReader is using
@@ -155,7 +156,7 @@ public class TestParallelReader extends 
     assertFalse(pr.isCurrent());
     
     modifier = IndexReader.open(dir2, false);
-    modifier.setNorm(0, "f3", Similarity.getDefault().encodeNormValue(100f));
+    modifier.setNorm(0, "f3", sim.get("f3").encodeNormValue(100f));
     modifier.close();
     
     // now both are not current anymore

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/JustCompileSearch.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/JustCompileSearch.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/JustCompileSearch.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/JustCompileSearch.java Mon Jan
24 19:13:31 2011
@@ -243,11 +243,6 @@ final class JustCompileSearch {
   static final class JustCompileSimilarity extends Similarity {
 
     @Override
-    public float coord(int overlap, int maxOverlap) {
-      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
-    }
-
-    @Override
     public float idf(int docFreq, int numDocs) {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
@@ -258,11 +253,6 @@ final class JustCompileSearch {
     }
 
     @Override
-    public float queryNorm(float sumOfSquaredWeights) {
-      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
-    }
-
-    @Override
     public float sloppyFreq(int distance) {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
@@ -270,8 +260,22 @@ final class JustCompileSearch {
     @Override
     public float tf(float freq) {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }  
+  }
+  
+  static final class JustCompileSimilarityProvider implements SimilarityProvider {
+
+    public float queryNorm(float sumOfSquaredWeights) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+    public float coord(int overlap, int maxOverlap) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
     
+    public Similarity get(String field) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
   }
 
   static final class JustCompileSpanFilter extends SpanFilter {

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/QueryUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/QueryUtils.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/QueryUtils.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/QueryUtils.java Mon Jan 24 19:13:31
2011
@@ -158,7 +158,7 @@ public class QueryUtils {
           0 < edge ? r : IndexReader.open(makeEmptyIndex(random, 0), true))
     };
     IndexSearcher out = new IndexSearcher(new MultiReader(readers));
-    out.setSimilarity(s.getSimilarity());
+    out.setSimilarityProvider(s.getSimilarityProvider());
     return out;
   }
 

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBoolean2.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBoolean2.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBoolean2.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBoolean2.java Mon Jan 24
19:13:31 2011
@@ -208,9 +208,9 @@ public class TestBoolean2 extends Lucene
   public void testQueries10() throws Exception {
     String queryText = "+w3 +xx +w2 zz";
     int[] expDocNrs = {2, 3};
-    Similarity oldSimilarity = searcher.getSimilarity();
+    SimilarityProvider oldSimilarity = searcher.getSimilarityProvider();
     try {
-      searcher.setSimilarity(new DefaultSimilarity(){
+      searcher.setSimilarityProvider(new DefaultSimilarity(){
         @Override
         public float coord(int overlap, int maxOverlap) {
           return overlap / ((float)maxOverlap - 1);
@@ -218,7 +218,7 @@ public class TestBoolean2 extends Lucene
       });
       queriesTest(queryText, expDocNrs);
     } finally {
-      searcher.setSimilarity(oldSimilarity);
+      searcher.setSimilarityProvider(oldSimilarity);
     }
   }
 

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestComplexExplanations.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestComplexExplanations.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestComplexExplanations.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestComplexExplanations.java
Mon Jan 24 19:13:31 2011
@@ -34,7 +34,7 @@ public class TestComplexExplanations ext
   @Override
   public void setUp() throws Exception {
     super.setUp();
-    searcher.setSimilarity(createQnorm1Similarity());
+    searcher.setSimilarityProvider(createQnorm1Similarity());
   }
 
   // must be static for weight serialization tests 

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestConstantScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestConstantScoreQuery.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestConstantScoreQuery.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestConstantScoreQuery.java
Mon Jan 24 19:13:31 2011
@@ -97,7 +97,7 @@ public class TestConstantScoreQuery exte
       searcher = new IndexSearcher(reader);
       
       // set a similarity that does not normalize our boost away
-      searcher.setSimilarity(new DefaultSimilarity() {
+      searcher.setSimilarityProvider(new DefaultSimilarity() {
         @Override
         public float queryNorm(float sumOfSquaredWeights) {
           return 1.0f;

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
Mon Jan 24 19:13:31 2011
@@ -73,7 +73,7 @@ public class TestDisjunctionMaxQuery ext
     }
   }
   
-  public Similarity sim = new TestSimilarity();
+  public SimilarityProvider sim = new TestSimilarity();
   public Directory index;
   public IndexReader r;
   public IndexSearcher s;
@@ -85,7 +85,7 @@ public class TestDisjunctionMaxQuery ext
     index = newDirectory();
     RandomIndexWriter writer = new RandomIndexWriter(random, index,
         newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer())
-            .setSimilarity(sim));
+            .setSimilarityProvider(sim));
     
     // hed is the most important field, dek is secondary
     
@@ -150,7 +150,7 @@ public class TestDisjunctionMaxQuery ext
     r = new SlowMultiReaderWrapper(writer.getReader());
     writer.close();
     s = new IndexSearcher(r);
-    s.setSimilarity(sim);
+    s.setSimilarityProvider(sim);
   }
   
   @Override

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java Mon
Jan 24 19:13:31 2011
@@ -69,7 +69,7 @@ public class TestMatchAllDocsQuery exten
     assertEquals("one", ir.document(hits[2].doc).get("key"));
 
     // change norm & retest
-    ir.setNorm(0, "key", Similarity.getDefault().encodeNormValue(400f));
+    ir.setNorm(0, "key", is.getSimilarityProvider().get("key").encodeNormValue(400f));
     normsQuery = new MatchAllDocsQuery("key");
     hits = is.search(normsQuery, null, 1000).scoreDocs;
     assertEquals(3, hits.length);

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java Mon
Jan 24 19:13:31 2011
@@ -295,7 +295,7 @@ public class TestMultiPhraseQuery extend
     
     IndexReader reader = writer.getReader();
     IndexSearcher searcher = new IndexSearcher(reader);
-    searcher.setSimilarity(new DefaultSimilarity() {
+    searcher.setSimilarityProvider(new DefaultSimilarity() {
       
       @Override
       public IDFExplanation idfExplain(Collection<Term> terms,

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSetNorm.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSetNorm.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSetNorm.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSetNorm.java Mon Jan 24
19:13:31 2011
@@ -51,10 +51,11 @@ public class TestSetNorm extends LuceneT
 
     // reset the boost of each instance of this document
     IndexReader reader = IndexReader.open(store, false);
-    reader.setNorm(0, "field", Similarity.getDefault().encodeNormValue(1.0f));
-    reader.setNorm(1, "field", Similarity.getDefault().encodeNormValue(2.0f));
-    reader.setNorm(2, "field", Similarity.getDefault().encodeNormValue(4.0f));
-    reader.setNorm(3, "field", Similarity.getDefault().encodeNormValue(16.0f));
+    Similarity similarity = new DefaultSimilarity().get("field");
+    reader.setNorm(0, "field", similarity.encodeNormValue(1.0f));
+    reader.setNorm(1, "field", similarity.encodeNormValue(2.0f));
+    reader.setNorm(2, "field", similarity.encodeNormValue(4.0f));
+    reader.setNorm(3, "field", similarity.encodeNormValue(16.0f));
     reader.close();
 
     // check that searches are ordered by this boost

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSimilarity.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSimilarity.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSimilarity.java Mon Jan
24 19:13:31 2011
@@ -39,13 +39,11 @@ import org.apache.lucene.search.Explanat
  */
 public class TestSimilarity extends LuceneTestCase {
   
-  public static class SimpleSimilarity extends Similarity {
+  public static class SimpleSimilarity extends Similarity implements SimilarityProvider {
     @Override public float computeNorm(String field, FieldInvertState state) { return state.getBoost();
}
-    @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, IndexSearcher
searcher) throws IOException {
       return new IDFExplanation() {
         @Override
@@ -58,13 +56,18 @@ public class TestSimilarity extends Luce
         }
       };
     }
+    public float queryNorm(float sumOfSquaredWeights) { return 1.0f; }
+    public float coord(int overlap, int maxOverlap) { return 1.0f; }
+    public Similarity get(String field) {
+      return this;
+    }
   }
 
   public void testSimilarity() throws Exception {
     Directory store = newDirectory();
     RandomIndexWriter writer = new RandomIndexWriter(random, store, 
         newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer())
-        .setSimilarity(new SimpleSimilarity()));
+        .setSimilarityProvider(new SimpleSimilarity()));
     
     Document d1 = new Document();
     d1.add(newField("field", "a c", Field.Store.YES, Field.Index.ANALYZED));
@@ -78,7 +81,7 @@ public class TestSimilarity extends Luce
     writer.close();
 
     IndexSearcher searcher = new IndexSearcher(reader);
-    searcher.setSimilarity(new SimpleSimilarity());
+    searcher.setSimilarityProvider(new SimpleSimilarity());
 
     Term a = new Term("field", "a");
     Term b = new Term("field", "b");

Added: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSimilarityProvider.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSimilarityProvider.java?rev=1062927&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSimilarityProvider.java
(added)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSimilarityProvider.java
Mon Jan 24 19:13:31 2011
@@ -0,0 +1,151 @@
+package org.apache.lucene.search;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.MockAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.index.FieldInvertState;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.MultiNorms;
+import org.apache.lucene.index.RandomIndexWriter;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestSimilarityProvider extends LuceneTestCase {
+  private Directory directory;
+  private IndexReader reader;
+  private IndexSearcher searcher;
+  
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+    directory = newDirectory();
+    SimilarityProvider sim = new ExampleSimilarityProvider();
+    IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, 
+        new MockAnalyzer()).setSimilarityProvider(sim);
+    RandomIndexWriter iw = new RandomIndexWriter(random, directory, iwc);
+    Document doc = new Document();
+    Field field = newField("foo", "", Field.Store.NO, Field.Index.ANALYZED);
+    doc.add(field);
+    Field field2 = newField("bar", "", Field.Store.NO, Field.Index.ANALYZED);
+    doc.add(field2);
+    
+    field.setValue("quick brown fox");
+    field2.setValue("quick brown fox");
+    iw.addDocument(doc);
+    field.setValue("jumps over lazy brown dog");
+    field2.setValue("jumps over lazy brown dog");
+    iw.addDocument(doc);
+    reader = iw.getReader();
+    iw.close();
+    searcher = new IndexSearcher(reader);
+    searcher.setSimilarityProvider(sim);
+  }
+  
+  @Override
+  public void tearDown() throws Exception {
+    searcher.close();
+    reader.close();
+    directory.close();
+    super.tearDown();
+  }
+  
+  public void testBasics() throws Exception {
+    // sanity check of norms writer
+    byte fooNorms[] = MultiNorms.norms(reader, "foo");
+    byte barNorms[] = MultiNorms.norms(reader, "bar");
+    for (int i = 0; i < fooNorms.length; i++) {
+      assertFalse(fooNorms[i] == barNorms[i]);
+    }
+    
+    // sanity check of searching
+    TopDocs foodocs = searcher.search(new TermQuery(new Term("foo", "brown")), 10);
+    assertTrue(foodocs.totalHits > 0);
+    TopDocs bardocs = searcher.search(new TermQuery(new Term("bar", "brown")), 10);
+    assertTrue(bardocs.totalHits > 0);
+    assertTrue(foodocs.scoreDocs[0].score < bardocs.scoreDocs[0].score);
+  }
+  
+  private class ExampleSimilarityProvider implements SimilarityProvider {
+    private Similarity sim1 = new Sim1();
+    private Similarity sim2 = new Sim2();
+    
+    public float coord(int overlap, int maxOverlap) {
+      return 1f;
+    }
+
+    public float queryNorm(float sumOfSquaredWeights) {
+      return 1f;
+    }
+
+    public Similarity get(String field) {
+      if (field.equals("foo")) {
+        return sim1;
+      } else {
+        return sim2;
+      }
+    }
+  }
+  
+  private class Sim1 extends Similarity {
+    @Override
+    public float computeNorm(String field, FieldInvertState state) {
+      return 1f;
+    }
+
+    @Override
+    public float sloppyFreq(int distance) {
+      return 1f;
+    }
+
+    @Override
+    public float tf(float freq) {
+      return 1f;
+    }
+
+    @Override
+    public float idf(int docFreq, int numDocs) {
+      return 1f;
+    }
+  }
+  
+  private class Sim2 extends Similarity {
+    @Override
+    public float computeNorm(String field, FieldInvertState state) {
+      return 10f;
+    }
+
+    @Override
+    public float sloppyFreq(int distance) {
+      return 10f;
+    }
+
+    @Override
+    public float tf(float freq) {
+      return 10f;
+    }
+
+    @Override
+    public float idf(int docFreq, int numDocs) {
+      return 10f;
+    }
+  }
+}

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java
Mon Jan 24 19:13:31 2011
@@ -27,7 +27,7 @@ import org.apache.lucene.document.Field;
 import org.apache.lucene.util.English;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Similarity;
+import org.apache.lucene.search.SimilarityProvider;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.MockDirectoryWrapper;
 import org.apache.lucene.store.RAMDirectory;
@@ -111,13 +111,13 @@ public class PayloadHelper {
    * @throws IOException
    */
   // TODO: randomize
-  public IndexSearcher setUp(Random random, Similarity similarity, int numDocs) throws IOException
{
+  public IndexSearcher setUp(Random random, SimilarityProvider similarity, int numDocs) throws
IOException {
     Directory directory = new MockDirectoryWrapper(random, new RAMDirectory());
     PayloadAnalyzer analyzer = new PayloadAnalyzer();
 
     // TODO randomize this
     IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(
-        TEST_VERSION_CURRENT, analyzer).setSimilarity(similarity));
+        TEST_VERSION_CURRENT, analyzer).setSimilarityProvider(similarity));
     // writer.infoStream = System.out;
     for (int i = 0; i < numDocs; i++) {
       Document doc = new Document();
@@ -130,7 +130,7 @@ public class PayloadHelper {
     writer.close();
 
     IndexSearcher searcher = new IndexSearcher(reader);
-    searcher.setSimilarity(similarity);
+    searcher.setSimilarityProvider(similarity);
     return searcher;
   }
 

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java
Mon Jan 24 19:13:31 2011
@@ -105,7 +105,7 @@ public class TestPayloadNearQuery extend
     directory = newDirectory();
     RandomIndexWriter writer = new RandomIndexWriter(random, directory, 
         newIndexWriterConfig(TEST_VERSION_CURRENT, new PayloadAnalyzer())
-        .setSimilarity(similarity));
+        .setSimilarityProvider(similarity));
     //writer.infoStream = System.out;
     for (int i = 0; i < 1000; i++) {
       Document doc = new Document();
@@ -118,7 +118,7 @@ public class TestPayloadNearQuery extend
     writer.close();
 
     searcher = new IndexSearcher(reader);
-    searcher.setSimilarity(similarity);
+    searcher.setSimilarityProvider(similarity);
   }
 
   @Override

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java
Mon Jan 24 19:13:31 2011
@@ -110,7 +110,7 @@ public class TestPayloadTermQuery extend
     directory = newDirectory();
     RandomIndexWriter writer = new RandomIndexWriter(random, directory, 
         newIndexWriterConfig(TEST_VERSION_CURRENT, new PayloadAnalyzer())
-        .setSimilarity(similarity));
+        .setSimilarityProvider(similarity));
     //writer.infoStream = System.out;
     for (int i = 0; i < 1000; i++) {
       Document doc = new Document();
@@ -125,7 +125,7 @@ public class TestPayloadTermQuery extend
     writer.close();
 
     searcher = new IndexSearcher(reader);
-    searcher.setSimilarity(similarity);
+    searcher.setSimilarityProvider(similarity);
   }
 
   @Override
@@ -220,7 +220,7 @@ public class TestPayloadTermQuery extend
             new MaxPayloadFunction(), false);
 
     IndexSearcher theSearcher = new IndexSearcher(directory, true);
-    theSearcher.setSimilarity(new FullSimilarity());
+    theSearcher.setSimilarityProvider(new FullSimilarity());
     TopDocs hits = searcher.search(query, null, 100);
     assertTrue("hits is null and it shouldn't be", hits != null);
     assertTrue("hits Size: " + hits.totalHits + " is not: " + 100, hits.totalHits == 100);

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java
Mon Jan 24 19:13:31 2011
@@ -39,7 +39,7 @@ import org.apache.lucene.index.Payload;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.DefaultSimilarity;
 import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Similarity;
+import org.apache.lucene.search.SimilarityProvider;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.TopDocs;
 import org.apache.lucene.search.payloads.PayloadHelper;
@@ -50,7 +50,7 @@ import org.apache.lucene.util.LuceneTest
 
 public class TestPayloadSpans extends LuceneTestCase {
   private IndexSearcher searcher;
-  private Similarity similarity = new DefaultSimilarity();
+  private SimilarityProvider similarity = new DefaultSimilarity();
   protected IndexReader indexReader;
   private IndexReader closeIndexReader;
   private Directory directory;
@@ -110,7 +110,7 @@ public class TestPayloadSpans extends Lu
 
     Directory directory = newDirectory();
     RandomIndexWriter writer = new RandomIndexWriter(random, directory,
-                                                     newIndexWriterConfig(TEST_VERSION_CURRENT,
new PayloadAnalyzer()).setSimilarity(similarity));
+                                                     newIndexWriterConfig(TEST_VERSION_CURRENT,
new PayloadAnalyzer()).setSimilarityProvider(similarity));
 
     Document doc = new Document();
     doc.add(newField(PayloadHelper.FIELD, "one two three one four three",
@@ -370,7 +370,7 @@ public class TestPayloadSpans extends Lu
   public void testPayloadSpanUtil() throws Exception {
     Directory directory = newDirectory();
     RandomIndexWriter writer = new RandomIndexWriter(random, directory,
-                                                     newIndexWriterConfig(TEST_VERSION_CURRENT,
new PayloadAnalyzer()).setSimilarity(similarity));
+                                                     newIndexWriterConfig(TEST_VERSION_CURRENT,
new PayloadAnalyzer()).setSimilarityProvider(similarity));
 
     Document doc = new Document();
     doc.add(newField(PayloadHelper.FIELD,"xx rr yy mm  pp", Field.Store.YES, Field.Index.ANALYZED));
@@ -430,7 +430,7 @@ public class TestPayloadSpans extends Lu
     directory = newDirectory();
     String[] docs = new String[]{"xx rr yy mm  pp","xx yy mm rr pp", "nopayload qq ss pp
np", "one two three four five six seven eight nine ten eleven", "nine one two three four five
six seven eight eleven ten"};
     RandomIndexWriter writer = new RandomIndexWriter(random, directory,
-                                                     newIndexWriterConfig(TEST_VERSION_CURRENT,
new PayloadAnalyzer()).setSimilarity(similarity));
+                                                     newIndexWriterConfig(TEST_VERSION_CURRENT,
new PayloadAnalyzer()).setSimilarityProvider(similarity));
 
     Document doc = null;
     for(int i = 0; i < docs.length; i++) {

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java Mon Jan
24 19:13:31 2011
@@ -20,9 +20,9 @@ package org.apache.lucene.search.spans;
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.CheckHits;
-import org.apache.lucene.search.Similarity;
 import org.apache.lucene.search.DefaultSimilarity;
 import org.apache.lucene.search.Scorer;
+import org.apache.lucene.search.SimilarityProvider;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Weight.ScorerContext;
@@ -410,17 +410,17 @@ public class TestSpans extends LuceneTes
     for (int i = 0; i < leaves.length; i++) {
       
      
-      final Similarity sim = new DefaultSimilarity() {
+      final SimilarityProvider sim = new DefaultSimilarity() {
         @Override
         public float sloppyFreq(int distance) {
           return 0.0f;
         }
       };
   
-      final Similarity oldSim = searcher.getSimilarity();
+      final SimilarityProvider oldSim = searcher.getSimilarityProvider();
       Scorer spanScorer;
       try {
-        searcher.setSimilarity(sim);
+        searcher.setSimilarityProvider(sim);
         SpanNearQuery snq = new SpanNearQuery(
                                 new SpanQuery[] {
                                   makeSpanTermQuery("t1"),
@@ -430,7 +430,7 @@ public class TestSpans extends LuceneTes
   
         spanScorer = snq.weight(searcher).scorer(leaves[i], ScorerContext.def());
       } finally {
-        searcher.setSimilarity(oldSim);
+        searcher.setSimilarityProvider(oldSim);
       }
       if (i == subIndex) {
         assertTrue("first doc", spanScorer.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/schema/IndexSchema.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/schema/IndexSchema.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/schema/IndexSchema.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/schema/IndexSchema.java Mon Jan 24 19:13:31
2011
@@ -20,7 +20,8 @@ package org.apache.solr.schema;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.document.Fieldable;
-import org.apache.lucene.search.Similarity;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.SimilarityProvider;
 import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.util.Version;
 import org.apache.solr.common.ResourceLoader;
@@ -192,7 +193,7 @@ public final class IndexSchema {
   /**
    * Returns the Similarity used for this index
    */
-  public Similarity getSimilarity() { return similarityFactory.getSimilarity(); }
+  public SimilarityProvider getSimilarityProvider() { return similarityFactory.getSimilarityProvider();
}
 
   /**
    * Returns the SimilarityFactory used for this index
@@ -496,8 +497,8 @@ public final class IndexSchema {
     Node node = (Node) xpath.evaluate("/schema/similarity", document, XPathConstants.NODE);
     if (node==null) {
       similarityFactory = new SimilarityFactory() {
-        public Similarity getSimilarity() {
-          return Similarity.getDefault();
+        public SimilarityProvider getSimilarityProvider() {
+          return IndexSearcher.getDefaultSimilarityProvider();
         }
       };
       log.debug("using default similarity");
@@ -509,10 +510,10 @@ public final class IndexSchema {
         similarityFactory = (SimilarityFactory)obj;
         similarityFactory.init(params);
       } else {
-        // just like always, assume it's a Similarlity and get a ClassCastException - reasonable
error handling
+        // just like always, assume it's a SimilarityProvider and get a ClassCastException
- reasonable error handling
         similarityFactory = new SimilarityFactory() {
-          public Similarity getSimilarity() {
-            return (Similarity) obj;
+          public SimilarityProvider getSimilarityProvider() {
+            return (SimilarityProvider) obj;
           }
         };
       }

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SimilarityFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SimilarityFactory.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SimilarityFactory.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SimilarityFactory.java Mon Jan 24
19:13:31 2011
@@ -16,7 +16,7 @@ package org.apache.solr.schema;
  * limitations under the License.
  */
 
-import org.apache.lucene.search.Similarity;
+import org.apache.lucene.search.SimilarityProvider;
 import org.apache.solr.common.params.SolrParams;
 
 public abstract class SimilarityFactory {
@@ -25,5 +25,5 @@ public abstract class SimilarityFactory 
   public void init(SolrParams params) { this.params = params; }
   public SolrParams getParams() { return params; }
 
-  public abstract Similarity getSimilarity();
+  public abstract SimilarityProvider getSimilarityProvider();
 }

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrConstantScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrConstantScoreQuery.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrConstantScoreQuery.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrConstantScoreQuery.java Mon
Jan 24 19:13:31 2011
@@ -55,13 +55,11 @@ public class SolrConstantScoreQuery exte
   }
 
   protected class ConstantWeight extends Weight {
-    private Similarity similarity;
     private float queryNorm;
     private float queryWeight;
     private Map context;
 
     public ConstantWeight(IndexSearcher searcher) throws IOException {
-      this.similarity = searcher.getSimilarity();
       this.context = ValueSource.newContext(searcher);
       if (filter instanceof SolrFilter)
         ((SolrFilter)filter).createWeight(context, searcher);

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java Mon Jan 24
19:13:31 2011
@@ -132,7 +132,7 @@ public class SolrIndexSearcher extends I
     }
 
     this.closeReader = closeReader;
-    setSimilarity(schema.getSimilarity());
+    setSimilarityProvider(schema.getSimilarityProvider());
 
     SolrConfig solrConfig = core.getSolrConfig();
     queryResultWindowSize = solrConfig.queryResultWindowSize;

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/IDFValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/IDFValueSource.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/IDFValueSource.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/IDFValueSource.java Mon
Jan 24 19:13:31 2011
@@ -41,7 +41,7 @@ public class IDFValueSource extends DocF
   @Override
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException
{
     IndexSearcher searcher = (IndexSearcher)context.get("searcher");
-    Similarity sim = searcher.getSimilarity();
+    Similarity sim = searcher.getSimilarityProvider().get(field);
     // todo: we need docFreq that takes a BytesRef
     String strVal = ByteUtils.UTF8toUTF16(indexedBytes);
     int docfreq = searcher.docFreq(new Term(indexedField, strVal));

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/NormValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/NormValueSource.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/NormValueSource.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/NormValueSource.java Mon
Jan 24 19:13:31 2011
@@ -46,7 +46,7 @@ public class NormValueSource extends Val
   @Override
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException
{
     IndexSearcher searcher = (IndexSearcher)context.get("searcher");
-    final Similarity similarity = searcher.getSimilarity();
+    final Similarity similarity = searcher.getSimilarityProvider().get(field);
     final byte[] norms = readerContext.reader.norms(field);
     if (norms == null) {
       return new ConstDoubleDocValues(0.0, this);

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/TFValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/TFValueSource.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/TFValueSource.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/TFValueSource.java Mon
Jan 24 19:13:31 2011
@@ -25,7 +25,7 @@ public class TFValueSource extends TermF
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException
{
     Fields fields = readerContext.reader.fields();
     final Terms terms = fields.terms(field);
-    final Similarity similarity = ((IndexSearcher)context.get("searcher")).getSimilarity();
+    final Similarity similarity = ((IndexSearcher)context.get("searcher")).getSimilarityProvider().get(field);
 
     return new FloatDocValues(this) {
       DocsEnum docs ;

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/update/SolrIndexConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/update/SolrIndexConfig.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/update/SolrIndexConfig.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/update/SolrIndexConfig.java Mon Jan 24
19:13:31 2011
@@ -153,7 +153,7 @@ public class SolrIndexConfig {
     if (writeLockTimeout != -1)
       iwc.setWriteLockTimeout(writeLockTimeout);
 
-    iwc.setSimilarity(schema.getSimilarity());
+    iwc.setSimilarityProvider(schema.getSimilarityProvider());
     iwc.setMergePolicy(buildMergePolicy(schema));
     iwc.setMergeScheduler(buildMergeScheduler(schema));
 

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/schema/CustomSimilarityFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/schema/CustomSimilarityFactory.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/schema/CustomSimilarityFactory.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/schema/CustomSimilarityFactory.java Mon
Jan 24 19:13:31 2011
@@ -16,10 +16,10 @@
  */
 package org.apache.solr.schema;
 
-import org.apache.lucene.search.Similarity;
+import org.apache.lucene.search.SimilarityProvider;
 
 public class CustomSimilarityFactory extends SimilarityFactory {
-  public Similarity getSimilarity() {
+  public SimilarityProvider getSimilarityProvider() {
     return new MockConfigurableSimilarity(params.get("echo"));
   }
 }

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/schema/IndexSchemaTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/schema/IndexSchemaTest.java?rev=1062927&r1=1062926&r2=1062927&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/schema/IndexSchemaTest.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/schema/IndexSchemaTest.java Mon Jan 24
19:13:31 2011
@@ -27,7 +27,7 @@ import org.apache.solr.common.params.Map
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.request.LocalSolrQueryRequest;
 import org.apache.solr.request.SolrQueryRequest;
-import org.apache.lucene.search.Similarity;
+import org.apache.lucene.search.SimilarityProvider;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -83,7 +83,7 @@ public class IndexSchemaTest extends Sol
   @Test
   public void testSimilarityFactory() {
     SolrCore core = h.getCore();
-    Similarity similarity = core.getSchema().getSimilarity();
+    SimilarityProvider similarity = core.getSchema().getSimilarityProvider();
     assertTrue("wrong class", similarity instanceof MockConfigurableSimilarity);
     assertEquals("is there an echo?", ((MockConfigurableSimilarity)similarity).getPassthrough());
   }



Mime
View raw message