lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject [lucene-solr] 01/02: SOLR-14189 switch from String.trim() to StringUtils.isBlank() (#1172)
Date Sun, 26 Jan 2020 11:07:37 GMT
This is an automated email from the ASF dual-hosted git repository.

uschindler pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 43085edaa6954f212d1a7f19a2f60e3d0de73ae6
Author: andywebb1975 <andy.webb2@bbc.co.uk>
AuthorDate: Sun Jan 26 11:03:39 2020 +0000

    SOLR-14189 switch from String.trim() to StringUtils.isBlank() (#1172)
---
 solr/core/src/java/org/apache/solr/search/DisMaxQParser.java        | 4 +++-
 .../core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java | 4 +++-
 solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java  | 4 +++-
 .../src/test/org/apache/solr/search/TestExtendedDismaxParser.java   | 6 ++++++
 4 files changed, 15 insertions(+), 3 deletions(-)

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 04aa77c..28bd3d1 100644
--- a/solr/core/src/java/org/apache/solr/search/DisMaxQParser.java
+++ b/solr/core/src/java/org/apache/solr/search/DisMaxQParser.java
@@ -33,6 +33,8 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.lang3.StringUtils;
+
 /**
  * Query parser for dismax queries
  * <p>
@@ -193,7 +195,7 @@ public class DisMaxQParser extends QParser {
     parsedUserQuery = null;
     String userQuery = getString();
     altUserQuery = null;
-    if (userQuery == null || userQuery.trim().length() < 1) {
+    if (StringUtils.isBlank(userQuery)) {
       // If no query is specified, we may have an alternate
       altUserQuery = getAlternateUserQuery(solrParams);
       if (altUserQuery == null)
diff --git a/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java b/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java
index 584532a..f2df6d6 100644
--- a/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java
+++ b/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java
@@ -29,6 +29,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.commons.lang3.StringUtils;
+
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.core.StopFilterFactory;
 import org.apache.lucene.analysis.util.TokenFilterFactory;
@@ -133,7 +135,7 @@ public class ExtendedDismaxQParser extends QParser {
     parsedUserQuery = null;
     String userQuery = getString();
     altUserQuery = null;
-    if( userQuery == null || userQuery.trim().length() == 0 ) {
+    if (StringUtils.isBlank(userQuery)) {
       // If no query is specified, we may have an alternate
       if (config.altQ != null) {
         QParser altQParser = subQuery(config.altQ, null);
diff --git a/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java
index 1190cdb..221501b 100644
--- a/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java
+++ b/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java
@@ -25,6 +25,8 @@ import org.apache.solr.common.SolrException;
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.request.SolrQueryRequest;
 
+import org.apache.commons.lang3.StringUtils;
+
 /*
 *
 *  Syntax: q=*:*&rq={!rerank reRankQuery=$rqq reRankDocs=300 reRankWeight=3}
@@ -56,7 +58,7 @@ public class ReRankQParserPlugin extends QParserPlugin {
 
     public Query parse() throws SyntaxError {
       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");
       }
       QParser reRankParser = QParser.getParser(reRankQueryString, req);
diff --git a/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java b/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
index 1f0b569..e8d7dbd 100644
--- a/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
+++ b/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
@@ -241,6 +241,12 @@ public class TestExtendedDismaxParser extends SolrTestCaseJ4 {
             "q.alt",allq,
             "defType","edismax")
         ,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)",
           req("q", "literal:colon", 


Mime
View raw message