From e7ebd44f1296ca54b4ce8ee0f3ef417feb19681d Mon Sep 17 00:00:00 2001 From: Timothy Potter Date: Fri, 13 Feb 2015 21:39:57 +0000 Subject: [PATCH] SOLR-6311: SearchHandler should use path when no qt or shard.qt parameter is specified git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1659694 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 4 +++ .../solr/handler/component/SearchHandler.java | 18 ++++++++++-- .../TermVectorComponentDistributedTest.java | 28 ++++++------------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index e1a441aa7c1..7159f67f343 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -155,6 +155,10 @@ Other Changes * SOLR-7103: Remove unused method params in faceting code. (shalin) +* SOLR-6311: When performing distributed queries, SearchHandler should use path + when no qt or shard.qt parameter is specified; fix also resolves SOLR-4479. + (Steve Molloy, Timothy Potter) + ================== 5.0.0 ================== Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release. diff --git a/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java b/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java index e2e90d28217..acd8a9b4cff 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java @@ -18,6 +18,7 @@ package org.apache.solr.handler.component; import org.apache.lucene.index.ExitableDirectoryReader; +import org.apache.lucene.util.Version; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.common.SolrDocumentList; import org.apache.solr.common.SolrException; @@ -306,10 +307,21 @@ public class SearchHandler extends RequestHandlerBase implements SolrCoreAware , params.set("NOW", Long.toString(rb.requestInfo.getNOW().getTime())); } String shardQt = params.get(ShardParams.SHARDS_QT); - if (shardQt == null) { - params.remove(CommonParams.QT); - } else { + if (shardQt != null) { params.set(CommonParams.QT, shardQt); + } else { + // for distributed queries that don't include shards.qt, use the original path + // as the default but operators need to update their luceneMatchVersion to enable + // this behavior since it did not work this way prior to 5.1 + if (req.getCore().getSolrConfig().luceneMatchVersion.onOrAfter(Version.LUCENE_5_1_0)) { + String reqPath = (String)req.getContext().get("path"); + if (!"/select".equals(reqPath)) { + params.set(CommonParams.QT, reqPath); + } // else if path is /select, then the qt gets passed thru if set + } else { + // this is the pre-5.1 behavior, which translates to sending the shard request to /select + params.remove(CommonParams.QT); + } } shardHandler1.submit(sreq, shard, params); } diff --git a/solr/core/src/test/org/apache/solr/handler/component/TermVectorComponentDistributedTest.java b/solr/core/src/test/org/apache/solr/handler/component/TermVectorComponentDistributedTest.java index bc184f848f2..527a36da733 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/TermVectorComponentDistributedTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/TermVectorComponentDistributedTest.java @@ -123,19 +123,16 @@ public class TermVectorComponentDistributedTest extends BaseDistributedSearchTes final String tv = "tvrh"; for (String q : new String[] {"id:0", "id:7", "id:[3 TO 6]", "*:*"}) { - query("sort","id desc", "qt",tv, - "shards.qt",tv, - "q", q, + "q", q, TermVectorComponent.COMPONENT_NAME, "true", TermVectorParams.TF, "true"); // tv.fl diff from fl query("sort", "id asc", "qt",tv, - "shards.qt",tv, - "q", q, + "q", q, "fl", "*,score", "tv.fl", "test_basictv,test_offtv", TermVectorComponent.COMPONENT_NAME, "true", @@ -144,8 +141,7 @@ public class TermVectorComponentDistributedTest extends BaseDistributedSearchTes // multi-valued tv.fl query("sort", "id asc", "qt",tv, - "shards.qt",tv, - "q", q, + "q", q, "fl", "*,score", "tv.fl", "test_basictv", "tv.fl","test_offtv", @@ -154,16 +150,14 @@ public class TermVectorComponentDistributedTest extends BaseDistributedSearchTes // re-use fl glob query("sort", "id desc", "qt",tv, - "shards.qt",tv, - "q", q, + "q", q, "fl", "*,score", TermVectorComponent.COMPONENT_NAME, "true", TermVectorParams.TF, "true"); // re-use fl, ignore things we can't handle query("sort", "id desc", "qt",tv, - "shards.qt",tv, - "q", q, + "q", q, "fl", "score,test_basictv,[docid],test_postv,val:sum(3,4)", TermVectorComponent.COMPONENT_NAME, "true", TermVectorParams.TF, "true"); @@ -171,8 +165,7 @@ public class TermVectorComponentDistributedTest extends BaseDistributedSearchTes // re-use (multi-valued) fl, ignore things we can't handle query("sort", "id desc", "qt",tv, - "shards.qt",tv, - "q", q, + "q", q, "fl", "score,test_basictv", "fl", "[docid],test_postv,val:sum(3,4)", TermVectorComponent.COMPONENT_NAME, "true", @@ -182,8 +175,7 @@ public class TermVectorComponentDistributedTest extends BaseDistributedSearchTes query("sort", "id asc", "qt",tv, - "shards.qt",tv, - "q", q, + "q", q, TermVectorComponent.COMPONENT_NAME, "true", TermVectorParams.TF, "true", TermVectorParams.DF, "true", @@ -193,8 +185,7 @@ public class TermVectorComponentDistributedTest extends BaseDistributedSearchTes query("sort", "id desc", "qt",tv, - "shards.qt",tv, - "q", q, + "q", q, TermVectorComponent.COMPONENT_NAME, "true", TermVectorParams.ALL, "true"); @@ -202,8 +193,7 @@ public class TermVectorComponentDistributedTest extends BaseDistributedSearchTes query("sort", "id desc", "qt",tv, - "shards.qt",tv, - "q", q, + "q", q, TermVectorComponent.COMPONENT_NAME, "true", TermVectorParams.TF, "true", TermVectorParams.DF, "true",