Skip to content

Apache Lucene open-source search software

SOLR-659: add shards.start shards.rows

Yonik Seeley3c96f846cdd4
diff --git a/CHANGES.txt b/CHANGES.txt
index 5ad527a6fc4..d584313a504 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -292,7 +292,11 @@ New Features
75. SOLR-1385 : Add an 'enable' attribute to all plugins (noble)
-76. SOLR-SOLR-1414 : implicit core properties are not set for single core (noble)
+76. SOLR-1414 : implicit core properties are not set for single core (noble)
+
+77. SOLR-659 : Adds shards.start and shards.rows to distributed search
+ to allow more efficient bulk queries (those that retrieve many or all
+ documents). (Brian Whitman via yonik)
Optimizations
----------------------
diff --git a/src/common/org/apache/solr/common/params/ShardParams.java b/src/common/org/apache/solr/common/params/ShardParams.java
index e929c0c98a9..da8fab3e2e7 100644
--- a/src/common/org/apache/solr/common/params/ShardParams.java
+++ b/src/common/org/apache/solr/common/params/ShardParams.java
@@ -24,6 +24,10 @@ public interface ShardParams {
/** the shards to use (distributed configuration) */
public static final String SHARDS = "shards";
+ /** per-shard start and rows */
+ public static final String SHARDS_ROWS = "shards.rows";
+ public static final String SHARDS_START = "shards.start";
+
/** IDs of the shard documents */
public static final String IDS = "ids";
diff --git a/src/java/org/apache/solr/handler/component/QueryComponent.java b/src/java/org/apache/solr/handler/component/QueryComponent.java
index 0d41b7a537d..1e077fd52ae 100644
--- a/src/java/org/apache/solr/handler/component/QueryComponent.java
+++ b/src/java/org/apache/solr/handler/component/QueryComponent.java
@@ -114,6 +114,14 @@ public class QueryComponent extends SearchComponent
List<String> lst = StrUtils.splitSmart(shards, ",", true);
rb.shards = lst.toArray(new String[lst.size()]);
}
+ String shards_rows = params.get(ShardParams.SHARDS_ROWS);
+ if(shards_rows != null) {
+ rb.shards_rows = Integer.parseInt(shards_rows);
+ }
+ String shards_start = params.get(ShardParams.SHARDS_START);
+ if(shards_start != null) {
+ rb.shards_start = Integer.parseInt(shards_start);
+ }
}
/**
@@ -330,14 +338,22 @@ public class QueryComponent extends SearchComponent
// set the start (offset) to 0 for each shard request so we can properly merge
// results from the start.
- sreq.params.set(CommonParams.START, "0");
-
+ if(rb.shards_start > -1) {
+ // if the client set shards.start set this explicitly
+ sreq.params.set(CommonParams.START,rb.shards_start);
+ } else {
+ sreq.params.set(CommonParams.START, "0");
+ }
// TODO: should we even use the SortSpec? That's obtained from the QParser, and
// perhaps we shouldn't attempt to parse the query at this level?
// Alternate Idea: instead of specifying all these things at the upper level,
// we could just specify that this is a shard request.
- sreq.params.set(CommonParams.ROWS, rb.getSortSpec().getOffset() + rb.getSortSpec().getCount());
-
+ if(rb.shards_rows > -1) {
+ // if the client set shards.rows set this explicity
+ sreq.params.set(CommonParams.ROWS,rb.shards_rows);
+ } else {
+ sreq.params.set(CommonParams.ROWS, rb.getSortSpec().getOffset() + rb.getSortSpec().getCount());
+ }
// in this first phase, request only the unique key field
// and any fields needed for merging.
diff --git a/src/java/org/apache/solr/handler/component/ResponseBuilder.java b/src/java/org/apache/solr/handler/component/ResponseBuilder.java
index 0a22b8bc97e..b002eb19c85 100644
--- a/src/java/org/apache/solr/handler/component/ResponseBuilder.java
+++ b/src/java/org/apache/solr/handler/component/ResponseBuilder.java
@@ -94,6 +94,8 @@ public class ResponseBuilder
//The address of the Shard
public String[] shards;
+ public int shards_rows = -1;
+ public int shards_start = -1;
public List<ShardRequest> outgoing; // requests to be sent
public List<ShardRequest> finished; // requests that have received responses from all shards