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
This commit is contained in:
Chris M. Hostetter 2015-11-05 18:44:13 +00:00
parent 2a24085bcd
commit d207e8c39a
16 changed files with 142 additions and 152 deletions

View File

@ -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

View File

@ -332,4 +332,19 @@
<copyField source="body" dest="text"/>
<copyField source="snippet" dest="text"/>
<!-- Similarity is the scoring routine for each document vs. a query.
A custom similarity may be specified here, but the default is fine
for most applications. -->
<!-- <similarity class="org.apache.lucene.search.DefaultSimilarity"/> -->
<!-- ... OR ...
Specify a SimilarityFactory class name implementation
allowing parameters to be used.
-->
<!--
<similarity class="com.example.solr.CustomSimilarityFactory">
<str name="paramkey">param value</str>
</similarity>
-->
</schema>

View File

@ -607,4 +607,23 @@
-->
<!-- <copyField source="name" dest="alphaNameSort"/> -->
<!--
Similarity is the scoring routine for each document vs. a query. A
custom similarity may be specified here, but the default is fine for
most applications.
-->
<!--
<similarity class="org.apache.lucene.search.DefaultSimilarity"/>
-->
<!--
... OR ... Specify a SimilarityFactory class name implementation
allowing parameters to be used.
-->
<!--
<similarity class="com.example.solr.CustomSimilarityFactory"> <str
name="paramkey">param value</str> </similarity>
-->
</schema>

View File

@ -611,4 +611,22 @@
<!-- <copyField source="name" dest="alphaNameSort"/> -->
<!--
Similarity is the scoring routine for each document vs. a query. A
custom similarity may be specified here, but the default is fine for
most applications.
-->
<!--
<similarity class="org.apache.lucene.search.DefaultSimilarity"/>
-->
<!--
... OR ... Specify a SimilarityFactory class name implementation
allowing parameters to be used.
-->
<!--
<similarity class="com.example.solr.CustomSimilarityFactory"> <str
name="paramkey">param value</str> </similarity>
-->
</schema>

View File

@ -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));

View File

@ -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}
* <p>
* ClassicSimilarity is Lucene's original scoring implementation, based
* upon the Vector Space Model.
* <p>
* Optional settings:
* <ul>
* <li>discountOverlaps (bool): Sets
* {@link ClassicSimilarity#setDiscountOverlaps(boolean)}</li>
* </ul>
* @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;
}
}

View File

@ -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 <code>ClassicSimilarityFactory</code> to reflect the renaming of the underlying Similarity returned.
*
* @see ClassicSimilarityFactory
* Factory for {@link ClassicSimilarity}
* <p>
* ClassicSimilarity is Lucene's original scoring implementation, based
* upon the Vector Space Model.
* <p>
* Optional settings:
* <ul>
* <li>discountOverlaps (bool): Sets
* {@link ClassicSimilarity#setDiscountOverlaps(boolean)}</li>
* </ul>
* @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;
}
}

View File

@ -35,9 +35,9 @@ import org.apache.solr.util.plugin.SolrCoreAware;
* <b>NOTE:</b> Users should be aware that in addition to supporting
* <code>Similarity</code> 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 <code>PerFieldSimilarityWrapper</code> and
* {@link ClassicSimilarity} - notably in methods such as
* <code>DefaultSimilarity</code> - notably in methods such as
* {@link Similarity#coord} and {@link Similarity#queryNorm}.
* </p>
*

View File

@ -34,7 +34,7 @@ import static org.apache.solr.common.SolrException.ErrorCode.*;
* </p>
* <p>
* In addition to the <code>discountOverlaps</code> 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:
* </p>
* <ul>
@ -106,7 +106,7 @@ import static org.apache.solr.common.SolrException.ErrorCode.*;
* <code>SweetSpotSimilarity</code> 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

View File

@ -459,4 +459,10 @@
<copyField source="*" dest="catchall_t"/>
<!-- Similarity is the scoring routine for each document vs a query.
A custom similarity may be specified here, but the default is fine
for most applications.
-->
<!-- <similarity class="org.apache.lucene.search.similarities.DefaultSimilarity"/> -->
</schema>

View File

@ -413,4 +413,10 @@
<copyField source="*_t" dest="text"/>
<!-- Similarity is the scoring routine for each document vs a query.
A custom similarity may be specified here, but the default is fine
for most applications.
-->
<!-- <similarity class="org.apache.lucene.search.similarities.DefaultSimilarity"/> -->
</schema>

View File

@ -16,46 +16,34 @@
limitations under the License.
-->
<!-- Test schema file for ClassicSimilarityFactory specified on a per-fieldtype basis
See TestClassicSimilarityFactory
-->
<!-- Test schema file for DefaultSimilarityFactory -->
<schema name="test" version="1.0">
<types>
<fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
<!-- testDefaults -->
<field name="text" type="text" indexed="true" stored="false"/>
<fieldType name="text" class="solr.TextField">
<analyzer class="org.apache.lucene.analysis.standard.StandardAnalyzer"/>
<similarity class="solr.ClassicSimilarityFactory"/>
</fieldType>
<!-- testParams -->
<field name="text_overlap" type="text_overlap" indexed="true" stored="false"/>
<fieldType name="text_overlap" class="solr.TextField">
<analyzer class="org.apache.lucene.analysis.standard.StandardAnalyzer"/>
<similarity class="solr.ClassicSimilarityFactory">
<bool name="discountOverlaps">false</bool>
</similarity>
</fieldType>
<!-- TF/IDF -->
<fieldType name="text" class="solr.TextField">
<analyzer class="org.apache.lucene.analysis.standard.StandardAnalyzer"/>
<similarity class="solr.DefaultSimilarityFactory"/>
</fieldType>
<!-- testDefaultWithDefaults -->
<field name="text__default" type="text__default" indexed="true" stored="false"/>
<fieldType name="text__default" class="solr.TextField">
<analyzer class="org.apache.lucene.analysis.standard.StandardAnalyzer"/>
<similarity class="solr.DefaultSimilarityFactory"/>
</fieldType>
<!-- testDefaultWithParams -->
<field name="text_overlap__default" type="text_overlap__default" indexed="true" stored="false"/>
<fieldType name="text_overlap__default" class="solr.TextField">
<analyzer class="org.apache.lucene.analysis.standard.StandardAnalyzer"/>
<similarity class="solr.DefaultSimilarityFactory">
<bool name="discountOverlaps">false</bool>
</similarity>
</fieldType>
<!-- TF/IDF -->
<fieldType name="text_overlap" class="solr.TextField">
<analyzer class="org.apache.lucene.analysis.standard.StandardAnalyzer"/>
<similarity class="solr.DefaultSimilarityFactory">
<bool name="discountOverlaps">false</bool>
</similarity>
</fieldType>
</types>
<fields>
<field name="id" type="int" indexed="true" stored="true" multiValued="false" required="false"/>
<field name="text" type="text" indexed="true" stored="false"/>
<field name="text_overlap" type="text_overlap" indexed="true" stored="false"/>
</fields>
<field name="id" type="int" indexed="true" stored="true" multiValued="false" required="false"/>
<fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
<defaultSearchField>text</defaultSearchField>
<uniqueKey>id</uniqueKey>
<similarity class="solr.SchemaSimilarityFactory"/>

View File

@ -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']");
}
}

View File

@ -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());
}
}

View File

@ -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 <a href="https://issues.apache.org/jira/browse/SOLR-5561">SOLR-5561</a>

View File

@ -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"));
}