Apache Lucene open-source search software
SOLR-1138: gracefully handle empty and null queries
Grant Ingersoll44302daeb252
diff --git a/CHANGES.txt b/CHANGES.txtindex 0891d8a4e0d..5de9106321f 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -354,6 +354,7 @@ Bug Fixes41. SOLR-1135: Java replication creates Snapshot in the directory where Solr was launched (Jianhan Guo via shalin)+42. SOLR-1138: Query Elevation Component now gracefully handles missing queries. (gsingers)Other Changes----------------------diff --git a/src/java/org/apache/solr/handler/component/QueryElevationComponent.java b/src/java/org/apache/solr/handler/component/QueryElevationComponent.javaindex e2df6f515ff..1058eb1c9ea 100644--- a/src/java/org/apache/solr/handler/component/QueryElevationComponent.java+++ b/src/java/org/apache/solr/handler/component/QueryElevationComponent.java@@ -52,6 +52,7 @@ import org.apache.lucene.search.Sort;import org.apache.lucene.search.SortComparatorSource;import org.apache.lucene.search.SortField;import org.apache.lucene.search.TermQuery;+import org.apache.lucene.search.MatchAllDocsQuery;import org.apache.solr.common.SolrException;import org.apache.solr.common.params.SolrParams;import org.apache.solr.common.util.DOMUtil;@@ -324,12 +325,12 @@ public class QueryElevationComponent extends SearchComponent implements SolrCoreboolean force = params.getBool( FORCE_ELEVATION, forceElevation );Query query = rb.getQuery();- if( query == null ) {- throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,- "The QueryElevationComponent needs to be registered 'after' the query component" );+ String qstr = rb.getQueryString();+ if( query == null || qstr == null) {+ return;}-- String qstr = getAnalyzedQuery( rb.getQueryString() );++ qstr = getAnalyzedQuery(qstr);IndexReader reader = req.getSearcher().getReader();ElevationObj booster = null;try {diff --git a/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java b/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.javaindex 1c3a99f56a9..50a02595bbc 100644--- a/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java+++ b/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java@@ -85,7 +85,24 @@ public class QueryElevationComponentTest extends AbstractSolrTestCase {assertEquals( "xxxx", comp.getAnalyzedQuery( "XXXX" ) );assertEquals( "xxxxyyyy", comp.getAnalyzedQuery( "XXXX YYYY" ) );}-++ public void testEmptyQuery() throws Exception {+ SolrCore core = h.getCore();++++ //String query = "title:ipod";++ Map<String,String> args = new HashMap<String, String>();+ args.put( "q.alt", "*:*" );+ args.put( "defType", "dismax");+ //args.put( CommonParams.FL, "id,title,score" );+ SolrQueryRequest req = new LocalSolrQueryRequest( core, new MapSolrParams( args) );+ assertQ("Make sure QEC handles null queries", req, "//*[@numFound='0']");++ }++public void testSorting() throws IOException{SolrCore core = h.getCore();