diff --git a/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java b/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java index 83a55afc38c..29b4b3d137f 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java @@ -153,14 +153,13 @@ public class QueryComponent extends SearchComponent rb.setQuery( q ); - String rankQueryString = rb.req.getParams().get(CommonParams.RQ); if(rankQueryString != null) { QParser rqparser = QParser.getParser(rankQueryString, defType, req); Query rq = rqparser.getQuery(); if(rq instanceof RankQuery) { RankQuery rankQuery = (RankQuery)rq; - rb.setQuery(rankQuery.wrap(q)); //Wrap the RankQuery around the main query. + rb.setRankQuery(rankQuery); MergeStrategy mergeStrategy = rankQuery.getMergeStrategy(); if(mergeStrategy != null) { rb.addMergeStrategy(mergeStrategy); diff --git a/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java b/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java index c30ac710c5e..1c3e7199235 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java +++ b/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java @@ -34,6 +34,7 @@ import org.apache.solr.search.DocListAndSet; import org.apache.solr.search.QParser; import org.apache.solr.search.SolrIndexSearcher; import org.apache.solr.search.SortSpec; +import org.apache.solr.search.RankQuery; import org.apache.solr.search.grouping.GroupingSpecification; import org.apache.solr.search.grouping.distributed.command.QueryCommandResult; @@ -77,6 +78,7 @@ public class ResponseBuilder private CursorMark nextCursorMark; private List mergeStrategies; + private RankQuery rankQuery; private DocListAndSet results = null; @@ -248,6 +250,10 @@ public class ResponseBuilder return this.mergeStrategies; } + public void setRankQuery(RankQuery rankQuery) { + this.rankQuery = rankQuery; + } + public void setResponseDocs(SolrDocumentList _responseDocs) { this._responseDocs = _responseDocs; } @@ -410,7 +416,7 @@ public class ResponseBuilder */ public SolrIndexSearcher.QueryCommand getQueryCommand() { SolrIndexSearcher.QueryCommand cmd = new SolrIndexSearcher.QueryCommand(); - cmd.setQuery(getQuery()) + cmd.setQuery(wrap(getQuery())) .setFilterList(getFilters()) .setSort(getSortSpec().getSort()) .setOffset(getSortSpec().getOffset()) @@ -421,6 +427,14 @@ public class ResponseBuilder return cmd; } + private Query wrap(Query q) { + if(this.rankQuery != null) { + return this.rankQuery.wrap(q); + } else { + return q; + } + } + /** * Sets results from a SolrIndexSearcher.QueryResult. */