mirror of https://github.com/apache/lucene.git
SOLR-10584: Remove defaultOperator completely in 7.0
This commit is contained in:
parent
9dc952a47c
commit
66cd20e98a
|
@ -70,6 +70,9 @@ Upgrading from Solr 6.x
|
|||
query text will not be split on whitespace before analysis. See
|
||||
https://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)
|
||||
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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%");
|
||||
}
|
||||
|
|
|
@ -990,8 +990,7 @@ public class ExtendedDismaxQParser extends QParser {
|
|||
super(parser, defaultField);
|
||||
// Respect the q.op parameter before mm will be applied later
|
||||
SolrParams 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
"/schema/version",
|
||||
"/schema/similarity",
|
||||
"/schema/solrqueryparser",
|
||||
"/schema/zkversion",
|
||||
"/schema/solrqueryparser/defaultoperator"
|
||||
"/schema/zkversion"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
|
@ -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']");
|
||||
}
|
||||
}
|
|
@ -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']");
|
||||
}
|
||||
}
|
|
@ -128,4 +128,8 @@ public class BadIndexSchemaTest extends AbstractBadConfigTestBase {
|
|||
"ft-does-not-exist");
|
||||
}
|
||||
|
||||
public void testDefaultOperatorBanned() throws Exception {
|
||||
doTest("bad-schema-default-operator.xml",
|
||||
"default operator in schema (solrQueryParser/@defaultOperator) not supported");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue