diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 0669e7768e4..0428c8819dc 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -140,6 +140,12 @@ Jetty 9.2.13.v20150730
Upgrading from Solr 5.3
-----------------------
+* DefaultSimilarityFactory has been renamed to ClassicSimilarityFactory to mach the underlying rename of
+ DefaultSimilarity to ClassicSimilarity and the (eventual) move away from using it as a default.
+ If you currently have DefaultSimilarityFactory explicitly refrenced in your schema.xml, you will now get
+ a warning urging you to edit your config to use the functionally identical ClassicSimilarityFactory.
+ DefaultSimilarityFactory will be removed completely in Solr 6. See SOLR-8239 for more details.
+
* SOLR-7859: The following APIs are now deprecated:
- SolrCore.getStartTime: Use SolrCore.getStartTimeStamp instead.
- SolrIndexSearcher.getOpenTime: Use SolrIndexSearcher.getOpenTimeStamp instead.
@@ -443,6 +449,8 @@ Other Changes
* SOLR-8147: contrib/analytics FieldFacetAccumulator now throws IOException instead of SolrException
(Scott Stults via Christine Poerschke)
+* SOLR-8239: Added ClassicSimilarityFactory, marked DefaultSimilarityFactory as deprecated. (hossman)
+
================== 5.3.1 ==================
Bug Fixes
diff --git a/solr/contrib/clustering/src/test-files/clustering/solr/collection1/conf/schema.xml b/solr/contrib/clustering/src/test-files/clustering/solr/collection1/conf/schema.xml
index 1fdf3b56275..39b6b168768 100644
--- a/solr/contrib/clustering/src/test-files/clustering/solr/collection1/conf/schema.xml
+++ b/solr/contrib/clustering/src/test-files/clustering/solr/collection1/conf/schema.xml
@@ -332,19 +332,4 @@
-
-
-
-
-
-
diff --git a/solr/contrib/uima/src/test-files/uima/solr/collection1/conf/schema.xml b/solr/contrib/uima/src/test-files/uima/solr/collection1/conf/schema.xml
index 6bf2a54526a..483fa2aea8b 100644
--- a/solr/contrib/uima/src/test-files/uima/solr/collection1/conf/schema.xml
+++ b/solr/contrib/uima/src/test-files/uima/solr/collection1/conf/schema.xml
@@ -607,23 +607,4 @@
-->
-
-
-
-
-
-
-
diff --git a/solr/contrib/uima/src/test-files/uima/uima-tokenizers-schema.xml b/solr/contrib/uima/src/test-files/uima/uima-tokenizers-schema.xml
index dfba444f80e..2ab88082353 100644
--- a/solr/contrib/uima/src/test-files/uima/uima-tokenizers-schema.xml
+++ b/solr/contrib/uima/src/test-files/uima/uima-tokenizers-schema.xml
@@ -611,22 +611,4 @@
-
-
-
-
-
-
diff --git a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
index 5fecdbe5b5a..966c295fa43 100644
--- a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
+++ b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
@@ -65,7 +65,7 @@ import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.response.SchemaXmlWriter;
import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.search.similarities.DefaultSimilarityFactory;
+import org.apache.solr.search.similarities.ClassicSimilarityFactory;
import org.apache.solr.util.DOMUtil;
import org.apache.solr.util.plugin.SolrCoreAware;
import org.slf4j.Logger;
@@ -497,7 +497,7 @@ public class IndexSchema {
Node node = (Node) xpath.evaluate(expression, document, XPathConstants.NODE);
similarityFactory = readSimilarity(loader, node);
if (similarityFactory == null) {
- similarityFactory = new DefaultSimilarityFactory();
+ similarityFactory = new ClassicSimilarityFactory();
final NamedList similarityParams = new NamedList();
Version luceneVersion = getDefaultLuceneMatchVersion();
similarityFactory.init(SolrParams.toSolrParams(similarityParams));
diff --git a/solr/core/src/java/org/apache/solr/search/similarities/ClassicSimilarityFactory.java b/solr/core/src/java/org/apache/solr/search/similarities/ClassicSimilarityFactory.java
new file mode 100644
index 00000000000..a8cf6abea43
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/search/similarities/ClassicSimilarityFactory.java
@@ -0,0 +1,65 @@
+package org.apache.solr.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 org.apache.lucene.search.similarities.ClassicSimilarity;
+import org.apache.lucene.search.similarities.Similarity;
+import org.apache.lucene.search.similarities.TFIDFSimilarity; // javadoc
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.schema.SimilarityFactory;
+
+/**
+ * Factory for {@link ClassicSimilarity}
+ *
+ * ClassicSimilarity is Lucene's original scoring implementation, based
+ * upon the Vector Space Model.
+ *
+ * Optional settings:
+ *
+ * - discountOverlaps (bool): Sets
+ * {@link ClassicSimilarity#setDiscountOverlaps(boolean)}
+ *
+ * @see TFIDFSimilarity
+ * @lucene.experimental
+ */
+public class ClassicSimilarityFactory extends SimilarityFactory {
+
+ /** Init param name for specifying the value to use in
+ * {@link ClassicSimilarity#setDiscountOverlaps(boolean)}
+ */
+ public static final String DISCOUNT_OVERLAPS = "discountOverlaps";
+
+ /**
+ * Controls the value of {@link ClassicSimilarity#setDiscountOverlaps(boolean)}
+ * on newly constructed instances of {@link ClassicSimilarity}
+ */
+ protected boolean discountOverlaps = true;
+
+ @Override
+ public void init(SolrParams params) {
+ super.init(params);
+ discountOverlaps = params.getBool(DISCOUNT_OVERLAPS, true);
+ }
+
+ @Override
+ public Similarity getSimilarity() {
+ ClassicSimilarity sim = new ClassicSimilarity();
+ sim.setDiscountOverlaps(discountOverlaps);
+ return sim;
+ }
+}
diff --git a/solr/core/src/java/org/apache/solr/search/similarities/DefaultSimilarityFactory.java b/solr/core/src/java/org/apache/solr/search/similarities/DefaultSimilarityFactory.java
index 4b3cc38ac0b..e3b18f5c902 100644
--- a/solr/core/src/java/org/apache/solr/search/similarities/DefaultSimilarityFactory.java
+++ b/solr/core/src/java/org/apache/solr/search/similarities/DefaultSimilarityFactory.java
@@ -16,50 +16,29 @@ package org.apache.solr.search.similarities;
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-import org.apache.lucene.search.similarities.ClassicSimilarity;
import org.apache.lucene.search.similarities.Similarity;
-import org.apache.lucene.search.similarities.TFIDFSimilarity; // javadoc
+
import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.schema.SimilarityFactory;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
- * Factory for {@link ClassicSimilarity}
- *
- * ClassicSimilarity is Lucene's original scoring implementation, based
- * upon the Vector Space Model.
- *
- * Optional settings:
- *
- * - discountOverlaps (bool): Sets
- * {@link ClassicSimilarity#setDiscountOverlaps(boolean)}
- *
- * @see TFIDFSimilarity
- * @lucene.experimental
+ * @deprecated This class has been renamed to ClassicSimilarityFactory
to reflect the renaming of the underlying Similarity returned.
+ *
+ * @see ClassicSimilarityFactory
*/
-public class DefaultSimilarityFactory extends SimilarityFactory {
-
- /** Init param name for specifying the value to use in
- * {@link ClassicSimilarity#setDiscountOverlaps(boolean)}
- */
- public static final String DISCOUNT_OVERLAPS = "discountOverlaps";
-
- /**
- * Controls the value of {@link ClassicSimilarity#setDiscountOverlaps(boolean)}
- * on newly constructed instances of {@link ClassicSimilarity}
- */
- protected boolean discountOverlaps = true;
+@Deprecated
+public class DefaultSimilarityFactory extends ClassicSimilarityFactory {
+
+ public static final Logger log = LoggerFactory.getLogger(DefaultSimilarityFactory.class);
@Override
public void init(SolrParams params) {
super.init(params);
- discountOverlaps = params.getBool(DISCOUNT_OVERLAPS, true);
- }
-
- @Override
- public Similarity getSimilarity() {
- ClassicSimilarity sim = new ClassicSimilarity();
- sim.setDiscountOverlaps(discountOverlaps);
- return sim;
+ log.warn("DefaultSimilarityFactory has been renamed and deprecated. " +
+ "Please update your configuration file to refer to ClassicSimilarityFactory instead");
}
+
}
diff --git a/solr/core/src/java/org/apache/solr/search/similarities/SchemaSimilarityFactory.java b/solr/core/src/java/org/apache/solr/search/similarities/SchemaSimilarityFactory.java
index 2e377a1605c..390a964e404 100644
--- a/solr/core/src/java/org/apache/solr/search/similarities/SchemaSimilarityFactory.java
+++ b/solr/core/src/java/org/apache/solr/search/similarities/SchemaSimilarityFactory.java
@@ -35,9 +35,9 @@ import org.apache.solr.util.plugin.SolrCoreAware;
* NOTE: Users should be aware that in addition to supporting
* Similarity
configurations specified on individual
* field types, this factory also differs in behavior from
- * {@link DefaultSimilarityFactory} because of other differences in the
+ * {@link ClassicSimilarityFactory} because of other differences in the
* implementations of PerFieldSimilarityWrapper
and
- * DefaultSimilarity
- notably in methods such as
+ * {@link ClassicSimilarity} - notably in methods such as
* {@link Similarity#coord} and {@link Similarity#queryNorm}.
*
*
diff --git a/solr/core/src/java/org/apache/solr/search/similarities/SweetSpotSimilarityFactory.java b/solr/core/src/java/org/apache/solr/search/similarities/SweetSpotSimilarityFactory.java
index 42ac4e96413..ac4976d4483 100644
--- a/solr/core/src/java/org/apache/solr/search/similarities/SweetSpotSimilarityFactory.java
+++ b/solr/core/src/java/org/apache/solr/search/similarities/SweetSpotSimilarityFactory.java
@@ -34,7 +34,7 @@ import static org.apache.solr.common.SolrException.ErrorCode.*;
*
*
* In addition to the discountOverlaps
init param supported by
- * {@link DefaultSimilarityFactory} The following sets of init params are
+ * {@link ClassicSimilarityFactory} The following sets of init params are
* supported by this factory:
*
*
@@ -106,7 +106,7 @@ import static org.apache.solr.common.SolrException.ErrorCode.*;
* SweetSpotSimilarity
for SVG diagrams showing how the
* each function behaves with various settings/inputs.
*/
-public class SweetSpotSimilarityFactory extends DefaultSimilarityFactory {
+public class SweetSpotSimilarityFactory extends ClassicSimilarityFactory {
private SweetSpotSimilarity sim = null;
@Override
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-copyfield-test.xml b/solr/core/src/test-files/solr/collection1/conf/schema-copyfield-test.xml
index c8af043e470..d759dca3c1d 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema-copyfield-test.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema-copyfield-test.xml
@@ -459,10 +459,4 @@
-
-
-
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-required-fields.xml b/solr/core/src/test-files/solr/collection1/conf/schema-required-fields.xml
index f048e404782..c34f34f2fb0 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema-required-fields.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema-required-fields.xml
@@ -413,10 +413,4 @@
-
-
-
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-tfidf.xml b/solr/core/src/test-files/solr/collection1/conf/schema-tfidf.xml
index eacea9009a8..f9bbde982b4 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema-tfidf.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema-tfidf.xml
@@ -16,34 +16,46 @@
limitations under the License.
-->
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+ false
+
+
-
-
-
-
- false
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+ false
+
+
+
+
text
id
diff --git a/solr/core/src/test/org/apache/solr/rest/schema/TestSchemaSimilarityResource.java b/solr/core/src/test/org/apache/solr/rest/schema/TestSchemaSimilarityResource.java
index b649e811194..64aac1a206e 100644
--- a/solr/core/src/test/org/apache/solr/rest/schema/TestSchemaSimilarityResource.java
+++ b/solr/core/src/test/org/apache/solr/rest/schema/TestSchemaSimilarityResource.java
@@ -24,7 +24,7 @@ public class TestSchemaSimilarityResource extends SolrRestletTestBase {
public void testGetSchemaSimilarity() throws Exception {
assertQ("/schema/similarity?indent=on&wt=xml",
"count(/response/lst[@name='similarity']) = 1",
- "/response/lst[@name='similarity']/str[@name='class'][.='org.apache.solr.search.similarities.DefaultSimilarityFactory']");
+ "/response/lst[@name='similarity']/str[@name='class'][.='org.apache.solr.search.similarities.ClassicSimilarityFactory']");
}
}
diff --git a/solr/core/src/test/org/apache/solr/search/similarities/TestDefaultSimilarityFactory.java b/solr/core/src/test/org/apache/solr/search/similarities/TestClassicSimilarityFactory.java
similarity index 55%
rename from solr/core/src/test/org/apache/solr/search/similarities/TestDefaultSimilarityFactory.java
rename to solr/core/src/test/org/apache/solr/search/similarities/TestClassicSimilarityFactory.java
index 254cb3b15eb..6b9ca9ceb5d 100644
--- a/solr/core/src/test/org/apache/solr/search/similarities/TestDefaultSimilarityFactory.java
+++ b/solr/core/src/test/org/apache/solr/search/similarities/TestClassicSimilarityFactory.java
@@ -22,25 +22,35 @@ import org.apache.lucene.search.similarities.Similarity;
import org.junit.BeforeClass;
/**
- * Tests {@link DefaultSimilarityFactory}
+ * Tests {@link DefaultSimilarityFactory} when specified on a per-fieldtype basis with various init options.
+ * @see SchemaSimilarityFactory
*/
-public class TestDefaultSimilarityFactory extends BaseSimilarityTestCase {
+public class TestClassicSimilarityFactory extends BaseSimilarityTestCase {
@BeforeClass
public static void beforeClass() throws Exception {
initCore("solrconfig-basic.xml","schema-tfidf.xml");
}
- /** default parameters */
+ /** Classic w/ default parameters */
public void testDefaults() throws Exception {
- Similarity sim = getSimilarity("text");
- assertEquals(ClassicSimilarity.class, sim.getClass());
- assertEquals(true, ((ClassicSimilarity)sim).getDiscountOverlaps());
+ ClassicSimilarity sim = getSimilarity("text", ClassicSimilarity.class);
+ assertEquals(true, sim.getDiscountOverlaps());
}
- /** explicit params */
+ /** Classic w/ explicit params */
public void testParams() throws Exception {
- Similarity sim = getSimilarity("text_overlap");
- assertEquals(ClassicSimilarity.class, sim.getClass());
- assertEquals(false, ((ClassicSimilarity)sim).getDiscountOverlaps());
+ ClassicSimilarity sim = getSimilarity("text_overlap", ClassicSimilarity.class);
+ assertEquals(false, sim.getDiscountOverlaps());
+ }
+
+ /** Default w/ default parameters */
+ public void testDefaultWithDefaults() throws Exception {
+ ClassicSimilarity sim = getSimilarity("text__default", ClassicSimilarity.class);
+ assertEquals(true, sim.getDiscountOverlaps());
+ }
+ /** Default w/ explicit params */
+ public void testDefaultWithParams() throws Exception {
+ ClassicSimilarity sim = getSimilarity("text_overlap__default", ClassicSimilarity.class);
+ assertEquals(false, sim.getDiscountOverlaps());
}
}
diff --git a/solr/core/src/test/org/apache/solr/search/similarities/TestNonDefinedSimilarityFactory.java b/solr/core/src/test/org/apache/solr/search/similarities/TestNonDefinedSimilarityFactory.java
index 6e46fa79231..8c2b9e824b8 100644
--- a/solr/core/src/test/org/apache/solr/search/similarities/TestNonDefinedSimilarityFactory.java
+++ b/solr/core/src/test/org/apache/solr/search/similarities/TestNonDefinedSimilarityFactory.java
@@ -22,7 +22,7 @@ import org.apache.lucene.util.Version;
import org.junit.After;
/**
- * Verifies that the default behavior of the implicit {@link DefaultSimilarityFactory}
+ * Verifies that the default behavior of the implicit {@link ClassicSimilarityFactory}
* (ie: no similarity configured in schema.xml at all) is consistnent with
* expectations based on the luceneMatchVersion
* @see SOLR-5561
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/SchemaTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/SchemaTest.java
index 2ea061104d9..9038604d65a 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/SchemaTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/SchemaTest.java
@@ -240,7 +240,7 @@ public class SchemaTest extends RestTestBase {
new SchemaRequest.GlobalSimilarity();
SchemaResponse.GlobalSimilarityResponse globalSimilarityResponse = globalSimilarityRequest.process(getSolrClient());
assertValidSchemaResponse(globalSimilarityResponse);
- assertEquals("org.apache.solr.search.similarities.DefaultSimilarityFactory",
+ assertEquals("org.apache.solr.search.similarities.ClassicSimilarityFactory",
globalSimilarityResponse.getSimilarity().get("class"));
}