Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

revert dsmiley's other commits: SOLR-2724,SOLR-435,SOLR-3283

Mark Robert Miller0ced8b5020ae
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 5c68e7528a1..a298be5bdf0 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -506,10 +506,6 @@ Upgrading from Solr 3.5
* SOLR-3161: Don't use the 'qt' parameter with a leading '/'. It probably won't work in 4.0
and it's now limited in 3.6 to SearchHandler subclasses that aren't lazy-loaded.
-* SOLR-2724: Specifying <defaultSearchField> and <solrQueryParser defaultOperator="..."/> in
- schema.xml is now considered deprecated. Instead you are encouraged to specify these via the "df"
- and "q.op" parameters in your request handler definition. (David Smiley)
-
New Features
----------------------
* SOLR-2854: Now load URL content stream data (via stream.url) when called for during request handling,
diff --git a/solr/core/src/java/org/apache/solr/handler/PingRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/PingRequestHandler.java
index d46beeb7642..5013e00a72a 100644
--- a/solr/core/src/java/org/apache/solr/handler/PingRequestHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/PingRequestHandler.java
@@ -39,6 +39,7 @@ public class PingRequestHandler extends RequestHandlerBase
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception
{
SolrParams params = req.getParams();
+ SolrParams required = params.required();
SolrCore core = req.getCore();
// Check if the service is available
@@ -48,11 +49,11 @@ public class PingRequestHandler extends RequestHandlerBase
}
// Get the RequestHandler
- String qt = params.get( CommonParams.QT );//optional; you get the default otherwise
+ String qt = required.get( CommonParams.QT );
SolrRequestHandler handler = core.getRequestHandler( qt );
if( handler == null ) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
- "Unknown RequestHandler (qt): "+qt );
+ "Unknown RequestHandler: "+qt );
}
if( handler instanceof PingRequestHandler ) {
diff --git a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
index 2dd86610963..7cac8994e5b 100644
--- a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
+++ b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
@@ -438,7 +438,7 @@ public final class IndexSchema {
node = (Node) xpath.evaluate("/schema/defaultSearchField/text()", document, XPathConstants.NODE);
if (node==null) {
- log.debug("no default search field specified in schema.");
+ log.warn("no default search field specified in schema.");
} else {
defaultSearchFieldName=node.getNodeValue().trim();
// throw exception if specified, but not found or not indexed
@@ -449,7 +449,7 @@ public final class IndexSchema {
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, msg );
}
}
- log.info("default search field in schema is "+defaultSearchFieldName);
+ log.info("default search field is "+defaultSearchFieldName);
}
node = (Node) xpath.evaluate("/schema/solrQueryParser/@defaultOperator", document, XPathConstants.NODE);
diff --git a/solr/core/src/java/org/apache/solr/search/DisMaxQParser.java b/solr/core/src/java/org/apache/solr/search/DisMaxQParser.java
index 60e3a8e16d9..527cd363e3c 100644
--- a/solr/core/src/java/org/apache/solr/search/DisMaxQParser.java
+++ b/solr/core/src/java/org/apache/solr/search/DisMaxQParser.java
@@ -22,6 +22,7 @@ import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Query;
import org.apache.solr.schema.IndexSchema;
+import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.DisMaxParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
@@ -91,9 +92,7 @@ public class DisMaxQParser extends QParser {
*/
BooleanQuery query = new BooleanQuery(true);
- boolean notBlank = addMainQuery(query, solrParams);
- if (!notBlank)
- return null;
+ addMainQuery(query, solrParams);
addBoostQuery(query, solrParams);
addBoostFunctions(query, solrParams);
@@ -152,8 +151,7 @@ public class DisMaxQParser extends QParser {
}
}
- /** Adds the main query to the query argument. If its blank then false is returned. */
- protected boolean addMainQuery(BooleanQuery query, SolrParams solrParams) throws ParseException {
+ protected void addMainQuery(BooleanQuery query, SolrParams solrParams) throws ParseException {
Map<String, Float> phraseFields = SolrPluginUtils.parseFieldBoosts(solrParams.getParams(DisMaxParams.PF));
float tiebreaker = solrParams.getFloat(DisMaxParams.TIE, 0.0f);
@@ -172,8 +170,6 @@ public class DisMaxQParser extends QParser {
if (userQuery == null || userQuery.trim().length() < 1) {
// If no query is specified, we may have an alternate
altUserQuery = getAlternateUserQuery(solrParams);
- if (altUserQuery == null)
- return false;
query.add(altUserQuery, BooleanClause.Occur.MUST);
} else {
// There is a valid query string
@@ -188,7 +184,6 @@ public class DisMaxQParser extends QParser {
query.add(phrase, BooleanClause.Occur.SHOULD);
}
}
- return true;
}
protected Query getAlternateUserQuery(SolrParams solrParams) throws ParseException {
@@ -197,7 +192,7 @@ public class DisMaxQParser extends QParser {
QParser altQParser = subQuery(altQ, null);
return altQParser.getQuery();
} else {
- return null;
+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "missing query string");
}
}
diff --git a/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java
index 3f94783be1b..f21636f8168 100755
--- a/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java
+++ b/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java
@@ -172,7 +172,7 @@ class ExtendedDismaxQParser extends QParser {
query.add( altUserQuery , BooleanClause.Occur.MUST );
} else {
return null;
- // throw new ParseException("missing query string" );
+ // throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "missing query string" );
}
}
else {
diff --git a/solr/core/src/java/org/apache/solr/search/LuceneQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/LuceneQParserPlugin.java
index 3d6b500dc89..793af1c7e0c 100755
--- a/solr/core/src/java/org/apache/solr/search/LuceneQParserPlugin.java
+++ b/solr/core/src/java/org/apache/solr/search/LuceneQParserPlugin.java
@@ -19,6 +19,7 @@ package org.apache.solr.search;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Sort;
+import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
@@ -47,6 +48,7 @@ public class LuceneQParserPlugin extends QParserPlugin {
}
class LuceneQParser extends QParser {
+ String sortStr;
SolrQueryParser lparser;
public LuceneQParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
@@ -57,7 +59,7 @@ class LuceneQParser extends QParser {
@Override
public Query parse() throws ParseException {
String qstr = getString();
- if (qstr == null || qstr.length()==0) return null;
+ if (qstr == null) return null;
String defaultField = getParam(CommonParams.DF);
if (defaultField==null) {
@@ -93,8 +95,6 @@ class OldLuceneQParser extends LuceneQParser {
// handle legacy "query;sort" syntax
if (getLocalParams() == null) {
String qstr = getString();
- if (qstr == null || qstr.length() == 0)
- return null;
sortStr = getParams().get(CommonParams.SORT);
if (sortStr == null) {
// sort may be legacy form, included in the query string
@@ -107,7 +107,7 @@ class OldLuceneQParser extends LuceneQParser {
qstr = commands.get(0);
}
else if (commands.size() > 2) {
- throw new ParseException("If you want to use multiple ';' in the query, use the 'sort' param.");
+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "If you want to use multiple ';' in the query, use the 'sort' param.");
}
}
setString(qstr);
diff --git a/solr/core/src/java/org/apache/solr/search/QParser.java b/solr/core/src/java/org/apache/solr/search/QParser.java
index f9c419b45c1..a18ad72ab2d 100755
--- a/solr/core/src/java/org/apache/solr/search/QParser.java
+++ b/solr/core/src/java/org/apache/solr/search/QParser.java
@@ -96,8 +96,7 @@ public abstract class QParser {
lst.add(val);
}
- /** Create and return the <code>Query</code> object represented by <code>qstr</code>. Null MAY be returned to signify
- * there was no input (e.g. no query string) to parse.
+ /** Create and return the <code>Query</code> object represented by <code>qstr</code>
* @see #getQuery()
**/
public abstract Query parse() throws ParseException;
diff --git a/solr/core/src/java/org/apache/solr/search/SolrQueryParser.java b/solr/core/src/java/org/apache/solr/search/SolrQueryParser.java
index 4b5899e71ec..630c6ada985 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrQueryParser.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrQueryParser.java
@@ -133,7 +133,7 @@ public class SolrQueryParser extends QueryParser {
if (field == null && defaultField == null) {
throw new SolrException
(SolrException.ErrorCode.BAD_REQUEST,
- "no field name specified in query and no default specified via 'df' param");
+ "no field name specified in query and no defaultSearchField defined in schema.xml");
}
}
diff --git a/solr/core/src/test/org/apache/solr/search/QueryParsingTest.java b/solr/core/src/test/org/apache/solr/search/QueryParsingTest.java
index 8ac4a908063..ff2dc53a4ae 100644
--- a/solr/core/src/test/org/apache/solr/search/QueryParsingTest.java
+++ b/solr/core/src/test/org/apache/solr/search/QueryParsingTest.java
@@ -16,7 +16,6 @@ package org.apache.solr.search;
* limitations under the License.
*/
-import org.apache.lucene.search.Query;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.solr.SolrTestCaseJ4;
@@ -36,40 +35,6 @@ public class QueryParsingTest extends SolrTestCaseJ4 {
initCore("solrconfig.xml","schema.xml");
}
- /**
- * Test that the main QParserPlugins people are likely to use
- * as defaults fail with a consistent exception when the query string
- * is either empty or null.
- * @see <a href="https://issues.apache.org/jira/browse/SOLR-435">SOLR-435</a>
- * @see <a href="https://issues.apache.org/jira/browse/SOLR-2001">SOLR-2001</a>
- */
- public void testQParserEmptyInput() throws Exception {
-
- SolrQueryRequest req = req();
-
- final String[] parsersTested = new String[] {
- OldLuceneQParserPlugin.NAME,
- LuceneQParserPlugin.NAME,
- DisMaxQParserPlugin.NAME,
- ExtendedDismaxQParserPlugin.NAME
- };
-
- for (String defType : parsersTested) {
- for (String qstr : new String[] {null, ""}) {
- QParser parser = null;
- try {
- parser = QParser.getParser(qstr, defType, req);
- } catch (Exception e) {
- throw new RuntimeException("getParser excep using defType=" +
- defType + " with qstr="+qstr, e);
- }
-
- Query q = parser.parse();
- assertNull("expected no query",q);
- }
- }
- }
-
@Test
public void testSort() throws Exception {
Sort sort;
diff --git a/solr/example/solr/conf/schema.xml b/solr/example/solr/conf/schema.xml
index 714a694b051..abc40e1a270 100755
--- a/solr/example/solr/conf/schema.xml
+++ b/solr/example/solr/conf/schema.xml
@@ -987,6 +987,12 @@
-->
<uniqueKey>id</uniqueKey>
+ <!-- field for the QueryParser to use when an explicit fieldname is absent -->
+ <defaultSearchField>text</defaultSearchField>
+
+ <!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
+ <solrQueryParser defaultOperator="OR"/>
+
<!-- copyField commands copy one field to another at the time a document
is added to the index. It's used either to index the same field differently,
or to add multiple fields to the same field for easier/faster searching. -->
diff --git a/solr/example/solr/conf/solrconfig.xml b/solr/example/solr/conf/solrconfig.xml
index 7678642e736..f7651a9d171 100755
--- a/solr/example/solr/conf/solrconfig.xml
+++ b/solr/example/solr/conf/solrconfig.xml
@@ -734,7 +734,6 @@
<lst name="defaults">
<str name="echoParams">explicit</str>
<int name="rows">10</int>
- <str name="df">text</str>
</lst>
<!-- In addition to defaults, "appends" params can be specified
to identify values which should be appended to the list of
@@ -1041,6 +1040,7 @@
<!-- ping/healthcheck -->
<requestHandler name="/admin/ping" class="solr.PingRequestHandler">
<lst name="invariants">
+ <str name="qt">search</str>
<str name="q">solrpingquery</str>
</lst>
<lst name="defaults">