diff --git a/CHANGES.txt b/CHANGES.txt index d9a4b109f9f..c19ef7b00b2 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -583,6 +583,8 @@ Bug Fixes 49. SOLR-589: Improved handling of badly formated query strings (Sean Timm via Otis Gospodnetic) +50. SOLR-749: Allow QParser and ValueSourceParsers to be extended with same name (hossman, gsingers) + Other Changes 1. SOLR-135: Moved common classes to org.apache.solr.common and altered the build scripts to make two jars: apache-solr-1.3.jar and diff --git a/src/java/org/apache/solr/core/SolrCore.java b/src/java/org/apache/solr/core/SolrCore.java index 2aa480768cc..0f1e6566db1 100644 --- a/src/java/org/apache/solr/core/SolrCore.java +++ b/src/java/org/apache/solr/core/SolrCore.java @@ -1339,10 +1339,12 @@ public final class SolrCore implements SolrInfoMBean { for (int i=0; i clazz = (Class)QParserPlugin.standardPlugins[i+1]; - QParserPlugin plugin = clazz.newInstance(); - qParserPlugins.put(name, plugin); - plugin.init(null); + if (null == qParserPlugins.get(name)) { + Class clazz = (Class)QParserPlugin.standardPlugins[i+1]; + QParserPlugin plugin = clazz.newInstance(); + qParserPlugins.put(name, plugin); + plugin.init(null); + } } catch (Exception e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e); } @@ -1371,9 +1373,11 @@ public final class SolrCore implements SolrInfoMBean { for (Map.Entry entry : ValueSourceParser.standardValueSourceParsers.entrySet()) { try { String name = entry.getKey(); - ValueSourceParser valueSourceParser = entry.getValue(); - valueSourceParsers.put(name, valueSourceParser); - valueSourceParser.init(null); + if (null == valueSourceParsers.get(name)) { + ValueSourceParser valueSourceParser = entry.getValue(); + valueSourceParsers.put(name, valueSourceParser); + valueSourceParser.init(null); + } } catch (Exception e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e); } diff --git a/src/test/org/apache/solr/core/DummyValueSourceParser.java b/src/test/org/apache/solr/core/DummyValueSourceParser.java new file mode 100644 index 00000000000..96f27c8689e --- /dev/null +++ b/src/test/org/apache/solr/core/DummyValueSourceParser.java @@ -0,0 +1,55 @@ +package org.apache.solr.core; +/** + * 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.queryParser.ParseException; +import org.apache.solr.common.util.NamedList; +import org.apache.solr.search.FunctionQParser; +import org.apache.solr.search.ValueSourceParser; +import org.apache.solr.search.function.DocValues; +import org.apache.solr.search.function.SimpleFloatFunction; +import org.apache.solr.search.function.ValueSource; + + +/** + * Mock ValueSource parser that doesn't do much of anything + * + **/ +public class DummyValueSourceParser extends ValueSourceParser { + private NamedList args; + + public void init(NamedList args) { + this.args = args; + } + + public ValueSource parse(FunctionQParser fp) throws ParseException { + ValueSource source = fp.parseValueSource(); + ValueSource result = new SimpleFloatFunction(source) { + protected String name() { + return "foo"; + } + + protected float func(int doc, DocValues vals) { + float result = 0; + return result; + } + }; + return result; + } + + +} diff --git a/src/test/org/apache/solr/core/SOLR749Test.java b/src/test/org/apache/solr/core/SOLR749Test.java new file mode 100644 index 00000000000..6507f2d3bfb --- /dev/null +++ b/src/test/org/apache/solr/core/SOLR749Test.java @@ -0,0 +1,49 @@ +package org.apache.solr.core; +/** + * 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.solr.util.AbstractSolrTestCase; +import org.apache.solr.search.QParserPlugin; +import org.apache.solr.search.FooQParserPlugin; +import org.apache.solr.search.ValueSourceParser; + + +/** + * Test for https://issues.apache.org/jira/browse/SOLR-749 + * + **/ +public class SOLR749Test extends AbstractSolrTestCase{ + public String getSchemaFile() { + return "schema.xml"; + } + + public String getSolrConfigFile() { + return "solrconfig-SOLR-749.xml"; + } + + public void testConstruction() throws Exception { + SolrCore core = h.getCore(); + assertTrue("core is null and it shouldn't be", core != null); + QParserPlugin parserPlugin = core.getQueryPlugin(QParserPlugin.DEFAULT_QTYPE); + assertTrue("parserPlugin is null and it shouldn't be", parserPlugin != null); + assertTrue("parserPlugin is not an instanceof " + FooQParserPlugin.class, parserPlugin instanceof FooQParserPlugin); + + ValueSourceParser vsp = core.getValueSourceParser("boost"); + assertTrue("vsp is null and it shouldn't be", vsp != null); + assertTrue("vsp is not an instanceof " + DummyValueSourceParser.class, vsp instanceof DummyValueSourceParser); + } +} diff --git a/src/test/test-files/solr/conf/solrconfig-SOLR-749.xml b/src/test/test-files/solr/conf/solrconfig-SOLR-749.xml new file mode 100644 index 00000000000..aed5c47e3fd --- /dev/null +++ b/src/test/test-files/solr/conf/solrconfig-SOLR-749.xml @@ -0,0 +1,419 @@ + + + + + + + + + + + + ${solr.data.dir:./solr/data} + + + + + false + 10 + + + + 32 + 2147483647 + 10000 + 1000 + 10000 + + + false + + + org.apache.lucene.index.LogByteSizeMergePolicy + + + org.apache.lucene.index.ConcurrentMergeScheduler + + 1000 + 10000 + + single + + + + + false + 10 + 32 + 2147483647 + 10000 + + true + + + + + + + + + + + + + + + + + 1024 + + + + + + + + + + + true + + + + + true + + 10 + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + 0.01 + + text^0.5 features_t^1.0 subject^1.4 title_stemmed^2.0 + + + text^0.2 features_t^1.1 subject^1.4 title_stemmed^2.0 title^1.5 + + + ord(weight)^0.5 recip(rord(iind),1,1000,1000)^0.3 + + + 3<-1 5<-2 6<90% + + 100 + + + + *:* + 0.01 + + text^0.5 features_t^1.0 subject^1.4 title_stemmed^2.0 + + + text^0.2 features_t^1.1 subject^1.4 title_stemmed^2.0 title^1.5 + + + ord(weight)^0.5 recip(rord(iind),1,1000,1000)^0.3 + + + 3<-1 5<-2 6<90% + + 100 + + + + 1000 + 1.4142135 + 12 + foo + + + sqrt 2 + log 10 + + + + + + + + 4 + true + text,name,subject,title,whitetok + + + + + + + 4 + true + text,name,subject,title,whitetok + + + + + + false + + + + + string + elevate.xml + + + + + explicit + + + elevate + + + + + lowerfilt + + + default + lowerfilt + spellchecker1 + true + + + + jarowinkler + lowerfilt + + org.apache.lucene.search.spell.JaroWinklerDistance + spellchecker2 + + + + solr.FileBasedSpellChecker + external + spellings.txt + UTF-8 + spellchecker3 + + + + + + + + + false + + false + + 1 + + + spellcheck + + + + + + + + 100 + + + + + + 70 + + + + + + + ]]> + ]]> + + + + + + + + + + max-age=30, public + + + + + solr + solrconfig.xml scheam.xml admin-extra.html + + + + prefix-${solr.test.sys.prop2}-suffix + + + + + + + +