lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hoss...@apache.org
Subject svn commit: r1713557 - in /lucene/dev/trunk/solr: ./ core/src/java/org/apache/solr/search/similarities/ core/src/test/org/apache/solr/search/similarities/
Date Mon, 09 Nov 2015 22:07:57 GMT
Author: hossman
Date: Mon Nov  9 22:07:57 2015
New Revision: 1713557

URL: http://svn.apache.org/viewvc?rev=1713557&view=rev
Log:
SOLR-8261: Change SchemaSimilarityFactory default to BM25Similarity

Added:
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/similarities/TestPerFieldSimilarityClassic.java
      - copied, changed from r1713475, lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/similarities/TestPerFieldSimilarity.java
Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/similarities/SchemaSimilarityFactory.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/similarities/TestPerFieldSimilarity.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1713557&r1=1713556&r2=1713557&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Mon Nov  9 22:07:57 2015
@@ -55,6 +55,10 @@ Upgrading from Solr 5.x
   refrenced in your schema.xml, edit your config to use the functionally identical ClassicSimilarityFactory.
   See SOLR-8239 for more details.
 
+* SchemaSimilarityFactory has been modified to use BM25Similarity as the default for fieldTypes
that
+  do not explicitly declare a Similarity.  The legacy behavior of using ClassicSimilarity
as the
+  default will occur if the luceneMatchVersion for the collection is less then 6.0.  See
SOLR-8261 for
+  more details.
 
 Detailed Change List
 ----------------------
@@ -130,6 +134,8 @@ Other Changes
 * SOLR-8114: in Grouping.java rename groupSort and sort to withinGroupSort and groupSort
   (Christine Poerschke)
 
+* SOLR-8261: Change SchemaSimilarityFactory default to BM25Similarity (hossman)
+
 ==================  5.4.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/similarities/SchemaSimilarityFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/similarities/SchemaSimilarityFactory.java?rev=1713557&r1=1713556&r2=1713557&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/similarities/SchemaSimilarityFactory.java
(original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/similarities/SchemaSimilarityFactory.java
Mon Nov  9 22:07:57 2015
@@ -18,8 +18,11 @@ package org.apache.solr.search.similarit
  */
 
 import org.apache.lucene.search.similarities.ClassicSimilarity;
+import org.apache.lucene.search.similarities.BM25Similarity;
 import org.apache.lucene.search.similarities.PerFieldSimilarityWrapper;
 import org.apache.lucene.search.similarities.Similarity;
+import org.apache.lucene.util.Version;
+
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.schema.FieldType;
@@ -27,10 +30,15 @@ import org.apache.solr.schema.Similarity
 import org.apache.solr.util.plugin.SolrCoreAware;
 
 /**
+ * <p>
  * SimilarityFactory that returns a {@link PerFieldSimilarityWrapper}
  * that delegates to the field type, if it's configured, otherwise
- * {@link ClassicSimilarity}.
- *
+ * returns a sensible default depending on the {@link Version} matching configured.
+ * </p>
+ * <ul>
+ *  <li><code>luceneMatchVersion &lt; 6.0</code> = {@link ClassicSimilarity}</li>
+ *  <li><code>luceneMatchVersion &gt;= 6.0</code> = {@link BM25Similarity}</li>
+ * </ul>
  * <p>
  * <b>NOTE:</b> Users should be aware that in addition to supporting 
  * <code>Similarity</code> configurations specified on individual 
@@ -44,13 +52,16 @@ import org.apache.solr.util.plugin.SolrC
  * @see FieldType#getSimilarity
  */
 public class SchemaSimilarityFactory extends SimilarityFactory implements SolrCoreAware {
-  private Similarity similarity;
-  private Similarity defaultSimilarity = new ClassicSimilarity();
+  private Similarity similarity; // set by init
+  private Similarity defaultSimilarity; // set by inform(SolrCore)
   private volatile SolrCore core;
 
   @Override
   public void inform(SolrCore core) {
     this.core = core;
+    this.defaultSimilarity = this.core.getSolrConfig().luceneMatchVersion.onOrAfter(Version.LUCENE_6_0_0)
+      ? new BM25Similarity()
+      : new ClassicSimilarity();
   }
   
   @Override

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/similarities/TestPerFieldSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/similarities/TestPerFieldSimilarity.java?rev=1713557&r1=1713556&r2=1713557&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/similarities/TestPerFieldSimilarity.java
(original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/similarities/TestPerFieldSimilarity.java
Mon Nov  9 22:07:57 2015
@@ -18,12 +18,13 @@ package org.apache.solr.search.similarit
  */
 
 import org.apache.lucene.misc.SweetSpotSimilarity;
-import org.apache.lucene.search.similarities.ClassicSimilarity;
+import org.apache.lucene.search.similarities.BM25Similarity;
 import org.apache.lucene.search.similarities.Similarity;
 import org.junit.BeforeClass;
 
 /**
  * Tests per-field similarity support in the schema
+ * @see TestPerFieldSimilarityClassic
  */
 public class TestPerFieldSimilarity extends BaseSimilarityTestCase {
 
@@ -59,18 +60,18 @@ public class TestPerFieldSimilarity exte
   /** test a field where no similarity is specified */
   public void testDefaults() throws Exception {
     Similarity sim = getSimilarity("sim3text");
-    assertEquals(ClassicSimilarity.class, sim.getClass());;
+    assertEquals(BM25Similarity.class, sim.getClass());;
   }
   
   /** ... and for a dynamic field */
   public void testDefaultsDynamic() throws Exception {
     Similarity sim = getSimilarity("text_sim3");
-    assertEquals(ClassicSimilarity.class, sim.getClass());
+    assertEquals(BM25Similarity.class, sim.getClass());
   }
   
   /** test a field that does not exist */
   public void testNonexistent() throws Exception {
     Similarity sim = getSimilarity("sdfdsfdsfdswr5fsdfdsfdsfs");
-    assertEquals(ClassicSimilarity.class, sim.getClass());
+    assertEquals(BM25Similarity.class, sim.getClass());
   }
 }

Copied: lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/similarities/TestPerFieldSimilarityClassic.java
(from r1713475, lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/similarities/TestPerFieldSimilarity.java)
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/similarities/TestPerFieldSimilarityClassic.java?p2=lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/similarities/TestPerFieldSimilarityClassic.java&p1=lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/similarities/TestPerFieldSimilarity.java&r1=1713475&r2=1713557&rev=1713557&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/similarities/TestPerFieldSimilarity.java
(original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/similarities/TestPerFieldSimilarityClassic.java
Mon Nov  9 22:07:57 2015
@@ -20,18 +20,29 @@ package org.apache.solr.search.similarit
 import org.apache.lucene.misc.SweetSpotSimilarity;
 import org.apache.lucene.search.similarities.ClassicSimilarity;
 import org.apache.lucene.search.similarities.Similarity;
+import org.apache.lucene.util.Version;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 
 /**
- * Tests per-field similarity support in the schema
+ * Tests per-field similarity support in the schema when luceneMatchVersion indicates 
+ * {@link ClassicSimilarity} should be the default.
+ * @see TestPerFieldSimilarity
  */
-public class TestPerFieldSimilarity extends BaseSimilarityTestCase {
+public class TestPerFieldSimilarityClassic extends BaseSimilarityTestCase {
 
   @BeforeClass
   public static void beforeClass() throws Exception {
+    // any value below 6.0 should have this behavior
+    System.setProperty("tests.luceneMatchVersion", Version.LUCENE_5_3_1.toString());
     initCore("solrconfig-basic.xml","schema-sim.xml");
   }
   
+  @AfterClass
+  public static void afterClass() throws Exception {
+    System.clearProperty("tests.luceneMatchVersion");
+  }
+
   /** test a field where the sim is specified directly */
   public void testDirect() throws Exception {
     assertEquals(SweetSpotSimilarity.class, getSimilarity("sim1text").getClass());



Mime
View raw message