lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1241001 [1/3] - in /lucene/dev/trunk: lucene/ lucene/contrib/ lucene/contrib/memory/src/java/org/apache/lucene/index/memory/ lucene/contrib/misc/src/test/org/apache/lucene/misc/ lucene/src/java/org/apache/lucene/index/ lucene/src/java/org/...
Date Mon, 06 Feb 2012 12:48:04 GMT
Author: rmuir
Date: Mon Feb  6 12:48:01 2012
New Revision: 1241001

URL: http://svn.apache.org/viewvc?rev=1241001&view=rev
Log:
LUCENE-3749: replace SimilarityProvider with PerFieldSimilarityWrapper

Added:
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/PerFieldSimilarityWrapper.java   (with props)
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/similarities/SchemaSimilarityFactory.java   (with props)
    lucene/dev/trunk/solr/core/src/test-files/solr/conf/schema-sim.xml   (with props)
Removed:
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/BasicSimilarityProvider.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/DefaultSimilarityProvider.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/SimilarityProvider.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/SimilarityProviderFactory.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SolrSimilarityProvider.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/similarities/BasicSimilarityProviderFactory.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/similarities/CustomSimilarityProviderFactory.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/similarities/MockConfigurableSimilarityProvider.java
Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/MIGRATE.txt
    lucene/dev/trunk/lucene/contrib/CHANGES.txt
    lucene/dev/trunk/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
    lucene/dev/trunk/lucene/contrib/misc/src/test/org/apache/lucene/misc/SweetSpotSimilarityTest.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocInverter.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocInverterPerField.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocumentsWriter.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/FieldInvertState.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriterConfig.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/NormsConsumerPerField.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/BooleanQuery.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/IndexSearcher.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/PhraseQuery.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/SearcherFactory.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/TermQuery.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/Weight.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/DefaultSimilarity.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/Similarity.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/TFIDFSimilarity.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/package.html
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/spans/SpanWeight.java
    lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/index/DocHelper.java
    lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/search/QueryUtils.java
    lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/search/RandomSimilarityProvider.java
    lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestCustomNorms.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestMaxTermFrequency.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestNorms.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestOmitTf.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestUniqueTermCount.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/JustCompileSearch.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBoolean2.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBooleanQuery.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestComplexExplanations.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestConstantScoreQuery.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestDocValuesScoring.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestElevationComparator.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery2.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestPhraseQuery.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSimilarity.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSimilarityProvider.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestTermScorer.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestTermVectors.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadExplanations.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/similarities/TestSimilarity2.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/similarities/TestSimilarityBase.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestFieldMaskingSpanQuery.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestSpansAdvanced.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestSpansAdvanced2.java
    lucene/dev/trunk/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/IDFValueSource.java
    lucene/dev/trunk/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NormValueSource.java
    lucene/dev/trunk/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/TFValueSource.java
    lucene/dev/trunk/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/StandardBooleanQueryNodeBuilder.java
    lucene/dev/trunk/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/StandardBooleanQueryNode.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/FieldType.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java
    lucene/dev/trunk/solr/core/src/test-files/solr/conf/schema-bm25.xml
    lucene/dev/trunk/solr/core/src/test-files/solr/conf/schema-dfr.xml
    lucene/dev/trunk/solr/core/src/test-files/solr/conf/schema-ib.xml
    lucene/dev/trunk/solr/core/src/test-files/solr/conf/schema-lmdirichlet.xml
    lucene/dev/trunk/solr/core/src/test-files/solr/conf/schema-lmjelinekmercer.xml
    lucene/dev/trunk/solr/core/src/test-files/solr/conf/schema.xml
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/schema/IndexSchemaTest.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/similarities/BaseSimilarityTestCase.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/similarities/TestPerFieldSimilarity.java
    lucene/dev/trunk/solr/solrj/src/test-files/solrj/solr/conf/schema.xml

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Mon Feb  6 12:48:01 2012
@@ -216,7 +216,7 @@ Changes in backwards compatibility polic
   and clone() no longer take readOnly booleans or IndexDeletionPolicy
   instances. Furthermore, IndexReader.setNorm() was removed. If you need
   customized norm values, the recommended way to do this is by modifying
-  SimilarityProvider to use an external byte[] or one of the new DocValues
+  Similarity to use an external byte[] or one of the new DocValues
   fields (LUCENE-3108). Alternatively, to dynamically change norms (boost
   *and* length norm) at query time, wrap your IndexReader using
   FilterIndexReader, overriding FilterIndexReader.norms(). To persist the
@@ -583,16 +583,12 @@ New features
     for plugging in new ranking algorithms without dealing with all of the
     nuances and implementation details of Lucene. 
 
-  - Added a new helper class BasicSimilarityProvider that just applies one
-    scoring algorithm to all fields, with queryNorm() and coord() returning 1.
-    In general, it is recommended to disable coord() when using the new models.
-    For example, to use BM25 for all fields: 
-     searcher.setSimilarityProvider(
-        new BasicSimilarityProvider(new BM25Similarity()));
+  - For example, to use BM25 for all fields: 
+     searcher.setSimilarity(new BM25Similarity());
 
     If you instead want to apply different similarities (e.g. ones with 
     different parameter values or different algorithms entirely) to different
-    fields, implement SimilarityProvider with your per-field logic.
+    fields, implement PerFieldSimilarityWrapper with your per-field logic.
 
   (David Mark Nemeskey via Robert Muir)
 
@@ -774,7 +770,7 @@ API Changes
   query time, wrap your IndexReader using FilterIndexReader, overriding
   FilterIndexReader.norms(). To persist the changes on disk, copy the
   FilteredIndexReader to a new index using IndexWriter.addIndexes().
-  In Lucene 4.0, SimilarityProvider will allow you to customize scoring
+  In Lucene 4.0, Similarity will allow you to customize scoring
   using external norms, too.  (Uwe Schindler, Robert Muir)
 
 * LUCENE-3735: PayloadProcessorProvider was changed to return a

Modified: lucene/dev/trunk/lucene/MIGRATE.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/MIGRATE.txt?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/MIGRATE.txt (original)
+++ lucene/dev/trunk/lucene/MIGRATE.txt Mon Feb  6 12:48:01 2012
@@ -351,13 +351,9 @@ LUCENE-1458, LUCENE-2111: Flexible Index
 
 * LUCENE-2236, LUCENE-2912: DefaultSimilarity can no longer be set statically 
   (and dangerously) for the entire JVM.
-  Instead, IndexWriterConfig and IndexSearcher now take a SimilarityProvider.
-  Similarity can now be configured on a per-field basis.
-  Similarity retains only the field-specific relevance methods such as tf() and idf().
-  Previously some (but not all) of these methods, such as computeNorm and scorePayload took 
-  field as a parameter, this is removed due to the fact the entire Similarity (all methods)
-  can now be configured per-field.
-  Methods that apply to the entire query such as coord() and queryNorm() exist in SimilarityProvider.
+  Similarity can now be configured on a per-field basis (via PerFieldSimilarityWrapper)
+  Similarity has a lower-level API, if you want the higher-level vector-space API
+  like in previous Lucene releases, then look at TFIDFSimilarity.
 
 * LUCENE-1076: TieredMergePolicy is now the default merge policy.
   It's able to merge non-contiguous segments; this may cause problems

Modified: lucene/dev/trunk/lucene/contrib/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/CHANGES.txt?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/contrib/CHANGES.txt Mon Feb  6 12:48:01 2012
@@ -81,7 +81,7 @@ API Changes
    for API use. (Andrzej Bialecki)
 
  * LUCENE-2912: The field-specific hashmaps in SweetSpotSimilarity were removed.
-   Instead, use SimilarityProvider to return different SweetSpotSimilaritys
+   Instead, use PerFieldSimilarityWrapper to return different SweetSpotSimilaritys
    for different fields, this way all parameters (such as TF factors) can be 
    customized on a per-field basis.  (Robert Muir)
 

Modified: lucene/dev/trunk/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java (original)
+++ lucene/dev/trunk/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java Mon Feb  6 12:48:01 2012
@@ -56,7 +56,6 @@ import org.apache.lucene.search.IndexSea
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.similarities.Similarity;
-import org.apache.lucene.search.similarities.SimilarityProvider;
 import org.apache.lucene.store.RAMDirectory; // for javadocs
 import org.apache.lucene.util.ArrayUtil;
 import org.apache.lucene.util.Bits;
@@ -1085,9 +1084,9 @@ public class MemoryIndex {
       }
     }
 
-    private SimilarityProvider getSimilarityProvider() {
-      if (searcher != null) return searcher.getSimilarityProvider();
-      return IndexSearcher.getDefaultSimilarityProvider();
+    private Similarity getSimilarity() {
+      if (searcher != null) return searcher.getSimilarity();
+      return IndexSearcher.getDefaultSimilarity();
     }
     
     private void setSearcher(IndexSearcher searcher) {
@@ -1131,21 +1130,20 @@ public class MemoryIndex {
     /** performance hack: cache norms to avoid repeated expensive calculations */
     private DocValues cachedNormValues;
     private String cachedFieldName;
-    private SimilarityProvider cachedSimilarity;
+    private Similarity cachedSimilarity;
     
     @Override
     public DocValues normValues(String field) throws IOException {
       DocValues norms = cachedNormValues;
-      SimilarityProvider sim = getSimilarityProvider();
+      Similarity sim = getSimilarity();
       if (!field.equals(cachedFieldName) || sim != cachedSimilarity) { // not cached?
         Info info = getInfo(field);
-        Similarity fieldSim = sim.get(field);
         int numTokens = info != null ? info.numTokens : 0;
         int numOverlapTokens = info != null ? info.numOverlapTokens : 0;
         float boost = info != null ? info.getBoost() : 1.0f; 
-        FieldInvertState invertState = new FieldInvertState(0, numTokens, numOverlapTokens, 0, boost);
+        FieldInvertState invertState = new FieldInvertState(field, 0, numTokens, numOverlapTokens, 0, boost);
         Norm norm = new Norm();
-        fieldSim.computeNorm(invertState, norm);
+        sim.computeNorm(invertState, norm);
         SingleValueSource singleByteSource = new SingleValueSource(norm);
         norms = new MemoryIndexNormDocValues(singleByteSource);
         // cache it for future reuse

Modified: lucene/dev/trunk/lucene/contrib/misc/src/test/org/apache/lucene/misc/SweetSpotSimilarityTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/misc/src/test/org/apache/lucene/misc/SweetSpotSimilarityTest.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/misc/src/test/org/apache/lucene/misc/SweetSpotSimilarityTest.java (original)
+++ lucene/dev/trunk/lucene/contrib/misc/src/test/org/apache/lucene/misc/SweetSpotSimilarityTest.java Mon Feb  6 12:48:01 2012
@@ -19,9 +19,8 @@
 package org.apache.lucene.misc;
 
 import org.apache.lucene.search.similarities.DefaultSimilarity;
-import org.apache.lucene.search.similarities.DefaultSimilarityProvider;
+import org.apache.lucene.search.similarities.PerFieldSimilarityWrapper;
 import org.apache.lucene.search.similarities.Similarity;
-import org.apache.lucene.search.similarities.SimilarityProvider;
 import org.apache.lucene.search.similarities.TFIDFSimilarity;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.index.Norm;
@@ -53,7 +52,7 @@ public class SweetSpotSimilarityTest ext
 
 
     // base case, should degrade
-    final FieldInvertState invertState = new FieldInvertState();
+    FieldInvertState invertState = new FieldInvertState("bogus");
     invertState.setBoost(1.0f);
     for (int i = 1; i < 1000; i++) {
       invertState.setLength(i);
@@ -102,7 +101,8 @@ public class SweetSpotSimilarityTest ext
     final SweetSpotSimilarity ssB = new SweetSpotSimilarity();
     ssB.setLengthNormFactors(5,8,0.1f, false);
     
-    SimilarityProvider sp = new DefaultSimilarityProvider() {
+    Similarity sp = new PerFieldSimilarityWrapper() {
+      @Override
       public Similarity get(String field) {
         if (field.equals("bar"))
           return ssBar;
@@ -116,53 +116,68 @@ public class SweetSpotSimilarityTest ext
           return ss;
       }
     };
-  
+
+    invertState = new FieldInvertState("foo");
+    invertState.setBoost(1.0f);
     for (int i = 3; i <=10; i++) {
       invertState.setLength(i);
       assertEquals("f: 3,10: spot i="+i,
                    1.0f,
-                   computeAndDecodeNorm(ss, sp.get("foo"), invertState),
+                   computeAndDecodeNorm(ss, sp, invertState),
                    0.0f);
     }
+    
     for (int i = 10; i < 1000; i++) {
       invertState.setLength(i-9);
       final byte normD = computeAndGetNorm(d, invertState);
       invertState.setLength(i);
-      final byte normS = computeAndGetNorm(sp.get("foo"), invertState);
+      final byte normS = computeAndGetNorm(sp, invertState);
       assertEquals("f: 3,10: 10<x : i="+i,
                    normD,
                    normS,
                    0.0f);
     }
+    
+    invertState = new FieldInvertState("bar");
+    invertState.setBoost(1.0f);
     for (int i = 8; i <=13; i++) {
       invertState.setLength(i);
       assertEquals("f: 8,13: spot i="+i,
                    1.0f,
-                   computeAndDecodeNorm(ss, sp.get("bar"), invertState),
+                   computeAndDecodeNorm(ss, sp, invertState),
                    0.0f);
     }
+    
+    invertState = new FieldInvertState("yak");
+    invertState.setBoost(1.0f);
     for (int i = 6; i <=9; i++) {
       invertState.setLength(i);
       assertEquals("f: 6,9: spot i="+i,
                    1.0f,
-                   computeAndDecodeNorm(ss, sp.get("yak"), invertState),
+                   computeAndDecodeNorm(ss, sp, invertState),
                    0.0f);
     }
+    
+    invertState = new FieldInvertState("bar");
+    invertState.setBoost(1.0f);
     for (int i = 13; i < 1000; i++) {
       invertState.setLength(i-12);
       final byte normD = computeAndGetNorm(d, invertState);
       invertState.setLength(i);
-      final byte normS = computeAndGetNorm(sp.get("bar"), invertState);
+      final byte normS = computeAndGetNorm(sp, invertState);
       assertEquals("f: 8,13: 13<x : i="+i,
                    normD,
                    normS,
                    0.0f);
     }
+    
+    invertState = new FieldInvertState("yak");
+    invertState.setBoost(1.0f);
     for (int i = 9; i < 1000; i++) {
       invertState.setLength(i-8);
       final byte normD = computeAndGetNorm(d, invertState);
       invertState.setLength(i);
-      final byte normS = computeAndGetNorm(sp.get("yak"), invertState);
+      final byte normS = computeAndGetNorm(sp, invertState);
       assertEquals("f: 6,9: 9<x : i="+i,
                    normD,
                    normS,
@@ -173,9 +188,14 @@ public class SweetSpotSimilarityTest ext
     // steepness
 
     for (int i = 9; i < 1000; i++) {
+      invertState = new FieldInvertState("a");
+      invertState.setBoost(1.0f);
+      invertState.setLength(i);
+      final byte normSS = computeAndGetNorm(sp, invertState);
+      invertState = new FieldInvertState("b");
+      invertState.setBoost(1.0f);
       invertState.setLength(i);
-      final byte normSS = computeAndGetNorm(sp.get("a"), invertState);
-      final byte normS = computeAndGetNorm(sp.get("b"), invertState);
+      final byte normS = computeAndGetNorm(sp, invertState);
       assertTrue("s: i="+i+" : a="+normSS+
                  " < b="+normS,
                  normSS < normS);

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocInverter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocInverter.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocInverter.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocInverter.java Mon Feb  6 12:48:01 2012
@@ -37,8 +37,6 @@ final class DocInverter extends DocField
 
   final DocumentsWriterPerThread.DocState docState;
 
-  final FieldInvertState fieldState = new FieldInvertState();
-
   final SingleTokenAttributeSource singleToken = new SingleTokenAttributeSource();
 
   static class SingleTokenAttributeSource extends AttributeSource {

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocInverterPerField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocInverterPerField.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocInverterPerField.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocInverterPerField.java Mon Feb  6 12:48:01 2012
@@ -42,7 +42,7 @@ final class DocInverterPerField extends 
   public DocInverterPerField(DocInverter parent, FieldInfo fieldInfo) {
     this.fieldInfo = fieldInfo;
     docState = parent.docState;
-    fieldState = parent.fieldState;
+    fieldState = new FieldInvertState(fieldInfo.name);
     this.consumer = parent.consumer.addField(this, fieldInfo);
     this.endConsumer = parent.endConsumer.addField(this, fieldInfo);
   }

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocumentsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocumentsWriter.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocumentsWriter.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocumentsWriter.java Mon Feb  6 12:48:01 2012
@@ -31,7 +31,7 @@ import org.apache.lucene.index.Documents
 import org.apache.lucene.index.DocumentsWriterPerThreadPool.ThreadState;
 import org.apache.lucene.index.FieldInfos.FieldNumberBiMap;
 import org.apache.lucene.search.Query;
-import org.apache.lucene.search.similarities.SimilarityProvider;
+import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.store.AlreadyClosedException;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.InfoStream;
@@ -106,7 +106,7 @@ final class DocumentsWriter {
   private volatile boolean closed;
 
   final InfoStream infoStream;
-  SimilarityProvider similarityProvider;
+  Similarity similarity;
 
   List<String> newFiles;
 
@@ -140,7 +140,7 @@ final class DocumentsWriter {
     this.directory = directory;
     this.indexWriter = writer;
     this.infoStream = config.getInfoStream();
-    this.similarityProvider = config.getSimilarityProvider();
+    this.similarity = config.getSimilarity();
     this.perThreadPool = config.getIndexerThreadPool();
     this.chain = config.getIndexingChain();
     this.perThreadPool.initialize(this, globalFieldNumbers, config);

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java Mon Feb  6 12:48:01 2012
@@ -26,7 +26,7 @@ import java.text.NumberFormat;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.codecs.Codec;
 import org.apache.lucene.index.DocumentsWriterDeleteQueue.DeleteSlice;
-import org.apache.lucene.search.similarities.SimilarityProvider;
+import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.FlushInfo;
 import org.apache.lucene.store.IOContext;
@@ -88,7 +88,7 @@ public class DocumentsWriterPerThread {
     final DocumentsWriterPerThread docWriter;
     Analyzer analyzer;
     InfoStream infoStream;
-    SimilarityProvider similarityProvider;
+    Similarity similarity;
     int docID;
     Iterable<? extends IndexableField> doc;
     String maxTermPrefix;
@@ -188,8 +188,7 @@ public class DocumentsWriterPerThread {
     this.infoStream = parent.infoStream;
     this.codec = parent.codec;
     this.docState = new DocState(this, infoStream);
-    this.docState.similarityProvider = parent.indexWriter.getConfig()
-        .getSimilarityProvider();
+    this.docState.similarity = parent.indexWriter.getConfig().getSimilarity();
     bytesUsed = Counter.newCounter();
     byteBlockAllocator = new DirectTrackingAllocator(bytesUsed);
     consumer = indexingChain.getChain(this);

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/FieldInvertState.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/FieldInvertState.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/FieldInvertState.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/FieldInvertState.java Mon Feb  6 12:48:01 2012
@@ -26,6 +26,7 @@ import org.apache.lucene.util.AttributeS
  * @lucene.experimental
  */
 public final class FieldInvertState {
+  String name;
   int position;
   int length;
   int numOverlap;
@@ -35,10 +36,12 @@ public final class FieldInvertState {
   float boost;
   AttributeSource attributeSource;
 
-  public FieldInvertState() {
+  public FieldInvertState(String name) {
+    this.name = name;
   }
-
-  public FieldInvertState(int position, int length, int numOverlap, int offset, float boost) {
+  
+  public FieldInvertState(String name, int position, int length, int numOverlap, int offset, float boost) {
+    this.name = name;
     this.position = position;
     this.length = length;
     this.numOverlap = numOverlap;
@@ -134,4 +137,11 @@ public final class FieldInvertState {
   public AttributeSource getAttributeSource() {
     return attributeSource;
   }
+  
+  /**
+   * Return the field's name
+   */
+  public String getName() {
+    return name;
+  }
 }

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriterConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriterConfig.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriterConfig.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriterConfig.java Mon Feb  6 12:48:01 2012
@@ -24,7 +24,7 @@ import org.apache.lucene.codecs.Codec;
 import org.apache.lucene.index.DocumentsWriterPerThread.IndexingChain;
 import org.apache.lucene.index.IndexWriter.IndexReaderWarmer;
 import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.similarities.SimilarityProvider;
+import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.util.InfoStream;
 import org.apache.lucene.util.PrintStreamInfoStream;
 import org.apache.lucene.util.Version;
@@ -116,7 +116,7 @@ public final class IndexWriterConfig imp
   private volatile IndexDeletionPolicy delPolicy;
   private volatile IndexCommit commit;
   private volatile OpenMode openMode;
-  private volatile SimilarityProvider similarityProvider;
+  private volatile Similarity similarity;
   private volatile int termIndexInterval; // TODO: this should be private to the codec, not settable here
   private volatile MergeScheduler mergeScheduler;
   private volatile long writeLockTimeout;
@@ -154,7 +154,7 @@ public final class IndexWriterConfig imp
     delPolicy = new KeepOnlyLastCommitDeletionPolicy();
     commit = null;
     openMode = OpenMode.CREATE_OR_APPEND;
-    similarityProvider = IndexSearcher.getDefaultSimilarityProvider();
+    similarity = IndexSearcher.getDefaultSimilarity();
     termIndexInterval = DEFAULT_TERM_INDEX_INTERVAL; // TODO: this should be private to the codec, not settable here
     mergeScheduler = new ConcurrentMergeScheduler();
     writeLockTimeout = WRITE_LOCK_TIMEOUT;
@@ -258,23 +258,23 @@ public final class IndexWriterConfig imp
   }
 
   /**
-   * Expert: set the {@link SimilarityProvider} implementation used by this IndexWriter.
+   * Expert: set the {@link Similarity} implementation used by this IndexWriter.
    * <p>
-   * <b>NOTE:</b> the similarity provider cannot be null. If <code>null</code> is passed,
-   * the similarity provider will be set to the default implementation (unspecified).
+   * <b>NOTE:</b> the similarity cannot be null. If <code>null</code> is passed,
+   * the similarity will be set to the default implementation (unspecified).
    *
    * <p>Only takes effect when IndexWriter is first created. */
-  public IndexWriterConfig setSimilarityProvider(SimilarityProvider similarityProvider) {
-    this.similarityProvider = similarityProvider == null ? IndexSearcher.getDefaultSimilarityProvider() : similarityProvider;
+  public IndexWriterConfig setSimilarity(Similarity similarity) {
+    this.similarity = similarity == null ? IndexSearcher.getDefaultSimilarity() : similarity;
     return this;
   }
 
   /**
-   * Expert: returns the {@link SimilarityProvider} implementation used by this
+   * Expert: returns the {@link Similarity} implementation used by this
    * IndexWriter.
    */
-  public SimilarityProvider getSimilarityProvider() {
-    return similarityProvider;
+  public Similarity getSimilarity() {
+    return similarity;
   }
 
   /**
@@ -718,7 +718,7 @@ public final class IndexWriterConfig imp
     sb.append("delPolicy=").append(delPolicy.getClass().getName()).append("\n");
     sb.append("commit=").append(commit == null ? "null" : commit).append("\n");
     sb.append("openMode=").append(openMode).append("\n");
-    sb.append("similarityProvider=").append(similarityProvider.getClass().getName()).append("\n");
+    sb.append("similarity=").append(similarity.getClass().getName()).append("\n");
     sb.append("termIndexInterval=").append(termIndexInterval).append("\n"); // TODO: this should be private to the codec, not settable here
     sb.append("mergeScheduler=").append(mergeScheduler.getClass().getName()).append("\n");
     sb.append("default WRITE_LOCK_TIMEOUT=").append(WRITE_LOCK_TIMEOUT).append("\n");

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/NormsConsumerPerField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/NormsConsumerPerField.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/NormsConsumerPerField.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/NormsConsumerPerField.java Mon Feb  6 12:48:01 2012
@@ -39,7 +39,7 @@ public class NormsConsumerPerField exten
     this.parent = parent;
     docState = docInverterPerField.docState;
     fieldState = docInverterPerField.fieldState;
-    similarity = docState.similarityProvider.get(fieldInfo.name);
+    similarity = docState.similarity;
     norm = new Norm();
   }
 

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/BooleanQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/BooleanQuery.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/BooleanQuery.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/BooleanQuery.java Mon Feb  6 12:48:01 2012
@@ -28,8 +28,8 @@ import org.apache.lucene.index.TermsEnum
 import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.search.ConjunctionTermScorer.DocsAndFreqs;
 import org.apache.lucene.search.TermQuery.TermWeight;
+import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.search.similarities.Similarity.ExactSimScorer;
-import org.apache.lucene.search.similarities.SimilarityProvider;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.ToStringUtils;
 
@@ -79,18 +79,18 @@ public class BooleanQuery extends Query 
 
   /** Constructs an empty boolean query.
    *
-   * {@link SimilarityProvider#coord(int,int)} may be disabled in scoring, as
+   * {@link Similarity#coord(int,int)} may be disabled in scoring, as
    * appropriate. For example, this score factor does not make sense for most
    * automatically generated queries, like {@link WildcardQuery} and {@link
    * FuzzyQuery}.
    *
-   * @param disableCoord disables {@link SimilarityProvider#coord(int,int)} in scoring.
+   * @param disableCoord disables {@link Similarity#coord(int,int)} in scoring.
    */
   public BooleanQuery(boolean disableCoord) {
     this.disableCoord = disableCoord;
   }
 
-  /** Returns true iff {@link SimilarityProvider#coord(int,int)} is disabled in
+  /** Returns true iff {@link Similarity#coord(int,int)} is disabled in
    * scoring for this query instance.
    * @see #BooleanQuery(boolean)
    */
@@ -169,7 +169,7 @@ public class BooleanQuery extends Query 
    */
   protected class BooleanWeight extends Weight {
     /** The Similarity implementation. */
-    protected SimilarityProvider similarityProvider;
+    protected Similarity similarity;
     protected ArrayList<Weight> weights;
     protected int maxCoord;  // num optional + num required
     private final boolean disableCoord;
@@ -177,7 +177,7 @@ public class BooleanQuery extends Query 
 
     public BooleanWeight(IndexSearcher searcher, boolean disableCoord)
       throws IOException {
-      this.similarityProvider = searcher.getSimilarityProvider();
+      this.similarity = searcher.getSimilarity();
       this.disableCoord = disableCoord;
       weights = new ArrayList<Weight>(clauses.size());
       boolean termConjunction = clauses.isEmpty() || minNrShouldMatch != 0 ? false : true;
@@ -213,7 +213,7 @@ public class BooleanQuery extends Query 
     }
 
     public float coord(int overlap, int maxOverlap) {
-      return similarityProvider.coord(overlap, maxOverlap);
+      return similarity.coord(overlap, maxOverlap);
     }
 
     @Override

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/IndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/IndexSearcher.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/IndexSearcher.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/IndexSearcher.java Mon Feb  6 12:48:01 2012
@@ -40,8 +40,8 @@ import org.apache.lucene.index.IndexRead
 import org.apache.lucene.index.StoredFieldVisitor;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.Terms;
-import org.apache.lucene.search.similarities.DefaultSimilarityProvider;
-import org.apache.lucene.search.similarities.SimilarityProvider;
+import org.apache.lucene.search.similarities.DefaultSimilarity;
+import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.store.NIOFSDirectory;    // javadoc
 import org.apache.lucene.util.ReaderUtil;
 import org.apache.lucene.util.TermContext;
@@ -86,22 +86,22 @@ public class IndexSearcher {
   // These are only used for multi-threaded search
   private final ExecutorService executor;
 
-  // the default SimilarityProvider
-  private static final SimilarityProvider defaultProvider = new DefaultSimilarityProvider();
+  // the default Similarity
+  private static final Similarity defaultSimilarity = new DefaultSimilarity();
   
   /**
-   * Expert: returns a default SimilarityProvider instance.
+   * Expert: returns a default Similarity instance.
    * In general, this method is only called to initialize searchers and writers.
    * User code and query implementations should respect
-   * {@link IndexSearcher#getSimilarityProvider()}.
+   * {@link IndexSearcher#getSimilarity()}.
    * @lucene.internal
    */
-  public static SimilarityProvider getDefaultSimilarityProvider() {
-    return defaultProvider;
+  public static Similarity getDefaultSimilarity() {
+    return defaultSimilarity;
   }
   
-  /** The SimilarityProvider implementation used by this searcher. */
-  private SimilarityProvider similarityProvider = defaultProvider;
+  /** The Similarity implementation used by this searcher. */
+  private Similarity similarity = defaultSimilarity;
 
   /** Creates a searcher searching the provided index. */
   public IndexSearcher(IndexReader r) {
@@ -193,15 +193,15 @@ public class IndexSearcher {
     return reader.document(docID, fieldsToLoad);
   }
 
-  /** Expert: Set the SimilarityProvider implementation used by this Searcher.
+  /** Expert: Set the Similarity implementation used by this Searcher.
    *
    */
-  public void setSimilarityProvider(SimilarityProvider similarityProvider) {
-    this.similarityProvider = similarityProvider;
+  public void setSimilarity(Similarity similarity) {
+    this.similarity = similarity;
   }
 
-  public SimilarityProvider getSimilarityProvider() {
-    return similarityProvider;
+  public Similarity getSimilarity() {
+    return similarity;
   }
   
   /** @lucene.internal */
@@ -583,7 +583,7 @@ public class IndexSearcher {
     query = rewrite(query);
     Weight weight = query.createWeight(this);
     float v = weight.getValueForNormalization();
-    float norm = getSimilarityProvider().queryNorm(v);
+    float norm = getSimilarity().queryNorm(v);
     if (Float.isInfinite(norm) || Float.isNaN(norm))
       norm = 1.0f;
     weight.normalize(norm, 1.0f);

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java Mon Feb  6 12:48:01 2012
@@ -142,7 +142,7 @@ public class MultiPhraseQuery extends Qu
 
     public MultiPhraseWeight(IndexSearcher searcher)
       throws IOException {
-      this.similarity = searcher.getSimilarityProvider().get(field);
+      this.similarity = searcher.getSimilarity();
       final IndexReaderContext context = searcher.getTopReaderContext();
       
       // compute idf

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/PhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/PhraseQuery.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/PhraseQuery.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/PhraseQuery.java Mon Feb  6 12:48:01 2012
@@ -188,7 +188,7 @@ public class PhraseQuery extends Query {
 
     public PhraseWeight(IndexSearcher searcher)
       throws IOException {
-      this.similarity = searcher.getSimilarityProvider().get(field);
+      this.similarity = searcher.getSimilarity();
       final IndexReaderContext context = searcher.getTopReaderContext();
       states = new TermContext[terms.size()];
       TermStatistics termStats[] = new TermStatistics[terms.size()];

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/SearcherFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/SearcherFactory.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/SearcherFactory.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/SearcherFactory.java Mon Feb  6 12:48:01 2012
@@ -23,7 +23,7 @@ import java.util.concurrent.ExecutorServ
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter; // javadocs
 import org.apache.lucene.index.IndexWriterConfig; // javadocs
-import org.apache.lucene.search.similarities.SimilarityProvider; // javadocs
+import org.apache.lucene.search.similarities.Similarity; // javadocs
 
 /**
  * Factory class used by {@link SearcherManager} and {@link NRTManager} to
@@ -38,7 +38,7 @@ import org.apache.lucene.search.similari
  * 
  * You can pass your own factory instead if you want custom behavior, such as:
  * <ul>
- *   <li>Setting a custom scoring model: {@link IndexSearcher#setSimilarityProvider(SimilarityProvider)}
+ *   <li>Setting a custom scoring model: {@link IndexSearcher#setSimilarity(Similarity)}
  *   <li>Parallel per-segment search: {@link IndexSearcher#IndexSearcher(IndexReader, ExecutorService)}
  *   <li>Return custom subclasses of IndexSearcher (for example that implement distributed scoring)
  *   <li>Run queries to warm your IndexSearcher before it is used. Note: when using near-realtime search

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/TermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/TermQuery.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/TermQuery.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/TermQuery.java Mon Feb  6 12:48:01 2012
@@ -52,7 +52,7 @@ public class TermQuery extends Query {
       throws IOException {
       assert termStates != null : "TermContext must not be null";
       this.termStates = termStates;
-      this.similarity = searcher.getSimilarityProvider().get(term.field());
+      this.similarity = searcher.getSimilarity();
       this.stats = similarity.computeWeight(
           getBoost(), 
           searcher.collectionStatistics(term.field()), 

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/Weight.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/Weight.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/Weight.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/Weight.java Mon Feb  6 12:48:01 2012
@@ -22,7 +22,7 @@ import java.io.IOException;
 import org.apache.lucene.index.AtomicReader; // javadocs
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.index.IndexReaderContext; // javadocs
-import org.apache.lucene.search.similarities.SimilarityProvider;
+import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.util.Bits;
 
 /**
@@ -46,7 +46,7 @@ import org.apache.lucene.util.Bits;
  * <code>IndexSearcher</code> ({@link Query#createWeight(IndexSearcher)}).
  * <li>The {@link #getValueForNormalization()} method is called on the
  * <code>Weight</code> to compute the query normalization factor
- * {@link SimilarityProvider#queryNorm(float)} of the query clauses contained in the
+ * {@link Similarity#queryNorm(float)} of the query clauses contained in the
  * query.
  * <li>The query normalization factor is passed to {@link #normalize(float, float)}. At
  * this point the weighting is complete.

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/DefaultSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/DefaultSimilarity.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/DefaultSimilarity.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/DefaultSimilarity.java Mon Feb  6 12:48:01 2012
@@ -24,6 +24,16 @@ import org.apache.lucene.util.BytesRef;
 /** Expert: Default scoring implementation. */
 public class DefaultSimilarity extends TFIDFSimilarity {
   
+  /** Implemented as <code>overlap / maxOverlap</code>. */
+  public float coord(int overlap, int maxOverlap) {
+    return overlap / (float)maxOverlap;
+  }
+
+  /** Implemented as <code>1/sqrt(sumOfSquaredWeights)</code>. */
+  public float queryNorm(float sumOfSquaredWeights) {
+    return (float)(1.0 / Math.sqrt(sumOfSquaredWeights));
+  }
+  
   /** Implemented as
    *  <code>state.getBoost()*lengthNorm(numTerms)</code>, where
    *  <code>numTerms</code> is {@link FieldInvertState#getLength()} if {@link

Added: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/PerFieldSimilarityWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/PerFieldSimilarityWrapper.java?rev=1241001&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/PerFieldSimilarityWrapper.java (added)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/PerFieldSimilarityWrapper.java Mon Feb  6 12:48:01 2012
@@ -0,0 +1,82 @@
+package org.apache.lucene.search.similarities;
+
+/**
+ * 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 java.io.IOException;
+
+import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.FieldInvertState;
+import org.apache.lucene.index.Norm;
+import org.apache.lucene.search.CollectionStatistics;
+import org.apache.lucene.search.TermStatistics;
+
+/**
+ * Provides the ability to use a different {@link Similarity} for different fields.
+ * <p>
+ * Subclasses should implement {@link #get(String)} to return an appropriate
+ * Similarity (for example, using field-specific parameter values) for the field.
+ * 
+ * @lucene.experimental
+ */
+public abstract class PerFieldSimilarityWrapper extends Similarity {
+
+  @Override
+  public final void computeNorm(FieldInvertState state, Norm norm) {
+    get(state.getName()).computeNorm(state, norm);
+  }
+
+  @Override
+  public final SimWeight computeWeight(float queryBoost, CollectionStatistics collectionStats, TermStatistics... termStats) {
+    PerFieldSimWeight weight = new PerFieldSimWeight();
+    weight.delegate = get(collectionStats.field());
+    weight.delegateWeight = weight.delegate.computeWeight(queryBoost, collectionStats, termStats);
+    return weight;
+  }
+
+  @Override
+  public final ExactSimScorer exactSimScorer(SimWeight weight, AtomicReaderContext context) throws IOException {
+    PerFieldSimWeight perFieldWeight = (PerFieldSimWeight) weight;
+    return perFieldWeight.delegate.exactSimScorer(perFieldWeight.delegateWeight, context);
+  }
+
+  @Override
+  public final SloppySimScorer sloppySimScorer(SimWeight weight, AtomicReaderContext context) throws IOException {
+    PerFieldSimWeight perFieldWeight = (PerFieldSimWeight) weight;
+    return perFieldWeight.delegate.sloppySimScorer(perFieldWeight.delegateWeight, context);
+  }
+  
+  /** 
+   * Returns a {@link Similarity} for scoring a field.
+   */
+  public abstract Similarity get(String name);
+  
+  static class PerFieldSimWeight extends SimWeight {
+    Similarity delegate;
+    SimWeight delegateWeight;
+    
+    @Override
+    public float getValueForNormalization() {
+      return delegateWeight.getValueForNormalization();
+    }
+    
+    @Override
+    public void normalize(float queryNorm, float topLevelBoost) {
+      delegateWeight.normalize(queryNorm, topLevelBoost);
+    }
+  }
+}

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/Similarity.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/Similarity.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/Similarity.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/Similarity.java Mon Feb  6 12:48:01 2012
@@ -74,8 +74,8 @@ import org.apache.lucene.util.SmallFloat
  * Finally, using index-time boosts (either via folding into the normalization byte or
  * via DocValues), is an inefficient way to boost the scores of different fields if the
  * boost will be the same for every document, instead the Similarity can simply take a constant
- * boost parameter <i>C</i>, and the SimilarityProvider can return different instances with
- * different boosts depending upon field name.
+ * boost parameter <i>C</i>, and {@link PerFieldSimilarityWrapper} can return different 
+ * instances with different boosts depending upon field name.
  * <p>
  * <a name="querytime"/>
  * At query-time, Queries interact with the Similarity via these steps:
@@ -87,7 +87,7 @@ import org.apache.lucene.util.SmallFloat
  *       of statistics without causing any additional I/O. Lucene makes no assumption about what is 
  *       stored in the returned {@link Similarity.SimWeight} object.
  *   <li>The query normalization process occurs a single time: {@link Similarity.SimWeight#getValueForNormalization()}
- *       is called for each query leaf node, {@link SimilarityProvider#queryNorm(float)} is called for the top-level
+ *       is called for each query leaf node, {@link Similarity#queryNorm(float)} is called for the top-level
  *       query, and finally {@link Similarity.SimWeight#normalize(float, float)} passes down the normalization value
  *       and any top-level boosts (e.g. from enclosing {@link BooleanQuery}s).
  *   <li>For each segment in the index, the Query creates a {@link #exactSimScorer(SimWeight, AtomicReaderContext)}
@@ -101,12 +101,43 @@ import org.apache.lucene.util.SmallFloat
  * explanation of how it computed its score. The query passes in a the document id and an explanation of how the frequency
  * was computed.
  *
- * @see org.apache.lucene.index.IndexWriterConfig#setSimilarityProvider(SimilarityProvider)
- * @see IndexSearcher#setSimilarityProvider(SimilarityProvider)
+ * @see org.apache.lucene.index.IndexWriterConfig#setSimilarity(Similarity)
+ * @see IndexSearcher#setSimilarity(Similarity)
  * @lucene.experimental
  */
 public abstract class Similarity {
   
+  /** Hook to integrate coordinate-level matching.
+   * <p>
+   * By default this is disabled (returns <code>1</code>), as with
+   * most modern models this will only skew performance, but some
+   * implementations such as {@link TFIDFSimilarity} override this.
+   *
+   * @param overlap the number of query terms matched in the document
+   * @param maxOverlap the total number of terms in the query
+   * @return a score factor based on term overlap with the query
+   */
+  public float coord(int overlap, int maxOverlap) {
+    return 1f;
+  }
+  
+  /** Computes the normalization value for a query given the sum of the
+   * normalized weights {@link SimWeight#getValueForNormalization()} of 
+   * each of the query terms.  This value is passed back to the 
+   * weight ({@link SimWeight#normalize(float, float)} of each query 
+   * term, to provide a hook to attempt to make scores from different
+   * queries comparable.
+   * <p>
+   * By default this is disabled (returns <code>1</code>), but some
+   * implementations such as {@link TFIDFSimilarity} override this.
+   * 
+   * @param valueForNormalization the sum of the term normalization values
+   * @return a normalization factor for query weights
+   */
+  public float queryNorm(float valueForNormalization) {
+    return 1f;
+  }
+  
   /**
    * Computes the normalization value for a field, given the accumulated
    * state of term processing for this field (see {@link FieldInvertState}).

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/TFIDFSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/TFIDFSimilarity.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/TFIDFSimilarity.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/TFIDFSimilarity.java Mon Feb  6 12:48:01 2012
@@ -366,8 +366,8 @@ import org.apache.lucene.util.SmallFloat
  *      Typically, a document that contains more of the query's terms will receive a higher score
  *      than another document with fewer query terms.
  *      This is a search time factor computed in
- *      {@link SimilarityProvider#coord(int, int) coord(q,d)}
- *      by the SimilarityProvider in effect at search time.
+ *      {@link #coord(int, int) coord(q,d)}
+ *      by the Similarity in effect at search time.
  *      <br>&nbsp;<br>
  *    </li>
  *
@@ -381,14 +381,14 @@ import org.apache.lucene.util.SmallFloat
  *      This is a search time factor computed by the Similarity in effect at search time.
  *
  *      The default computation in
- *      {@link org.apache.lucene.search.similarities.DefaultSimilarityProvider#queryNorm(float) DefaultSimilarityProvider}
+ *      {@link org.apache.lucene.search.similarities.DefaultSimilarity#queryNorm(float) DefaultSimilarity}
  *      produces a <a href="http://en.wikipedia.org/wiki/Euclidean_norm#Euclidean_norm">Euclidean norm</a>:
  *      <br>&nbsp;<br>
  *      <table cellpadding="1" cellspacing="0" border="0" align="center">
  *        <tr>
  *          <td valign="middle" align="right" rowspan="1">
  *            queryNorm(q)  &nbsp; = &nbsp;
- *            {@link org.apache.lucene.search.similarities.DefaultSimilarityProvider#queryNorm(float) queryNorm(sumOfSquaredWeights)}
+ *            {@link org.apache.lucene.search.similarities.DefaultSimilarity#queryNorm(float) queryNorm(sumOfSquaredWeights)}
  *            &nbsp; = &nbsp;
  *          </td>
  *          <td valign="middle" align="center" rowspan="1">
@@ -520,11 +520,42 @@ import org.apache.lucene.util.SmallFloat
  *    </li>
  * </ol>
  *
- * @see org.apache.lucene.index.IndexWriterConfig#setSimilarityProvider(SimilarityProvider)
- * @see IndexSearcher#setSimilarityProvider(SimilarityProvider)
+ * @see org.apache.lucene.index.IndexWriterConfig#setSimilarity(Similarity)
+ * @see IndexSearcher#setSimilarity(Similarity)
  */
 public abstract class TFIDFSimilarity extends Similarity {
   
+  /** Computes a score factor based on the fraction of all query terms that a
+   * document contains.  This value is multiplied into scores.
+   *
+   * <p>The presence of a large portion of the query terms indicates a better
+   * match with the query, so implementations of this method usually return
+   * larger values when the ratio between these parameters is large and smaller
+   * values when the ratio between them is small.
+   *
+   * @param overlap the number of query terms matched in the document
+   * @param maxOverlap the total number of terms in the query
+   * @return a score factor based on term overlap with the query
+   */
+  @Override
+  public abstract float coord(int overlap, int maxOverlap);
+  
+  /** Computes the normalization value for a query given the sum of the squared
+   * weights of each of the query terms.  This value is multiplied into the
+   * weight of each query term. While the classic query normalization factor is
+   * computed as 1/sqrt(sumOfSquaredWeights), other implementations might
+   * completely ignore sumOfSquaredWeights (ie return 1).
+   *
+   * <p>This does not affect ranking, but the default implementation does make scores
+   * from different queries more comparable than they would be by eliminating the
+   * magnitude of the Query vector as a factor in the score.
+   *
+   * @param sumOfSquaredWeights the sum of the squares of query term weights
+   * @return a normalization factor for query weights
+   */
+  @Override
+  public abstract float queryNorm(float sumOfSquaredWeights);
+  
   /** Computes a score factor based on a term or phrase's frequency in a
    * document.  This value is multiplied by the {@link #idf(long, long)}
    * factor for each term in the query and these products are then summed to

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/package.html
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/package.html?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/package.html (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/similarities/package.html Mon Feb  6 12:48:01 2012
@@ -30,7 +30,6 @@ package.
 <p>
     <ol>
         <li><a href="#sims">Summary of the Ranking Methods</a></li>
-        <li><a href="#providers">Similarity Providers<a/></li>
         <li><a href="#changingSimilarity">Changing the Similarity</a></li>
     </ol>
 </p>
@@ -69,27 +68,6 @@ performance is to be expected when using
 optimizations can always be implemented in subclasses; see
 <a href="#changingSimilarity">below</a>.</p>
 
-
-<a name="providers"></a>
-<h2>Similarity Providers</h2>
-
-<p>{@link org.apache.lucene.search.similarities.SimilarityProvider}s are factories
-that return Similarities per-field and compute coordination factors and normalization 
-values for the query.
-{@link org.apache.lucene.search.similarities.DefaultSimilarityProvider} is the
-default implementation used by Lucene, geared towards vector-spaced search: it returns 
-{@link org.apache.lucene.search.similarities.DefaultSimilarity} for every field,
-and implements coordination-level matching and query normalization. 
-{@link org.apache.lucene.search.similarities.BasicSimilarityProvider} is geared towards
-non-vector-space models and does not implement coordination-level matching or query
-normalization. It is a convenience implementation that returns an arbitrary 
-{@link org.apache.lucene.search.similarities.Similarity} for every field.
-You can write your own SimilarityProvider to return different Similarities for different
-fields: for example you might want to use different parameter values for different fields,
-or maybe even entirely different ranking algorithms.
-</p>
-
-
 <a name="changingSimilarity"></a>
 <h2>Changing Similarity</h2>
 
@@ -110,13 +88,11 @@ or maybe even entirely different ranking
 <p>To make this change, implement your own {@link org.apache.lucene.search.similarities.Similarity} (likely
     you'll want to simply subclass an existing method, be it
     {@link org.apache.lucene.search.similarities.DefaultSimilarity} or a descendant of
-    {@link org.apache.lucene.search.similarities.SimilarityBase}) and
-    {@link org.apache.lucene.search.similarities.SimilarityProvider} (or use
-    {@link org.apache.lucene.search.similarities.BasicSimilarityProvider}), and
+    {@link org.apache.lucene.search.similarities.SimilarityBase}), and
     then register the new class by calling
-    {@link org.apache.lucene.index.IndexWriterConfig#setSimilarityProvider(SimilarityProvider)}
+    {@link org.apache.lucene.index.IndexWriterConfig#setSimilarity(Similarity)}
     before indexing and
-    {@link org.apache.lucene.search.IndexSearcher#setSimilarityProvider(SimilarityProvider)}
+    {@link org.apache.lucene.search.IndexSearcher#setSimilarity(Similarity)}
     before searching.
 </p>
 

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/spans/SpanWeight.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/spans/SpanWeight.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/spans/SpanWeight.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/spans/SpanWeight.java Mon Feb  6 12:48:01 2012
@@ -42,7 +42,7 @@ public class SpanWeight extends Weight {
 
   public SpanWeight(SpanQuery query, IndexSearcher searcher)
     throws IOException {
-    this.similarity = searcher.getSimilarityProvider().get(query.getField());
+    this.similarity = searcher.getSimilarity();
     this.query = query;
     
     termContexts = new HashMap<Term,TermContext>();

Modified: lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/index/DocHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/index/DocHelper.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/index/DocHelper.java (original)
+++ lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/index/DocHelper.java Mon Feb  6 12:48:01 2012
@@ -33,7 +33,7 @@ import org.apache.lucene.document.Stored
 import org.apache.lucene.document.StringField;
 import org.apache.lucene.document.TextField;
 import org.apache.lucene.index.FieldInfo.IndexOptions;
-import org.apache.lucene.search.similarities.SimilarityProvider;
+import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.store.Directory;
 
 import static org.apache.lucene.util.LuceneTestCase.TEST_VERSION_CURRENT;
@@ -276,9 +276,9 @@ class DocHelper {
    * @param doc
    * @throws IOException
    */ 
-  public static SegmentInfo writeDoc(Random random, Directory dir, Analyzer analyzer, SimilarityProvider similarity, Document doc) throws IOException {
+  public static SegmentInfo writeDoc(Random random, Directory dir, Analyzer analyzer, Similarity similarity, Document doc) throws IOException {
     IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig( /* LuceneTestCase.newIndexWriterConfig(random, */ 
-        TEST_VERSION_CURRENT, analyzer).setSimilarityProvider(similarity));
+        TEST_VERSION_CURRENT, analyzer).setSimilarity(similarity));
     //writer.setUseCompoundFile(false);
     writer.addDocument(doc);
     writer.commit();

Modified: lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/search/QueryUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/search/QueryUtils.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/search/QueryUtils.java (original)
+++ lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/search/QueryUtils.java Mon Feb  6 12:48:01 2012
@@ -168,7 +168,7 @@ public class QueryUtils {
           0 < edge ? r : emptyReaders[0])
     };
     IndexSearcher out = LuceneTestCase.newSearcher(new MultiReader(readers));
-    out.setSimilarityProvider(s.getSimilarityProvider());
+    out.setSimilarity(s.getSimilarity());
     return out;
   }
   

Modified: lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/search/RandomSimilarityProvider.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/search/RandomSimilarityProvider.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/search/RandomSimilarityProvider.java (original)
+++ lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/search/RandomSimilarityProvider.java Mon Feb  6 12:48:01 2012
@@ -38,7 +38,6 @@ import org.apache.lucene.search.similari
 import org.apache.lucene.search.similarities.BasicModelP;
 import org.apache.lucene.search.similarities.DFRSimilarity;
 import org.apache.lucene.search.similarities.DefaultSimilarity;
-import org.apache.lucene.search.similarities.DefaultSimilarityProvider;
 import org.apache.lucene.search.similarities.Distribution;
 import org.apache.lucene.search.similarities.DistributionLL;
 import org.apache.lucene.search.similarities.DistributionSPL;
@@ -53,9 +52,11 @@ import org.apache.lucene.search.similari
 import org.apache.lucene.search.similarities.NormalizationH2;
 import org.apache.lucene.search.similarities.NormalizationH3;
 import org.apache.lucene.search.similarities.NormalizationZ;
+import org.apache.lucene.search.similarities.PerFieldSimilarityWrapper;
 import org.apache.lucene.search.similarities.Similarity;
 
-public class RandomSimilarityProvider extends DefaultSimilarityProvider {
+public class RandomSimilarityProvider extends PerFieldSimilarityWrapper {
+  final DefaultSimilarity defaultSim = new DefaultSimilarity();
   final List<Similarity> knownSims;
   Map<String,Similarity> previousMappings = new HashMap<String,Similarity>();
   final int perFieldSeed;
@@ -73,7 +74,7 @@ public class RandomSimilarityProvider ex
   @Override
   public float coord(int overlap, int maxOverlap) {
     if (shouldCoord) {
-      return super.coord(overlap, maxOverlap);
+      return defaultSim.coord(overlap, maxOverlap);
     } else {
       return 1.0f;
     }
@@ -82,7 +83,7 @@ public class RandomSimilarityProvider ex
   @Override
   public float queryNorm(float sumOfSquaredWeights) {
     if (shouldQueryNorm) {
-      return super.queryNorm(sumOfSquaredWeights);
+      return defaultSim.queryNorm(sumOfSquaredWeights);
     } else {
       return 1.0f;
     }

Modified: lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java Mon Feb  6 12:48:01 2012
@@ -49,7 +49,8 @@ import org.apache.lucene.search.FieldCac
 import org.apache.lucene.search.AssertingIndexSearcher;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.RandomSimilarityProvider;
-import org.apache.lucene.search.similarities.SimilarityProvider;
+import org.apache.lucene.search.similarities.DefaultSimilarity;
+import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.FSDirectory;
 import org.apache.lucene.store.FlushInfo;
@@ -213,7 +214,7 @@ public abstract class LuceneTestCase ext
   
   private static InfoStream savedInfoStream;
 
-  private static SimilarityProvider similarityProvider;
+  private static Similarity similarity;
 
   private static Locale locale;
   private static Locale savedLocale;
@@ -330,7 +331,7 @@ public abstract class LuceneTestCase ext
     savedTimeZone = TimeZone.getDefault();
     timeZone = TEST_TIMEZONE.equals("random") ? randomTimeZone(random) : TimeZone.getTimeZone(TEST_TIMEZONE);
     TimeZone.setDefault(timeZone);
-    similarityProvider = new RandomSimilarityProvider(random);
+    similarity = random.nextBoolean() ? new DefaultSimilarity() : new RandomSimilarityProvider(random);
     testsFailed = false;
   }
 
@@ -407,7 +408,7 @@ public abstract class LuceneTestCase ext
   /** print some useful debugging information about the environment */
   private static void printDebuggingInformation(String codecDescription) {
     System.err.println("NOTE: test params are: codec=" + codecDescription +
-        ", sim=" + similarityProvider +
+        ", sim=" + similarity +
         ", locale=" + locale +
         ", timezone=" + (timeZone == null ? "(null)" : timeZone.getID()));
     System.err.println("NOTE: all tests run in this JVM:");
@@ -911,7 +912,7 @@ public abstract class LuceneTestCase ext
   /** create a new index writer config with random defaults using the specified random */
   public static IndexWriterConfig newIndexWriterConfig(Random r, Version v, Analyzer a) {
     IndexWriterConfig c = new IndexWriterConfig(v, a);
-    c.setSimilarityProvider(similarityProvider);
+    c.setSimilarity(similarity);
     if (r.nextBoolean()) {
       c.setMergeScheduler(new SerialMergeScheduler());
     }
@@ -1261,7 +1262,7 @@ public abstract class LuceneTestCase ext
         r = SlowCompositeReaderWrapper.wrap(r);
       }
       IndexSearcher ret = random.nextBoolean() ? new AssertingIndexSearcher(random, r) : new AssertingIndexSearcher(random, r.getTopReaderContext());
-      ret.setSimilarityProvider(similarityProvider);
+      ret.setSimilarity(similarity);
       return ret;
     } else {
       int threads = 0;
@@ -1282,7 +1283,7 @@ public abstract class LuceneTestCase ext
       IndexSearcher ret = random.nextBoolean() 
           ? new AssertingIndexSearcher(random, r, ex)
           : new AssertingIndexSearcher(random, r.getTopReaderContext(), ex);
-      ret.setSimilarityProvider(similarityProvider);
+      ret.setSimilarity(similarity);
       return ret;
     }
   }

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestCustomNorms.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestCustomNorms.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestCustomNorms.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestCustomNorms.java Mon Feb  6 12:48:01 2012
@@ -27,9 +27,8 @@ import org.apache.lucene.document.TextFi
 import org.apache.lucene.index.DocValues.Source;
 import org.apache.lucene.index.DocValues.Type;
 import org.apache.lucene.search.similarities.DefaultSimilarity;
-import org.apache.lucene.search.similarities.DefaultSimilarityProvider;
+import org.apache.lucene.search.similarities.PerFieldSimilarityWrapper;
 import org.apache.lucene.search.similarities.Similarity;
-import org.apache.lucene.search.similarities.SimilarityProvider;
 import org.apache.lucene.store.MockDirectoryWrapper;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.LineFileDocs;
@@ -59,8 +58,8 @@ public class TestCustomNorms extends Luc
     dir.setCheckIndexOnClose(false); // can't set sim to checkindex yet
     IndexWriterConfig config = newIndexWriterConfig(TEST_VERSION_CURRENT,
         new MockAnalyzer(random));
-    SimilarityProvider provider = new MySimProvider();
-    config.setSimilarityProvider(provider);
+    Similarity provider = new MySimProvider();
+    config.setSimilarity(provider);
     RandomIndexWriter writer = new RandomIndexWriter(random, dir, config);
     final LineFileDocs docs = new LineFileDocs(random);
     int num = atLeast(100);
@@ -100,8 +99,8 @@ public class TestCustomNorms extends Luc
     dir.setCheckIndexOnClose(false); // can't set sim to checkindex yet
     IndexWriterConfig config = newIndexWriterConfig(TEST_VERSION_CURRENT,
         new MockAnalyzer(random));
-    SimilarityProvider provider = new MySimProvider();
-    config.setSimilarityProvider(provider);
+    Similarity provider = new MySimProvider();
+    config.setSimilarity(provider);
     RandomIndexWriter writer = new RandomIndexWriter(random, dir, config);
     final LineFileDocs docs = new LineFileDocs(random);
     int num = atLeast(100);
@@ -130,12 +129,11 @@ public class TestCustomNorms extends Luc
 
   }
 
-  public class MySimProvider implements SimilarityProvider {
-    SimilarityProvider delegate = new DefaultSimilarityProvider();
+  public class MySimProvider extends PerFieldSimilarityWrapper {
+    Similarity delegate = new DefaultSimilarity();
 
     @Override
     public float queryNorm(float sumOfSquaredWeights) {
-
       return delegate.queryNorm(sumOfSquaredWeights);
     }
 
@@ -146,7 +144,7 @@ public class TestCustomNorms extends Luc
       } else if (exceptionTestField.equals(field)) {
         return new RandomTypeSimilarity(random);
       } else {
-        return delegate.get(field);
+        return delegate;
       }
     }
 

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java Mon Feb  6 12:48:01 2012
@@ -28,14 +28,14 @@ import org.apache.lucene.codecs.Codec;
 import org.apache.lucene.index.DocumentsWriterPerThread.IndexingChain;
 import org.apache.lucene.index.IndexWriterConfig.OpenMode;
 import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.similarities.DefaultSimilarityProvider;
+import org.apache.lucene.search.similarities.DefaultSimilarity;
 import org.apache.lucene.util.InfoStream;
 import org.apache.lucene.util.LuceneTestCase;
 import org.junit.Test;
 
 public class TestIndexWriterConfig extends LuceneTestCase {
 
-  private static final class MySimilarityProvider extends DefaultSimilarityProvider {
+  private static final class MySimilarity extends DefaultSimilarity {
     // Does not implement anything - used only for type checking on IndexWriterConfig.
   }
 
@@ -58,7 +58,7 @@ public class TestIndexWriterConfig exten
     assertEquals(ConcurrentMergeScheduler.class, conf.getMergeScheduler().getClass());
     assertEquals(OpenMode.CREATE_OR_APPEND, conf.getOpenMode());
     // we don't need to assert this, it should be unspecified
-    assertTrue(IndexSearcher.getDefaultSimilarityProvider() == conf.getSimilarityProvider());
+    assertTrue(IndexSearcher.getDefaultSimilarity() == conf.getSimilarity());
     assertEquals(IndexWriterConfig.DEFAULT_TERM_INDEX_INTERVAL, conf.getTermIndexInterval());
     assertEquals(IndexWriterConfig.getDefaultWriteLockTimeout(), conf.getWriteLockTimeout());
     assertEquals(IndexWriterConfig.WRITE_LOCK_TIMEOUT, IndexWriterConfig.getDefaultWriteLockTimeout());
@@ -83,7 +83,7 @@ public class TestIndexWriterConfig exten
     getters.add("getMaxFieldLength");
     getters.add("getMergeScheduler");
     getters.add("getOpenMode");
-    getters.add("getSimilarityProvider");
+    getters.add("getSimilarity");
     getters.add("getTermIndexInterval");
     getters.add("getWriteLockTimeout");
     getters.add("getDefaultWriteLockTimeout");
@@ -185,11 +185,11 @@ public class TestIndexWriterConfig exten
 
     // Test Similarity: 
     // we shouldnt assert what the default is, just that its not null.
-    assertTrue(IndexSearcher.getDefaultSimilarityProvider() == conf.getSimilarityProvider());
-    conf.setSimilarityProvider(new MySimilarityProvider());
-    assertEquals(MySimilarityProvider.class, conf.getSimilarityProvider().getClass());
-    conf.setSimilarityProvider(null);
-    assertTrue(IndexSearcher.getDefaultSimilarityProvider() == conf.getSimilarityProvider());
+    assertTrue(IndexSearcher.getDefaultSimilarity() == conf.getSimilarity());
+    conf.setSimilarity(new MySimilarity());
+    assertEquals(MySimilarity.class, conf.getSimilarity().getClass());
+    conf.setSimilarity(null);
+    assertTrue(IndexSearcher.getDefaultSimilarity() == conf.getSimilarity());
 
     // Test IndexingChain
     assertTrue(DocumentsWriterPerThread.defaultIndexingChain == conf.getIndexingChain());

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestMaxTermFrequency.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestMaxTermFrequency.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestMaxTermFrequency.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestMaxTermFrequency.java Mon Feb  6 12:48:01 2012
@@ -28,8 +28,6 @@ import org.apache.lucene.document.Docume
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.TextField;
 import org.apache.lucene.search.similarities.DefaultSimilarity;
-import org.apache.lucene.search.similarities.DefaultSimilarityProvider;
-import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util._TestUtil;
@@ -49,12 +47,7 @@ public class TestMaxTermFrequency extend
     dir = newDirectory();
     IndexWriterConfig config = newIndexWriterConfig(TEST_VERSION_CURRENT, 
                                                     new MockAnalyzer(random, MockTokenizer.SIMPLE, true)).setMergePolicy(newLogMergePolicy());
-    config.setSimilarityProvider(new DefaultSimilarityProvider() {
-      @Override
-      public Similarity get(String field) {
-        return new TestSimilarity();
-      }
-    });
+    config.setSimilarity(new TestSimilarity());
     RandomIndexWriter writer = new RandomIndexWriter(random, dir, config);
     Document doc = new Document();
     Field foo = newField("foo", "", TextField.TYPE_UNSTORED);

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestNorms.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestNorms.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestNorms.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestNorms.java Mon Feb  6 12:48:01 2012
@@ -26,9 +26,8 @@ import org.apache.lucene.document.TextFi
 import org.apache.lucene.index.DocValues.Source;
 import org.apache.lucene.index.DocValues.Type;
 import org.apache.lucene.search.similarities.DefaultSimilarity;
-import org.apache.lucene.search.similarities.DefaultSimilarityProvider;
+import org.apache.lucene.search.similarities.PerFieldSimilarityWrapper;
 import org.apache.lucene.search.similarities.Similarity;
-import org.apache.lucene.search.similarities.SimilarityProvider;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.MockDirectoryWrapper;
 import org.apache.lucene.util.LineFileDocs;
@@ -62,12 +61,7 @@ public class TestNorms extends LuceneTes
   public void testCustomEncoder() throws Exception {
     Directory dir = newDirectory();
     IndexWriterConfig config = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random));
-    config.setSimilarityProvider(new DefaultSimilarityProvider() {
-      @Override
-      public Similarity get(String field) {
-        return new CustomNormEncodingSimilarity();
-      }
-    });
+    config.setSimilarity(new CustomNormEncodingSimilarity());
     RandomIndexWriter writer = new RandomIndexWriter(random, dir, config);
     Document doc = new Document();
     Field foo = newField("foo", "", TextField.TYPE_UNSTORED);
@@ -182,8 +176,8 @@ public class TestNorms extends LuceneTes
       CorruptIndexException {
     IndexWriterConfig config = newIndexWriterConfig(TEST_VERSION_CURRENT,
         new MockAnalyzer(random));
-    SimilarityProvider provider = new MySimProvider(writeNorms);
-    config.setSimilarityProvider(provider);
+    Similarity provider = new MySimProvider(writeNorms);
+    config.setSimilarity(provider);
     RandomIndexWriter writer = new RandomIndexWriter(random, dir, config);
     final LineFileDocs docs = new LineFileDocs(random);
     int num = atLeast(100);
@@ -205,8 +199,8 @@ public class TestNorms extends LuceneTes
   }
 
 
-  public class MySimProvider implements SimilarityProvider {
-    SimilarityProvider delegate = new DefaultSimilarityProvider();
+  public class MySimProvider extends PerFieldSimilarityWrapper {
+    Similarity delegate = new DefaultSimilarity();
     private boolean writeNorms;
     public MySimProvider(boolean writeNorms) {
       this.writeNorms = writeNorms;
@@ -222,7 +216,7 @@ public class TestNorms extends LuceneTes
       if (byteTestField.equals(field)) {
         return new ByteEncodingBoostSimilarity(writeNorms);
       } else {
-        return delegate.get(field);
+        return delegate;
       }
     }
 

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=1241001&r1=1241000&r2=1241001&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 Feb  6 12:48:01 2012
@@ -31,28 +31,23 @@ import org.apache.lucene.document.TextFi
 import org.apache.lucene.search.*;
 import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.search.similarities.Similarity;
-import org.apache.lucene.search.similarities.SimilarityProvider;
 import org.apache.lucene.search.similarities.TFIDFSimilarity;
 import org.apache.lucene.store.Directory;
 
 
 public class TestOmitTf extends LuceneTestCase {
   
-  public static class SimpleSimilarityProvider implements SimilarityProvider {
+  public static class SimpleSimilarity extends TFIDFSimilarity {
     public float queryNorm(float sumOfSquaredWeights) { return 1.0f; }
     public float coord(int overlap, int maxOverlap) { return 1.0f; }
-    public Similarity get(String field) {
-      return new TFIDFSimilarity() {
-        @Override public void computeNorm(FieldInvertState state, Norm norm) { norm.setByte(encodeNormValue(state.getBoost())); }
-        @Override public float tf(float freq) { return freq; }
-        @Override public float sloppyFreq(int distance) { return 2.0f; }
-        @Override public float idf(long docFreq, long numDocs) { return 1.0f; }
-        @Override public Explanation idfExplain(CollectionStatistics collectionStats, TermStatistics[] termStats) {
-          return new Explanation(1.0f, "Inexplicable");
-        }
-        @Override public float scorePayload(int doc, int start, int end, BytesRef payload) { return 1.0f; }
-      };
+    @Override public void computeNorm(FieldInvertState state, Norm norm) { norm.setByte(encodeNormValue(state.getBoost())); }
+    @Override public float tf(float freq) { return freq; }
+    @Override public float sloppyFreq(int distance) { return 2.0f; }
+    @Override public float idf(long docFreq, long numDocs) { return 1.0f; }
+    @Override public Explanation idfExplain(CollectionStatistics collectionStats, TermStatistics[] termStats) {
+      return new Explanation(1.0f, "Inexplicable");
     }
+    @Override public float scorePayload(int doc, int start, int end, BytesRef payload) { return 1.0f; }
   }
 
   private static final FieldType omitType = new FieldType(TextField.TYPE_UNSTORED);
@@ -257,7 +252,7 @@ public class TestOmitTf extends LuceneTe
         dir,
         newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer).
             setMaxBufferedDocs(2).
-            setSimilarityProvider(new SimpleSimilarityProvider()).
+            setSimilarity(new SimpleSimilarity()).
             setMergePolicy(newLogMergePolicy(2))
     );
         
@@ -286,7 +281,7 @@ public class TestOmitTf extends LuceneTe
      */         
     IndexReader reader = IndexReader.open(dir);
     IndexSearcher searcher = new IndexSearcher(reader);
-    searcher.setSimilarityProvider(new SimpleSimilarityProvider());
+    searcher.setSimilarity(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/TestUniqueTermCount.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestUniqueTermCount.java?rev=1241001&r1=1241000&r2=1241001&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestUniqueTermCount.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestUniqueTermCount.java Mon Feb  6 12:48:01 2012
@@ -26,7 +26,6 @@ import org.apache.lucene.document.Docume
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.TextField;
 import org.apache.lucene.search.similarities.DefaultSimilarity;
-import org.apache.lucene.search.similarities.DefaultSimilarityProvider;
 import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.LuceneTestCase;
@@ -47,12 +46,7 @@ public class TestUniqueTermCount extends
     dir = newDirectory();
     IndexWriterConfig config = newIndexWriterConfig(TEST_VERSION_CURRENT, 
                                                     new MockAnalyzer(random, MockTokenizer.SIMPLE, true)).setMergePolicy(newLogMergePolicy());
-    config.setSimilarityProvider(new DefaultSimilarityProvider() {
-      @Override
-      public Similarity get(String field) {
-        return new TestSimilarity();
-      }
-    });
+    config.setSimilarity(new TestSimilarity());
     RandomIndexWriter writer = new RandomIndexWriter(random, dir, config);
     Document doc = new Document();
     Field foo = newField("foo", "", TextField.TYPE_UNSTORED);



Mime
View raw message