mirror of https://github.com/apache/lucene.git
SOLR-8239: Added ClassicSimilarityFactory, marked DefaultSimilarityFactory as deprecated
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1712979 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7c917a5ed8
commit
ecf410f413
|
@ -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
|
||||
|
|
|
@ -332,19 +332,4 @@
|
|||
<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>
|
||||
|
|
|
@ -607,23 +607,4 @@
|
|||
-->
|
||||
<!-- <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>
|
||||
|
|
|
@ -611,22 +611,4 @@
|
|||
<!-- <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>
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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}
|
||||
* <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;
|
||||
}
|
||||
}
|
|
@ -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}
|
||||
* <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 This class has been renamed to <code>ClassicSimilarityFactory</code> to reflect the renaming of the underlying Similarity returned.
|
||||
*
|
||||
* @see ClassicSimilarityFactory
|
||||
*/
|
||||
public class DefaultSimilarityFactory extends SimilarityFactory {
|
||||
@Deprecated
|
||||
public class DefaultSimilarityFactory extends ClassicSimilarityFactory {
|
||||
|
||||
/** 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;
|
||||
public static final Logger log = LoggerFactory.getLogger(DefaultSimilarityFactory.class);
|
||||
|
||||
@Override
|
||||
public void init(SolrParams params) {
|
||||
super.init(params);
|
||||
discountOverlaps = params.getBool(DISCOUNT_OVERLAPS, true);
|
||||
log.warn("DefaultSimilarityFactory has been renamed and deprecated. " +
|
||||
"Please update your configuration file to refer to ClassicSimilarityFactory instead");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Similarity getSimilarity() {
|
||||
ClassicSimilarity sim = new ClassicSimilarity();
|
||||
sim.setDiscountOverlaps(discountOverlaps);
|
||||
return sim;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 DefaultSimilarityFactory} because of other differences in the
|
||||
* {@link ClassicSimilarityFactory} because of other differences in the
|
||||
* implementations of <code>PerFieldSimilarityWrapper</code> and
|
||||
* <code>DefaultSimilarity</code> - notably in methods such as
|
||||
* {@link ClassicSimilarity} - notably in methods such as
|
||||
* {@link Similarity#coord} and {@link Similarity#queryNorm}.
|
||||
* </p>
|
||||
*
|
||||
|
|
|
@ -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 DefaultSimilarityFactory} The following sets of init params are
|
||||
* {@link ClassicSimilarityFactory} 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 DefaultSimilarityFactory {
|
||||
public class SweetSpotSimilarityFactory extends ClassicSimilarityFactory {
|
||||
private SweetSpotSimilarity sim = null;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -459,10 +459,4 @@
|
|||
|
||||
<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>
|
||||
|
|
|
@ -413,10 +413,4 @@
|
|||
|
||||
<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>
|
||||
|
|
|
@ -16,34 +16,46 @@
|
|||
limitations under the License.
|
||||
-->
|
||||
|
||||
<!-- Test schema file for DefaultSimilarityFactory -->
|
||||
<!-- Test schema file for ClassicSimilarityFactory specified on a per-fieldtype basis
|
||||
See TestClassicSimilarityFactory
|
||||
-->
|
||||
|
||||
<schema name="test" version="1.0">
|
||||
<types>
|
||||
<fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
|
||||
|
||||
<!-- TF/IDF -->
|
||||
<fieldType name="text" class="solr.TextField">
|
||||
<analyzer class="org.apache.lucene.analysis.standard.StandardAnalyzer"/>
|
||||
<similarity class="solr.DefaultSimilarityFactory"/>
|
||||
</fieldType>
|
||||
<!-- 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>
|
||||
|
||||
<!-- 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>
|
||||
<!-- 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>
|
||||
|
||||
</types>
|
||||
<!-- 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>
|
||||
|
||||
<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>
|
||||
<!-- 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>
|
||||
|
||||
<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"/>
|
||||
|
|
|
@ -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']");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
|
@ -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 <a href="https://issues.apache.org/jira/browse/SOLR-5561">SOLR-5561</a>
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue