SOLR-5561: Fix implicit DefaultSimilarityFactory initialization in IndexSchema to properly specify discountOverlap option

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1566842 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2014-02-10 23:26:21 +00:00
parent b2d66a6019
commit 601f536f9a
4 changed files with 88 additions and 2 deletions

View File

@ -71,6 +71,13 @@ Upgrading from Solr 4.6.0
* CloudSolrServer and LBHttpSolrServer no longer declare MalformedURLException
as thrown from their constructors.
* Due to a bug in previous versions the default value of the 'discountOverlap' property
of DefaultSimilarity was not being set appropriately if you were using the implicit
DefaultSimilarityFactory instead of explicitly configuring it. To preserve
consistent behavior for people who upgrade, the implicit behavior is now contingent
on the <luceneMatchVersion/> -- discountOverlap=false for 4.6 and below,
discountOverlap=true for 4.7 and above. See SOLR-5561 for more information.
Detailed Change List
----------------------
@ -305,6 +312,10 @@ Bug Fixes
* SOLR-5709: Highlighting grouped duplicate docs from different shards with
group.limit > 1 throws ArrayIndexOutOfBoundsException. (Steve Rowe)
* SOLR-5561: Fix implicit DefaultSimilarityFactory initialization in IndexSchema
to properly specify discountOverlap option.
(Isaac Hebsh, Ahmet Arslan, Vitaliy Zhovtyuk, hossman)
Optimizations
----------------------

View File

@ -477,6 +477,12 @@ public class IndexSchema {
similarityFactory = readSimilarity(loader, node);
if (similarityFactory == null) {
similarityFactory = new DefaultSimilarityFactory();
final NamedList similarityParams = new NamedList();
Version luceneVersion = getDefaultLuceneMatchVersion();
if (!luceneVersion.onOrAfter(Version.LUCENE_47)) {
similarityParams.add(DefaultSimilarityFactory.DISCOUNT_OVERLAPS, false);
}
similarityFactory.init(SolrParams.toSolrParams(similarityParams));
} else {
isExplicitSimilarity = true;
}

View File

@ -38,12 +38,22 @@ import org.apache.solr.schema.SimilarityFactory;
* @lucene.experimental
*/
public class DefaultSimilarityFactory extends SimilarityFactory {
protected boolean discountOverlaps;
/** Init param name for specifying the value to use in
* {@link DefaultSimilarity#setDiscountOverlaps(boolean)}
*/
public static final String DISCOUNT_OVERLAPS = "discountOverlaps";
/**
* Controls the value of {@link DefaultSimilarity#setDiscountOverlaps(boolean)}
* on newly constructed instances of {@link DefaultSimilarity}
*/
protected boolean discountOverlaps = true;
@Override
public void init(SolrParams params) {
super.init(params);
discountOverlaps = params.getBool("discountOverlaps", true);
discountOverlaps = params.getBool(DISCOUNT_OVERLAPS, true);
}
@Override

View File

@ -0,0 +1,59 @@
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.DefaultSimilarity;
import org.apache.lucene.search.similarities.Similarity;
import org.apache.lucene.util.Version;
import org.junit.After;
/**
* 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>
*/
public class TestNonDefinedSimilarityFactory extends BaseSimilarityTestCase {
@After
public void cleanup() throws Exception {
deleteCore();
}
public void testCurrent() throws Exception {
// no sys prop set, rely on LUCENE_CURRENT
initCore("solrconfig-basic.xml","schema-tiny.xml");
DefaultSimilarity sim = getSimilarity("text", DefaultSimilarity.class);
assertEquals(true, sim.getDiscountOverlaps());
}
public void test47() throws Exception {
System.setProperty("tests.luceneMatchVersion", Version.LUCENE_47.toString());
initCore("solrconfig-basic.xml","schema-tiny.xml");
DefaultSimilarity sim = getSimilarity("text", DefaultSimilarity.class);
assertEquals(true, sim.getDiscountOverlaps());
}
public void test46() throws Exception {
System.setProperty("tests.luceneMatchVersion", Version.LUCENE_46.toString());
initCore("solrconfig-basic.xml","schema-tiny.xml");
DefaultSimilarity sim = getSimilarity("text", DefaultSimilarity.class);
assertEquals(false, sim.getDiscountOverlaps());
}
}