unit test fixes
This commit is contained in:
parent
2e3cc50a0f
commit
585ed07c5b
|
@ -685,7 +685,9 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
|
|||
context.queryBoost(indexBoost);
|
||||
}
|
||||
}
|
||||
context.parsedQuery(context.queryParserService().parse(source.query()));
|
||||
if (source.query() != null) {
|
||||
context.parsedQuery(context.queryParserService().parse(source.query()));
|
||||
}
|
||||
if (source.postFilter() != null) {
|
||||
context.parsedPostFilter(context.queryParserService().parse(source.postFilter()));
|
||||
}
|
||||
|
|
|
@ -174,7 +174,9 @@ public class ShardSearchLocalRequest extends ContextAndHeaderHolder implements S
|
|||
if (in.readBoolean()) {
|
||||
scroll = readScroll(in);
|
||||
}
|
||||
source = SearchSourceBuilder.PROTOTYPE.readFrom(in);
|
||||
if (in.readBoolean()) {
|
||||
source = SearchSourceBuilder.PROTOTYPE.readFrom(in);
|
||||
}
|
||||
types = in.readStringArray();
|
||||
filteringAliases = in.readStringArray();
|
||||
nowInMillis = in.readVLong();
|
||||
|
@ -195,7 +197,13 @@ public class ShardSearchLocalRequest extends ContextAndHeaderHolder implements S
|
|||
out.writeBoolean(true);
|
||||
scroll.writeTo(out);
|
||||
}
|
||||
source.writeTo(out);
|
||||
if (source == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
source.writeTo(out);
|
||||
|
||||
}
|
||||
out.writeStringArray(types);
|
||||
out.writeStringArrayNullable(filteringAliases);
|
||||
if (!asKey) {
|
||||
|
|
|
@ -21,16 +21,11 @@ package org.elasticsearch.action.count;
|
|||
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.action.support.QuerySourceBuilder;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
|
@ -74,29 +69,19 @@ public class CountRequestTests extends ESTestCase {
|
|||
assertThat(searchRequest.types(), equalTo(countRequest.types()));
|
||||
assertThat(searchRequest.routing(), equalTo(countRequest.routing()));
|
||||
assertThat(searchRequest.preference(), equalTo(countRequest.preference()));
|
||||
BytesArray array = new BytesArray(XContentHelper.toString(searchRequest.source()));
|
||||
Map<String, Object> sourceMap = XContentHelper.convertToMap(array, false).v2();
|
||||
int count = 1;
|
||||
assertThat(sourceMap.get("size"), equalTo(0));
|
||||
SearchSourceBuilder source = searchRequest.source();
|
||||
assertThat(source.size(), equalTo(0));
|
||||
if (querySet) {
|
||||
count++;
|
||||
assertThat(sourceMap.get("query"), notNullValue());
|
||||
assertThat(source.query(), notNullValue());
|
||||
} else {
|
||||
assertNull(sourceMap.get("query"));
|
||||
assertNull(source.query());
|
||||
}
|
||||
if (countRequest.minScore() == CountRequest.DEFAULT_MIN_SCORE) {
|
||||
assertThat(sourceMap.get("min_score"), nullValue());
|
||||
assertThat(source.minScore(), nullValue());
|
||||
} else {
|
||||
assertThat(((Number)sourceMap.get("min_score")).floatValue(), equalTo(countRequest.minScore()));
|
||||
count++;
|
||||
assertThat(source.minScore(), equalTo(countRequest.minScore()));
|
||||
}
|
||||
if (countRequest.terminateAfter() == SearchContext.DEFAULT_TERMINATE_AFTER) {
|
||||
assertThat(sourceMap.get("terminate_after"), nullValue());
|
||||
} else {
|
||||
assertThat(sourceMap.get("terminate_after"), equalTo(countRequest.terminateAfter()));
|
||||
count++;
|
||||
}
|
||||
assertThat(sourceMap.toString(), sourceMap.size(), equalTo(count));
|
||||
assertThat(source.terminateAfter(), equalTo(countRequest.terminateAfter()));
|
||||
}
|
||||
|
||||
private static String[] randomStringArray() {
|
||||
|
|
|
@ -45,7 +45,6 @@ import org.elasticsearch.common.io.stream.StreamInput;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.settings.SettingsModule;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContent;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.env.Environment;
|
||||
|
@ -319,7 +318,7 @@ public class NewSearchSourceBuilderTests extends ESTestCase {
|
|||
fetchSourceContext = new FetchSourceContext(randomAsciiOfLengthBetween(5, 20), randomAsciiOfLengthBetween(5, 20));
|
||||
break;
|
||||
case 3:
|
||||
fetchSourceContext = new FetchSourceContext(randomBoolean(), includes, excludes, randomBoolean());
|
||||
fetchSourceContext = new FetchSourceContext(true, includes, excludes, randomBoolean());
|
||||
break;
|
||||
case 4:
|
||||
fetchSourceContext = new FetchSourceContext(includes);
|
||||
|
@ -433,6 +432,7 @@ public class NewSearchSourceBuilderTests extends ESTestCase {
|
|||
|
||||
protected SearchSourceBuilder parseQuery(String queryAsString, ParseFieldMatcher matcher) throws IOException {
|
||||
XContentParser parser = XContentFactory.xContent(queryAsString).createParser(queryAsString);
|
||||
System.out.println(queryAsString);
|
||||
QueryParseContext context = createParseContext();
|
||||
context.reset(parser);
|
||||
context.parseFieldMatcher(matcher);
|
||||
|
|
Loading…
Reference in New Issue