From d207e8c39a9025ccbfca68fbaa90525bf8f5c8b4 Mon Sep 17 00:00:00 2001
From: "Chris M. Hostetter"
Date: Thu, 5 Nov 2015 18:44:13 +0000
Subject: [PATCH] SOLR-8239: reverting r1712840 from trunk -- backport to 5x
was more complicated then I expected because aparently DefaultSimilarity
deprecation with ClassicSimilarity was never backported? want to
clarify/resolve that before moving forward here
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1712845 13f79535-47bb-0310-9956-ffa450edef68
---
solr/CHANGES.txt | 8 ---
.../solr/collection1/conf/schema.xml | 15 +++++
.../uima/solr/collection1/conf/schema.xml | 19 ++++++
.../uima/uima-tokenizers-schema.xml | 18 +++++
.../org/apache/solr/schema/IndexSchema.java | 4 +-
.../ClassicSimilarityFactory.java | 65 -------------------
.../DefaultSimilarityFactory.java | 51 ++++++++++-----
.../similarities/SchemaSimilarityFactory.java | 4 +-
.../SweetSpotSimilarityFactory.java | 4 +-
.../conf/schema-copyfield-test.xml | 6 ++
.../conf/schema-required-fields.xml | 6 ++
.../solr/collection1/conf/schema-tfidf.xml | 58 +++++++----------
.../schema/TestSchemaSimilarityResource.java | 2 +-
...java => TestDefaultSimilarityFactory.java} | 30 +++------
.../TestNonDefinedSimilarityFactory.java | 2 +-
.../solr/client/solrj/request/SchemaTest.java | 2 +-
16 files changed, 142 insertions(+), 152 deletions(-)
delete mode 100644 solr/core/src/java/org/apache/solr/search/similarities/ClassicSimilarityFactory.java
rename solr/core/src/test/org/apache/solr/search/similarities/{TestClassicSimilarityFactory.java => TestDefaultSimilarityFactory.java} (55%)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 0167c2ecc35..261ca5b8a9d 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -140,12 +140,6 @@ 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.
@@ -446,8 +440,6 @@ 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 39b6b168768..1fdf3b56275 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,4 +332,19 @@
+
+
+
+
+
+
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 483fa2aea8b..6bf2a54526a 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,4 +607,23 @@
-->
+
+
+
+
+
+
+
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 2ab88082353..dfba444f80e 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,4 +611,22 @@
+
+
+
+
+
+
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 966c295fa43..5fecdbe5b5a 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.ClassicSimilarityFactory;
+import org.apache.solr.search.similarities.DefaultSimilarityFactory;
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 ClassicSimilarityFactory();
+ similarityFactory = new DefaultSimilarityFactory();
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
deleted file mode 100644
index a8cf6abea43..00000000000
--- a/solr/core/src/java/org/apache/solr/search/similarities/ClassicSimilarityFactory.java
+++ /dev/null
@@ -1,65 +0,0 @@
-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 e3b18f5c902..4b3cc38ac0b 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,29 +16,50 @@ 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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
+import org.apache.solr.schema.SimilarityFactory;
/**
- * @deprecated This class has been renamed to ClassicSimilarityFactory
to reflect the renaming of the underlying Similarity returned.
- *
- * @see ClassicSimilarityFactory
+ * 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
-public class DefaultSimilarityFactory extends ClassicSimilarityFactory {
-
- public static final Logger log = LoggerFactory.getLogger(DefaultSimilarityFactory.class);
+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;
@Override
public void init(SolrParams params) {
super.init(params);
- log.warn("DefaultSimilarityFactory has been renamed and deprecated. " +
- "Please update your configuration file to refer to ClassicSimilarityFactory instead");
+ 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/SchemaSimilarityFactory.java b/solr/core/src/java/org/apache/solr/search/similarities/SchemaSimilarityFactory.java
index 390a964e404..2e377a1605c 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 ClassicSimilarityFactory} because of other differences in the
+ * {@link DefaultSimilarityFactory} because of other differences in the
* implementations of PerFieldSimilarityWrapper
and
- * {@link ClassicSimilarity} - notably in methods such as
+ * DefaultSimilarity
- 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 ac4976d4483..42ac4e96413 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 ClassicSimilarityFactory} The following sets of init params are
+ * {@link DefaultSimilarityFactory} 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 ClassicSimilarityFactory {
+public class SweetSpotSimilarityFactory extends DefaultSimilarityFactory {
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 d759dca3c1d..c8af043e470 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,4 +459,10 @@
+
+
+
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 c34f34f2fb0..f048e404782 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,4 +413,10 @@
+
+
+
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 f9bbde982b4..eacea9009a8 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,46 +16,34 @@
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 64aac1a206e..b649e811194 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.ClassicSimilarityFactory']");
+ "/response/lst[@name='similarity']/str[@name='class'][.='org.apache.solr.search.similarities.DefaultSimilarityFactory']");
}
}
diff --git a/solr/core/src/test/org/apache/solr/search/similarities/TestClassicSimilarityFactory.java b/solr/core/src/test/org/apache/solr/search/similarities/TestDefaultSimilarityFactory.java
similarity index 55%
rename from solr/core/src/test/org/apache/solr/search/similarities/TestClassicSimilarityFactory.java
rename to solr/core/src/test/org/apache/solr/search/similarities/TestDefaultSimilarityFactory.java
index 6b9ca9ceb5d..254cb3b15eb 100644
--- a/solr/core/src/test/org/apache/solr/search/similarities/TestClassicSimilarityFactory.java
+++ b/solr/core/src/test/org/apache/solr/search/similarities/TestDefaultSimilarityFactory.java
@@ -22,35 +22,25 @@ import org.apache.lucene.search.similarities.Similarity;
import org.junit.BeforeClass;
/**
- * Tests {@link DefaultSimilarityFactory} when specified on a per-fieldtype basis with various init options.
- * @see SchemaSimilarityFactory
+ * Tests {@link DefaultSimilarityFactory}
*/
-public class TestClassicSimilarityFactory extends BaseSimilarityTestCase {
+public class TestDefaultSimilarityFactory extends BaseSimilarityTestCase {
@BeforeClass
public static void beforeClass() throws Exception {
initCore("solrconfig-basic.xml","schema-tfidf.xml");
}
- /** Classic w/ default parameters */
+ /** default parameters */
public void testDefaults() throws Exception {
- ClassicSimilarity sim = getSimilarity("text", ClassicSimilarity.class);
- assertEquals(true, sim.getDiscountOverlaps());
+ Similarity sim = getSimilarity("text");
+ assertEquals(ClassicSimilarity.class, sim.getClass());
+ assertEquals(true, ((ClassicSimilarity)sim).getDiscountOverlaps());
}
- /** Classic w/ explicit params */
+ /** explicit params */
public void testParams() throws Exception {
- 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());
+ Similarity sim = getSimilarity("text_overlap");
+ assertEquals(ClassicSimilarity.class, sim.getClass());
+ assertEquals(false, ((ClassicSimilarity)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 8c2b9e824b8..6e46fa79231 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 ClassicSimilarityFactory}
+ * Verifies that the default behavior of the implicit {@link DefaultSimilarityFactory}
* (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 9038604d65a..2ea061104d9 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.ClassicSimilarityFactory",
+ assertEquals("org.apache.solr.search.similarities.DefaultSimilarityFactory",
globalSimilarityResponse.getSimilarity().get("class"));
}