test fixes
This commit is contained in:
parent
d59e959c80
commit
7055a05e6e
|
@ -32,8 +32,6 @@ import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.elasticsearch.search.internal.SearchContext.DEFAULT_TERMINATE_AFTER;
|
||||
|
||||
/**
|
||||
* A request to count the number of documents matching a specific query. Best created with
|
||||
* {@link org.elasticsearch.client.Requests#countRequest(String...)}.
|
||||
|
@ -46,8 +44,6 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
|
|||
|
||||
public static final float DEFAULT_MIN_SCORE = -1f;
|
||||
|
||||
private float minScore = DEFAULT_MIN_SCORE;
|
||||
|
||||
@Nullable
|
||||
protected String routing;
|
||||
|
||||
|
@ -56,10 +52,12 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
|
|||
|
||||
private String[] types = Strings.EMPTY_ARRAY;
|
||||
|
||||
private int terminateAfter = DEFAULT_TERMINATE_AFTER;
|
||||
|
||||
private SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
|
||||
public CountRequest() {
|
||||
searchSourceBuilder.size(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new count request against the provided indices. No indices provided means it will
|
||||
* run against all indices.
|
||||
|
@ -72,7 +70,7 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
|
|||
* The minimum score of the documents to include in the count.
|
||||
*/
|
||||
public float minScore() {
|
||||
return minScore;
|
||||
return searchSourceBuilder.minScore();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,7 +78,7 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
|
|||
* documents will be included in the count.
|
||||
*/
|
||||
public CountRequest minScore(float minScore) {
|
||||
this.minScore = minScore;
|
||||
this.searchSourceBuilder.minScore(minScore);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -88,8 +86,8 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
|
|||
/**
|
||||
* The query to execute
|
||||
*/
|
||||
public CountRequest query(QueryBuilder queryBuilder) {
|
||||
this.searchSourceBuilder = new SearchSourceBuilder().query(queryBuilder);
|
||||
public CountRequest query(QueryBuilder<?> queryBuilder) {
|
||||
this.searchSourceBuilder.query(queryBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -147,12 +145,12 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
|
|||
if (terminateAfterCount <= 0) {
|
||||
throw new IllegalArgumentException("terminateAfter must be > 0");
|
||||
}
|
||||
this.terminateAfter = terminateAfterCount;
|
||||
this.searchSourceBuilder.terminateAfter(terminateAfterCount);
|
||||
return this;
|
||||
}
|
||||
|
||||
public int terminateAfter() {
|
||||
return this.terminateAfter;
|
||||
return this.searchSourceBuilder.terminateAfter();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -181,13 +179,6 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
|
|||
}
|
||||
|
||||
public SearchRequest toSearchRequest() {
|
||||
searchSourceBuilder.size(0);
|
||||
if (minScore() != DEFAULT_MIN_SCORE) {
|
||||
searchSourceBuilder.minScore(minScore());
|
||||
}
|
||||
if (terminateAfter() != DEFAULT_TERMINATE_AFTER) {
|
||||
searchSourceBuilder.terminateAfter(terminateAfter());
|
||||
}
|
||||
SearchRequest searchRequest = new SearchRequest(indices());
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
searchRequest.indicesOptions(indicesOptions());
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
|
||||
package org.elasticsearch.action.count;
|
||||
|
||||
import org.elasticsearch.action.support.QuerySourceBuilder;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.transport.TransportClient;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.query.MatchAllQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -56,14 +56,15 @@ public class CountRequestBuilderTests extends ESTestCase {
|
|||
@Test
|
||||
public void testEmptySourceToString() {
|
||||
CountRequestBuilder countRequestBuilder = client.prepareCount();
|
||||
assertThat(countRequestBuilder.toString(), equalTo(new QuerySourceBuilder().toString()));
|
||||
assertThat(countRequestBuilder.toString(), equalTo(new SearchSourceBuilder().size(0).toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryBuilderQueryToString() {
|
||||
CountRequestBuilder countRequestBuilder = client.prepareCount();
|
||||
countRequestBuilder.setQuery(QueryBuilders.matchAllQuery());
|
||||
assertThat(countRequestBuilder.toString(), equalTo(new QuerySourceBuilder().setQuery(QueryBuilders.matchAllQuery()).toString()));
|
||||
assertThat(countRequestBuilder.toString(), equalTo(new SearchSourceBuilder().size(0).query(QueryBuilders.matchAllQuery())
|
||||
.toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -28,7 +28,6 @@ import org.junit.Test;
|
|||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
|
||||
public class CountRequestTests extends ESTestCase {
|
||||
|
||||
|
@ -76,11 +75,7 @@ public class CountRequestTests extends ESTestCase {
|
|||
} else {
|
||||
assertNull(source.query());
|
||||
}
|
||||
if (countRequest.minScore() == CountRequest.DEFAULT_MIN_SCORE) {
|
||||
assertThat(source.minScore(), nullValue());
|
||||
} else {
|
||||
assertThat(source.minScore(), equalTo(countRequest.minScore()));
|
||||
}
|
||||
assertThat(source.minScore(), equalTo(countRequest.minScore()));
|
||||
assertThat(source.terminateAfter(), equalTo(countRequest.terminateAfter()));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue