refactor from and size in url to use the new "extraSource" in it

This commit is contained in:
kimchy 2010-02-27 16:48:01 +02:00
parent 948f0ef0da
commit a5790cab28
7 changed files with 23 additions and 69 deletions

View File

@ -52,10 +52,6 @@ public class SearchRequest implements ActionRequest {
private Scroll scroll;
private int from = -1;
private int size = -1;
private String[] types = Strings.EMPTY_ARRAY;
private TimeValue timeout;
@ -179,15 +175,6 @@ public class SearchRequest implements ActionRequest {
return this;
}
public int from() {
return from;
}
public SearchRequest from(int from) {
this.from = from;
return this;
}
public String[] types() {
return types;
}
@ -206,15 +193,6 @@ public class SearchRequest implements ActionRequest {
return this;
}
public int size() {
return size;
}
public SearchRequest size(int size) {
this.size = size;
return this;
}
@Override public void readFrom(DataInput in) throws IOException, ClassNotFoundException {
operationThreading = SearchOperationThreading.fromId(in.readByte());
searchType = SearchType.fromId(in.readByte());
@ -231,8 +209,6 @@ public class SearchRequest implements ActionRequest {
if (in.readBoolean()) {
scroll = readScroll(in);
}
from = in.readInt();
size = in.readInt();
if (in.readBoolean()) {
timeout = readTimeValue(in);
}
@ -282,8 +258,6 @@ public class SearchRequest implements ActionRequest {
out.writeBoolean(true);
scroll.writeTo(out);
}
out.writeInt(from);
out.writeInt(size);
if (timeout == null) {
out.writeBoolean(false);
} else {

View File

@ -62,7 +62,6 @@ public abstract class TransportSearchHelper {
public static InternalSearchRequest internalSearchRequest(ShardRouting shardRouting, SearchRequest request) {
InternalSearchRequest internalRequest = new InternalSearchRequest(shardRouting, request.source());
internalRequest.extraSource(request.extraSource());
internalRequest.from(request.from()).size(request.size());
internalRequest.scroll(request.scroll());
internalRequest.timeout(request.timeout());
internalRequest.types(request.types());

View File

@ -43,6 +43,7 @@ import static org.elasticsearch.rest.RestRequest.Method.*;
import static org.elasticsearch.rest.RestResponse.Status.*;
import static org.elasticsearch.rest.action.support.RestActions.*;
import static org.elasticsearch.rest.action.support.RestJsonBuilder.*;
import static org.elasticsearch.search.builder.SearchSourceBuilder.*;
import static org.elasticsearch.util.TimeValue.*;
/**
@ -117,8 +118,22 @@ public class RestSearchAction extends BaseRestHandler {
SearchRequest searchRequest = new SearchRequest(indices, parseSearchSource(request));
searchRequest.searchType(parseSearchType(request.param("searchType")));
searchRequest.from(request.paramAsInt("from", -1));
searchRequest.size(request.paramAsInt("size", -1));
SearchSourceBuilder extraSourceBuilder = null;
int from = request.paramAsInt("from", -1);
if (from != -1) {
if (extraSourceBuilder == null) {
extraSourceBuilder = searchSource();
}
extraSourceBuilder.from(from);
}
int size = request.paramAsInt("size", -1);
if (size != -1) {
if (extraSourceBuilder == null) {
extraSourceBuilder = searchSource();
}
extraSourceBuilder.size(size);
}
String scroll = request.param("scroll");
if (scroll != null) {
@ -134,6 +149,10 @@ public class RestSearchAction extends BaseRestHandler {
searchRequest.queryHint(request.param("queryHint"));
if (extraSourceBuilder != null) {
searchRequest.extraSource(extraSourceBuilder);
}
return searchRequest;
}

View File

@ -247,10 +247,6 @@ public class SearchService extends AbstractComponent implements LifecycleCompone
SearchContext context = new SearchContext(idGenerator.incrementAndGet(), shardTarget, request.timeout(), request.types(), engineSearcher, indexService);
// init the from and size
context.from(request.from());
context.size(request.size());
context.scroll(request.scroll());
parseSource(context, request.source());

View File

@ -61,10 +61,6 @@ public class InternalSearchRequest implements Streamable {
private Scroll scroll;
private int from = -1;
private int size = -1;
private TimeValue timeout;
private String[] types = Strings.EMPTY_ARRAY;
@ -116,15 +112,6 @@ public class InternalSearchRequest implements Streamable {
return this;
}
public int from() {
return from;
}
public InternalSearchRequest from(int from) {
this.from = from;
return this;
}
public TimeValue timeout() {
return timeout;
}
@ -134,15 +121,6 @@ public class InternalSearchRequest implements Streamable {
return this;
}
public int size() {
return size;
}
public InternalSearchRequest size(int size) {
this.size = size;
return this;
}
public String[] types() {
return types;
}
@ -157,8 +135,6 @@ public class InternalSearchRequest implements Streamable {
if (in.readBoolean()) {
scroll = readScroll(in);
}
from = in.readInt();
size = in.readInt();
if (in.readBoolean()) {
timeout = readTimeValue(in);
}
@ -194,8 +170,6 @@ public class InternalSearchRequest implements Streamable {
out.writeBoolean(true);
scroll.writeTo(out);
}
out.writeInt(from);
out.writeInt(size);
if (timeout == null) {
out.writeBoolean(false);
} else {

View File

@ -24,15 +24,11 @@ import org.elasticsearch.search.SearchParseElement;
import org.elasticsearch.search.internal.SearchContext;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class FromParseElement implements SearchParseElement {
@Override public void parse(JsonParser jp, SearchContext context) throws Exception {
if (context.from() != -1) {
// it was externally set
return;
}
context.from(jp.getIntValue());
}
}

View File

@ -24,15 +24,11 @@ import org.elasticsearch.search.SearchParseElement;
import org.elasticsearch.search.internal.SearchContext;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class SizeParseElement implements SearchParseElement {
@Override public void parse(JsonParser jp, SearchContext context) throws Exception {
if (context.size() != -1) {
// it was externally set
return;
}
context.size(jp.getIntValue());
}
}