Apache Lucene open-source search software
SOLR-10584: Remove defaultOperator completely in 7.0
Jan Høydahl66cd20e98a61
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex f42d2acf47c..16c91af094a 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -70,6 +70,9 @@ Upgrading from Solr 6.xquery text will not be split on whitespace before analysis. Seehttps://lucidworks.com/2017/04/18/multi-word-synonyms-solr-adds-query-time-support/ .+* Setting <solrQueryParser defaultOperator="..."/> in schema is no longer allowed and will cause an exception.+ Please use "q.op" parameter on the request instead. For more details, see SOLR-10584.+New Features----------------------* SOLR-9857, SOLR-9858: Collect aggregated metrics from nodes and shard leaders in overseer. (ab)@@ -102,7 +105,7 @@ Bug Fixes* SOLR-10408: v2 API introspect should return useful message for non-existent command (Cao Manh Dat)-* SOLR-10411: v2 Collection API "modify" command specification's replicationFactor property is incorrectly typed as string,+* SOLR-10411: v2 Collection API "modify" command specification's replicationFactor property is incorrectly typed as string,should be integer (Cao Manh Dat)* SOLR-10405: v2 API introspect response contains multiple copies of the experimental format WARNING (Cao Manh Dat)@@ -128,6 +131,7 @@ Optimizations(yonik)Other Changes+----------------------* SOLR-10236: Removed FieldType.getNumericType(). Use getNumberType() instead. (Tomás Fernández Löbbe)* SOLR-10347: Removed index level boost support from "documents" section of the admin UI (Amrit Sarkar via@@ -148,6 +152,9 @@ Other Changes* SOLR-10647: Move the V1 <-> V2 API mapping to SolrJ (noble)+* SOLR-10584: We'll now always throw an exception if defaultOperator is found in schema. This config has+ been deprecated since 3.6, and enforced for new configs since 6.6 (janhoy)+================== 6.7.0 ==================Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.@@ -169,8 +176,8 @@ Other Changes* SOLR-10617: JDBCStream accepts columns of type TIME, DATE & TIMESTAMP as well as CLOBs and decimalnumeric types (James Dyer)--* SOLR-10400: Replace (instanceof TrieFooField || instanceof FooPointField) constructs with++* SOLR-10400: Replace (instanceof TrieFooField || instanceof FooPointField) constructs withFieldType.getNumberType() or SchemaField.getSortField() where appropriate. (hossman, Steve Rowe)================== 6.6.0 ==================@@ -361,9 +368,9 @@ Bug Fixes* SOLR-10549: The new 'large' attribute had been forgotten in /schema/fieldtypes?showDefaults=true (David Smiley)-* SOLR-10615: requests are suspended until SolrDispatchFilter initialization is completed.- After core container shutdown or severe initialization problem Solr responds with- http stauts 404 Not Found instead of 500 as it was before (Mikhail Khludnev)+* SOLR-10615: requests are suspended until SolrDispatchFilter initialization is completed.+ After core container shutdown or severe initialization problem Solr responds with+ http stauts 404 Not Found instead of 500 as it was before (Mikhail Khludnev)* SOLR-8149: Admin UI - Plugins / Stats - active item is now highlighted (Labuzov Dmitriy via janhoy)@@ -438,9 +445,9 @@ Other Changes* SOLR-10601: StreamExpressionParser should handle white space around = in named parameters (Joel Bernstein)-* SOLR-10614: Static fields have turned to instance's field in SimplePostTool.+* SOLR-10614: Static fields have turned to instance's field in SimplePostTool.Enabled TestSolrCLIRunExample.testTechproductsExample(). (Andrey Kudryavtsev, Mikhail Khludnev)-+* SOLR-10522: Revert SpellCheckComponent response format change from SOLR-9972 (rel. 6.5.0). While thiswas an improvement for the json "arrntv" format, it caused problems for the default json format.(James Dyer, reported by Nikita Pchelintsev)diff --git a/solr/core/src/java/org/apache/solr/handler/SchemaHandler.java b/solr/core/src/java/org/apache/solr/handler/SchemaHandler.javaindex f3e503e0cd3..38f29a7cd35 100644--- a/solr/core/src/java/org/apache/solr/handler/SchemaHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/SchemaHandler.java@@ -146,12 +146,6 @@ public class SchemaHandler extends RequestHandlerBase implements SolrCoreAware,rsp.add(IndexSchema.DEFAULT_SEARCH_FIELD, defaultSearchFieldName);break;}- case "/schema/solrqueryparser": {- SimpleOrderedMap<Object> props = new SimpleOrderedMap<>();- props.add(IndexSchema.DEFAULT_OPERATOR, req.getSchema().getQueryParserDefaultOperator());- rsp.add(IndexSchema.SOLR_QUERY_PARSER, props);- break;- }case "/schema/zkversion": {int refreshIfBelowVersion = -1;Object refreshParam = req.getParams().get("refreshIfBelowVersion");@@ -175,10 +169,6 @@ public class SchemaHandler extends RequestHandlerBase implements SolrCoreAware,rsp.add("zkversion", zkVersion);break;}- case "/schema/solrqueryparser/defaultoperator": {- rsp.add(IndexSchema.DEFAULT_OPERATOR, req.getSchema().getQueryParserDefaultOperator());- break;- }default: {List<String> parts = StrUtils.splitSmart(path, '/');if (parts.get(0).isEmpty()) parts.remove(0);diff --git a/solr/core/src/java/org/apache/solr/response/SchemaXmlWriter.java b/solr/core/src/java/org/apache/solr/response/SchemaXmlWriter.javaindex a38fe364eaf..580157528b0 100644--- a/solr/core/src/java/org/apache/solr/response/SchemaXmlWriter.java+++ b/solr/core/src/java/org/apache/solr/response/SchemaXmlWriter.java@@ -103,10 +103,6 @@ public class SchemaXmlWriter extends TextResponseWriter {closeStartTag(false);writer.write(val.toString());endTag(IndexSchema.DEFAULT_SEARCH_FIELD, false);- } else if (schemaPropName.equals(IndexSchema.SOLR_QUERY_PARSER)) {- openStartTag(IndexSchema.SOLR_QUERY_PARSER);- writeAttr(IndexSchema.DEFAULT_OPERATOR, ((Map<String ,Object>) val).get(IndexSchema.DEFAULT_OPERATOR).toString());- closeStartTag(true);} else if (schemaPropName.equals(IndexSchema.SIMILARITY)) {writeSimilarity((SimpleOrderedMap<Object>) val);} else if (schemaPropName.equals(IndexSchema.FIELD_TYPES)) {diff --git a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java b/solr/core/src/java/org/apache/solr/schema/IndexSchema.javaindex 2ea63d4074b..9a69ec54248 100644--- a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java+++ b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java@@ -94,7 +94,6 @@ import static java.util.Collections.singletonMap;public class IndexSchema {public static final String COPY_FIELD = "copyField";public static final String COPY_FIELDS = COPY_FIELD + "s";- public static final String DEFAULT_OPERATOR = "defaultOperator";public static final String DEFAULT_SCHEMA_FILE = "schema.xml";public static final String DEFAULT_SEARCH_FIELD = "defaultSearchField";public static final String DESTINATION = "dest";@@ -112,7 +111,6 @@ public class IndexSchema {public static final String SCHEMA = "schema";public static final String SIMILARITY = "similarity";public static final String SLASH = "/";- public static final String SOLR_QUERY_PARSER = "solrQueryParser";public static final String SOURCE = "source";public static final String TYPE = "type";public static final String TYPES = "types";@@ -148,9 +146,6 @@ public class IndexSchema {protected List<SchemaAware> schemaAware = new ArrayList<>();protected String defaultSearchFieldName=null;- protected String queryParserDefaultOperator = "OR";- protected boolean isExplicitQueryParserDefaultOperator = false;-protected Map<String, List<CopyField>> copyFieldsMap = new HashMap<>();public Map<String,List<CopyField>> getCopyFieldsMap() { return Collections.unmodifiableMap(copyFieldsMap); }@@ -312,13 +307,6 @@ public class IndexSchema {return defaultSearchFieldName;}- /**- * default operator ("AND" or "OR") for QueryParser- */- public String getQueryParserDefaultOperator() {- return queryParserDefaultOperator;- }-protected SchemaField uniqueKeyField;/**@@ -540,15 +528,10 @@ public class IndexSchema {}// /schema/solrQueryParser/@defaultOperator- expression = stepsToPath(SCHEMA, SOLR_QUERY_PARSER, AT + DEFAULT_OPERATOR);+ expression = stepsToPath(SCHEMA, "solrQueryParser", AT + "defaultOperator");node = (Node) xpath.evaluate(expression, document, XPathConstants.NODE);- if (node==null) {- log.debug("Default query parser operator not set in Schema");- } else {- isExplicitQueryParserDefaultOperator = true;- queryParserDefaultOperator=node.getNodeValue().trim();- log.warn("[{}] query parser default operator is {}. WARNING: Deprecated, please use 'q.op' on request instead.",- coreName, queryParserDefaultOperator);+ if (node != null) {+ throw new SolrException(ErrorCode.SERVER_ERROR, "Setting default operator in schema (solrQueryParser/@defaultOperator) not supported");}// /schema/uniqueKey/text()@@ -1402,9 +1385,6 @@ public class IndexSchema {VERSION(IndexSchema.VERSION, sp -> sp.schema.getVersion()),UNIQUE_KEY(IndexSchema.UNIQUE_KEY, sp -> sp.schema.uniqueKeyFieldName),DEFAULT_SEARCH_FIELD(IndexSchema.DEFAULT_SEARCH_FIELD, sp -> sp.schema.defaultSearchFieldName),- SOLR_QUERY_PARSER(IndexSchema.SOLR_QUERY_PARSER, sp -> sp.schema.isExplicitQueryParserDefaultOperator ?- singletonMap(DEFAULT_OPERATOR, sp.schema.queryParserDefaultOperator) :- null),SIMILARITY(IndexSchema.SIMILARITY, sp -> sp.schema.isExplicitSimilarity ?sp.schema.similarityFactory.getNamedPropertyValues() :null),diff --git a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.javaindex 9bc888dd767..de292fdfb99 100644--- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java+++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java@@ -1358,8 +1358,6 @@ public final class ManagedIndexSchema extends IndexSchema {newSchema.name = name;newSchema.version = version;newSchema.defaultSearchFieldName = defaultSearchFieldName;- newSchema.queryParserDefaultOperator = queryParserDefaultOperator;- newSchema.isExplicitQueryParserDefaultOperator = isExplicitQueryParserDefaultOperator;newSchema.similarity = similarity;newSchema.similarityFactory = similarityFactory;newSchema.isExplicitSimilarity = isExplicitSimilarity;diff --git a/solr/core/src/java/org/apache/solr/search/ComplexPhraseQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/ComplexPhraseQParserPlugin.javaindex 2a00a0989c4..1ce7aed6bb0 100644--- a/solr/core/src/java/org/apache/solr/search/ComplexPhraseQParserPlugin.java+++ b/solr/core/src/java/org/apache/solr/search/ComplexPhraseQParserPlugin.java@@ -156,7 +156,7 @@ public class ComplexPhraseQParserPlugin extends QParserPlugin {lparser.setInOrder(inOrder);- QueryParser.Operator defaultOperator = QueryParsing.getQueryParserDefaultOperator(getReq().getSchema(), getParam(QueryParsing.OP));+ QueryParser.Operator defaultOperator = QueryParsing.parseOP(getParam(QueryParsing.OP));if (QueryParser.Operator.AND.equals(defaultOperator))lparser.setDefaultOperator(org.apache.lucene.queryparser.classic.QueryParser.Operator.AND);diff --git a/solr/core/src/java/org/apache/solr/search/DisMaxQParser.java b/solr/core/src/java/org/apache/solr/search/DisMaxQParser.javaindex efd1c202229..28c80b0d52f 100644--- a/solr/core/src/java/org/apache/solr/search/DisMaxQParser.java+++ b/solr/core/src/java/org/apache/solr/search/DisMaxQParser.java@@ -52,14 +52,13 @@ public class DisMaxQParser extends QParser {* Applies the appropriate default rules for the "mm" param based on the* effective value of the "q.op" param*- * @see QueryParsing#getQueryParserDefaultOperator* @see QueryParsing#OP* @see DisMaxParams#MM*/public static String parseMinShouldMatch(final IndexSchema schema,final SolrParams params) {- org.apache.solr.parser.QueryParser.Operator op = QueryParsing.getQueryParserDefaultOperator- (schema, params.get(QueryParsing.OP));+ org.apache.solr.parser.QueryParser.Operator op = QueryParsing.parseOP(params.get(QueryParsing.OP));+return params.get(DisMaxParams.MM,op.equals(QueryParser.Operator.AND) ? "100%" : "0%");}diff --git a/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java b/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.javaindex 937f77e0255..a68836c39ec 100644--- a/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java+++ b/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java@@ -990,8 +990,7 @@ public class ExtendedDismaxQParser extends QParser {super(parser, defaultField);// Respect the q.op parameter before mm will be applied laterSolrParams defaultParams = SolrParams.wrapDefaults(parser.getLocalParams(), parser.getParams());- QueryParser.Operator defaultOp = QueryParsing.getQueryParserDefaultOperator(- parser.getReq().getSchema(), defaultParams.get(QueryParsing.OP));+ QueryParser.Operator defaultOp = QueryParsing.parseOP(defaultParams.get(QueryParsing.OP));setDefaultOperator(defaultOp);}diff --git a/solr/core/src/java/org/apache/solr/search/LuceneQParser.java b/solr/core/src/java/org/apache/solr/search/LuceneQParser.javaindex 9668d8f8e4a..16b29d3547b 100644--- a/solr/core/src/java/org/apache/solr/search/LuceneQParser.java+++ b/solr/core/src/java/org/apache/solr/search/LuceneQParser.java@@ -44,9 +44,7 @@ public class LuceneQParser extends QParser {}lparser = new SolrQueryParser(this, defaultField);- lparser.setDefaultOperator- (QueryParsing.getQueryParserDefaultOperator(getReq().getSchema(),- getParam(QueryParsing.OP)));+ lparser.setDefaultOperator(QueryParsing.parseOP(getParam(QueryParsing.OP)));lparser.setSplitOnWhitespace(StrUtils.parseBool(getParam(QueryParsing.SPLIT_ON_WHITESPACE), SolrQueryParser.DEFAULT_SPLIT_ON_WHITESPACE));diff --git a/solr/core/src/java/org/apache/solr/search/QueryParsing.java b/solr/core/src/java/org/apache/solr/search/QueryParsing.javaindex da16d86b6e8..4398ac4774a 100644--- a/solr/core/src/java/org/apache/solr/search/QueryParsing.java+++ b/solr/core/src/java/org/apache/solr/search/QueryParsing.java@@ -59,18 +59,15 @@ public class QueryParsing {/**- * Returns the "preferred" default operator for use by Query Parsers,- * based on the settings in the IndexSchema which may be overridden using- * an optional String override value.- *- * @see IndexSchema#getQueryParserDefaultOperator()- * @see #OP+ * Returns the default operator for use by Query Parsers, parsed from the df string+ * @param notUsed is not used, but is there for back compat with 3rd party QParsers+ * @param df the df string from request+ * @deprecated this method is here purely not to break code back compat in 7.x*/- public static QueryParser.Operator getQueryParserDefaultOperator(final IndexSchema sch,- final String override) {- String val = override;- if (null == val) val = sch.getQueryParserDefaultOperator();- return "AND".equals(val) ? QueryParser.Operator.AND : QueryParser.Operator.OR;+ @Deprecated+ public static QueryParser.Operator getQueryParserDefaultOperator(final IndexSchema notUsed,+ final String df) {+ return parseOP(df);}/**@@ -396,4 +393,12 @@ public class QueryParsing {return out;}+ /**+ * Parses default operator string into Operator object+ * @param operator the string from request+ * @return Operator.AND if string equals "AND", else return Operator.OR (default)+ */+ public static QueryParser.Operator parseOP(String operator) {+ return "and".equalsIgnoreCase(operator) ? QueryParser.Operator.AND : QueryParser.Operator.OR;+ }}diff --git a/solr/core/src/java/org/apache/solr/search/SimpleQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/SimpleQParserPlugin.javaindex 2b0098f8cbc..f265d9364ec 100644--- a/solr/core/src/java/org/apache/solr/search/SimpleQParserPlugin.java+++ b/solr/core/src/java/org/apache/solr/search/SimpleQParserPlugin.java@@ -154,7 +154,7 @@ public class SimpleQParserPlugin extends QParserPlugin {parser = new SolrSimpleQueryParser(req.getSchema().getQueryAnalyzer(), queryFields, enabledOps, this, schema);// Set the default operator to be either 'AND' or 'OR' for the query.- QueryParser.Operator defaultOp = QueryParsing.getQueryParserDefaultOperator(req.getSchema(), defaultParams.get(QueryParsing.OP));+ QueryParser.Operator defaultOp = QueryParsing.parseOP(defaultParams.get(QueryParsing.OP));if (defaultOp == QueryParser.Operator.AND) {parser.setDefaultOperator(BooleanClause.Occur.MUST);diff --git a/solr/core/src/resources/apispec/core.SchemaRead.json b/solr/core/src/resources/apispec/core.SchemaRead.jsonindex da62c06c2d1..c90795470b9 100644--- a/solr/core/src/resources/apispec/core.SchemaRead.json+++ b/solr/core/src/resources/apispec/core.SchemaRead.json@@ -11,8 +11,7 @@"/schema/version","/schema/similarity","/schema/solrqueryparser",- "/schema/zkversion",- "/schema/solrqueryparser/defaultoperator"+ "/schema/zkversion"]}}diff --git a/solr/core/src/test-files/solr/collection1/conf/bad-schema-default-operator.xml b/solr/core/src/test-files/solr/collection1/conf/bad-schema-default-operator.xmlnew file mode 100644index 00000000000..3de607c42b3--- /dev/null+++ b/solr/core/src/test-files/solr/collection1/conf/bad-schema-default-operator.xml@@ -0,0 +1,26 @@+<?xml version="1.0" ?>+<!--+ 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.+-->++<schema name="bad-schema-default-operator" version="1.6">+ <fieldType name="string" class="solr.StrField"/>+ <field name="id" type="string" indexed="true" stored="true" multiValued="false" required="false"/>+ <uniqueKey>id</uniqueKey>+ <!-- BEGIN BAD STUFF: not allowed anymore -->+ <solrQueryParser defaultOperator="OR"/>+ <!-- END BAD STUFF -->+</schema>diff --git a/solr/core/src/test/org/apache/solr/rest/schema/TestSolrQueryParserDefaultOperatorResource.java b/solr/core/src/test/org/apache/solr/rest/schema/TestSolrQueryParserDefaultOperatorResource.javadeleted file mode 100644index 064c3ace9e2..00000000000--- a/solr/core/src/test/org/apache/solr/rest/schema/TestSolrQueryParserDefaultOperatorResource.java+++ /dev/null@@ -1,29 +0,0 @@-/*- * 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.- */-package org.apache.solr.rest.schema;-import org.apache.solr.rest.SolrRestletTestBase;-import org.junit.Test;--public class TestSolrQueryParserDefaultOperatorResource extends SolrRestletTestBase {-- @Test- public void testGetDefaultOperator() throws Exception {- assertQ("/schema/solrqueryparser/defaultoperator?indent=on&wt=xml",- "count(/response/str[@name='defaultOperator']) = 1",- "/response/str[@name='defaultOperator'][.='OR']");- }-}diff --git a/solr/core/src/test/org/apache/solr/rest/schema/TestSolrQueryParserResource.java b/solr/core/src/test/org/apache/solr/rest/schema/TestSolrQueryParserResource.javadeleted file mode 100644index d4946ade76f..00000000000--- a/solr/core/src/test/org/apache/solr/rest/schema/TestSolrQueryParserResource.java+++ /dev/null@@ -1,30 +0,0 @@-/*- * 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.- */-package org.apache.solr.rest.schema;-import org.apache.solr.rest.SolrRestletTestBase;-import org.junit.Test;--public class TestSolrQueryParserResource extends SolrRestletTestBase {-- @Test- public void testGetSolrQueryParser() throws Exception {- assertQ("/schema/solrqueryparser?indent=on&wt=xml",- "count(/response/lst[@name='solrQueryParser']) = 1",- "count(/response/lst[@name='solrQueryParser']/str[@name='defaultOperator']) = 1",- "/response/lst[@name='solrQueryParser']/str[@name='defaultOperator'][.='OR']");- }-}diff --git a/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java b/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.javaindex 8d2f93aa40e..e24386b87b2 100644--- a/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java+++ b/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java@@ -127,5 +127,9 @@ public class BadIndexSchemaTest extends AbstractBadConfigTestBase {doTest("bad-schema-sim-default-does-not-exist.xml","ft-does-not-exist");}-++ public void testDefaultOperatorBanned() throws Exception {+ doTest("bad-schema-default-operator.xml",+ "default operator in schema (solrQueryParser/@defaultOperator) not supported");+ }}