mirror of https://github.com/apache/lucene.git
SOLR-14189 switch from String.trim() to StringUtils.isBlank() (#1172)
This commit is contained in:
parent
dea6f38d54
commit
43085edaa6
|
@ -33,6 +33,8 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query parser for dismax queries
|
* Query parser for dismax queries
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -193,7 +195,7 @@ public class DisMaxQParser extends QParser {
|
||||||
parsedUserQuery = null;
|
parsedUserQuery = null;
|
||||||
String userQuery = getString();
|
String userQuery = getString();
|
||||||
altUserQuery = null;
|
altUserQuery = null;
|
||||||
if (userQuery == null || userQuery.trim().length() < 1) {
|
if (StringUtils.isBlank(userQuery)) {
|
||||||
// If no query is specified, we may have an alternate
|
// If no query is specified, we may have an alternate
|
||||||
altUserQuery = getAlternateUserQuery(solrParams);
|
altUserQuery = getAlternateUserQuery(solrParams);
|
||||||
if (altUserQuery == null)
|
if (altUserQuery == null)
|
||||||
|
|
|
@ -29,6 +29,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.apache.lucene.analysis.core.StopFilterFactory;
|
import org.apache.lucene.analysis.core.StopFilterFactory;
|
||||||
import org.apache.lucene.analysis.util.TokenFilterFactory;
|
import org.apache.lucene.analysis.util.TokenFilterFactory;
|
||||||
|
@ -133,7 +135,7 @@ public class ExtendedDismaxQParser extends QParser {
|
||||||
parsedUserQuery = null;
|
parsedUserQuery = null;
|
||||||
String userQuery = getString();
|
String userQuery = getString();
|
||||||
altUserQuery = null;
|
altUserQuery = null;
|
||||||
if( userQuery == null || userQuery.trim().length() == 0 ) {
|
if (StringUtils.isBlank(userQuery)) {
|
||||||
// If no query is specified, we may have an alternate
|
// If no query is specified, we may have an alternate
|
||||||
if (config.altQ != null) {
|
if (config.altQ != null) {
|
||||||
QParser altQParser = subQuery(config.altQ, null);
|
QParser altQParser = subQuery(config.altQ, null);
|
||||||
|
|
|
@ -25,6 +25,8 @@ import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.common.params.SolrParams;
|
import org.apache.solr.common.params.SolrParams;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* Syntax: q=*:*&rq={!rerank reRankQuery=$rqq reRankDocs=300 reRankWeight=3}
|
* Syntax: q=*:*&rq={!rerank reRankQuery=$rqq reRankDocs=300 reRankWeight=3}
|
||||||
|
@ -56,7 +58,7 @@ public class ReRankQParserPlugin extends QParserPlugin {
|
||||||
|
|
||||||
public Query parse() throws SyntaxError {
|
public Query parse() throws SyntaxError {
|
||||||
String reRankQueryString = localParams.get(RERANK_QUERY);
|
String reRankQueryString = localParams.get(RERANK_QUERY);
|
||||||
if (reRankQueryString == null || reRankQueryString.trim().length() == 0) {
|
if (StringUtils.isBlank(reRankQueryString)) {
|
||||||
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, RERANK_QUERY+" parameter is mandatory");
|
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, RERANK_QUERY+" parameter is mandatory");
|
||||||
}
|
}
|
||||||
QParser reRankParser = QParser.getParser(reRankQueryString, req);
|
QParser reRankParser = QParser.getParser(reRankQueryString, req);
|
||||||
|
|
|
@ -241,6 +241,12 @@ public class TestExtendedDismaxParser extends SolrTestCaseJ4 {
|
||||||
"q.alt",allq,
|
"q.alt",allq,
|
||||||
"defType","edismax")
|
"defType","edismax")
|
||||||
,allr);
|
,allr);
|
||||||
|
|
||||||
|
assertQ("ideographic space should be considered whitespace",
|
||||||
|
req("q","\u3000",
|
||||||
|
"q.alt",allq,
|
||||||
|
"defType","edismax")
|
||||||
|
,allr);
|
||||||
|
|
||||||
assertQ("expected doc is missing (using un-escaped edismax w/qf)",
|
assertQ("expected doc is missing (using un-escaped edismax w/qf)",
|
||||||
req("q", "literal:colon",
|
req("q", "literal:colon",
|
||||||
|
|
Loading…
Reference in New Issue