Don't throw UOE in PercolateContext#from and #size

Create mapping in PercolatorTests#testPercolateSorting_unsupportedField in create index call instead of lazily via index call.
This commit is contained in:
Martijn van Groningen 2014-03-09 23:04:34 +07:00
parent 8cfff9d796
commit 52d099dfae
5 changed files with 21 additions and 20 deletions

View File

@ -64,7 +64,7 @@ public class PercolateShardResponse extends BroadcastShardOperationResponse {
this.count = count;
this.scores = scores;
this.percolatorTypeId = context.percolatorTypeId;
this.requestedSize = context.size;
this.requestedSize = context.size();
QuerySearchResult result = context.queryResult();
if (result != null) {
if (result.facets() != null) {

View File

@ -82,12 +82,11 @@ import java.util.concurrent.ConcurrentMap;
public class PercolateContext extends SearchContext {
public boolean limit;
public int size;
private int size;
public boolean doSort;
public byte percolatorTypeId;
private boolean trackScores;
private final PercolateShardRequest request;
private final SearchShardTarget searchShardTarget;
private final IndexService indexService;
private final IndexFieldDataService fieldDataService;
@ -118,7 +117,6 @@ public class PercolateContext extends SearchContext {
public PercolateContext(PercolateShardRequest request, SearchShardTarget searchShardTarget, IndexShard indexShard,
IndexService indexService, CacheRecycler cacheRecycler, PageCacheRecycler pageCacheRecycler,
BigArrays bigArrays, ScriptService scriptService) {
this.request = request;
this.indexShard = indexShard;
this.indexService = indexService;
this.fieldDataService = indexService.fieldData();
@ -554,7 +552,7 @@ public class PercolateContext extends SearchContext {
@Override
public int from() {
throw new UnsupportedOperationException();
return 0;
}
@Override
@ -564,12 +562,14 @@ public class PercolateContext extends SearchContext {
@Override
public int size() {
throw new UnsupportedOperationException();
return size;
}
@Override
public SearchContext size(int size) {
throw new UnsupportedOperationException();
this.size = size;
this.limit = true;
return this;
}
@Override

View File

@ -185,8 +185,8 @@ public class PercolatorService extends AbstractComponent {
throw new ElasticsearchIllegalArgumentException("Can't highlight if size isn't specified");
}
if (context.size < 0) {
context.size = 0;
if (context.size() < 0) {
context.size(0);
}
// parse the source either into one MemoryIndex, if it is a single document or index multiple docs if nested
@ -294,10 +294,9 @@ public class PercolatorService extends AbstractComponent {
break;
} else if (token.isValue()) {
if ("size".equals(currentFieldName)) {
context.limit = true;
context.size = parser.intValue();
if (context.size < 0) {
throw new ElasticsearchParseException("size is set to [" + context.size + "] and is expected to be higher or equal to 0");
context.size(parser.intValue());
if (context.size() < 0) {
throw new ElasticsearchParseException("size is set to [" + context.size() + "] and is expected to be higher or equal to 0");
}
} else if ("sort".equals(currentFieldName)) {
parseSort(parser, context);
@ -531,7 +530,7 @@ public class PercolatorService extends AbstractComponent {
}
if (collector.exists()) {
if (!context.limit || count < context.size) {
if (!context.limit || count < context.size()) {
matches.add(entry.getKey().bytes);
if (context.highlight() != null) {
highlightPhase.hitExecute(context, context.hitContext());

View File

@ -184,7 +184,7 @@ abstract class QueryCollector extends Collector {
Match(ESLogger logger, PercolateContext context, HighlightPhase highlightPhase) {
super(logger, context);
this.limit = context.limit;
this.size = context.size;
this.size = context.size();
this.context = context;
this.highlightPhase = highlightPhase;
}
@ -243,7 +243,7 @@ abstract class QueryCollector extends Collector {
MatchAndSort(ESLogger logger, PercolateContext context) {
super(logger, context);
// TODO: Use TopFieldCollector.create(...) for ascending and decending scoring?
topDocsCollector = TopScoreDocCollector.create(context.size, false);
topDocsCollector = TopScoreDocCollector.create(context.size(), false);
}
@Override
@ -303,7 +303,7 @@ abstract class QueryCollector extends Collector {
MatchAndScore(ESLogger logger, PercolateContext context, HighlightPhase highlightPhase) {
super(logger, context);
this.limit = context.limit;
this.size = context.size;
this.size = context.size();
this.context = context;
this.highlightPhase = highlightPhase;
}

View File

@ -1256,15 +1256,17 @@ public class PercolatorTests extends ElasticsearchIntegrationTest {
@Test
public void testPercolateSorting_unsupportedField() throws Exception {
client().admin().indices().prepareCreate("my-index").execute().actionGet();
client().admin().indices().prepareCreate("my-index")
.addMapping("my-type", "level", "type=integer")
.get();
ensureGreen();
client().prepareIndex("my-index", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).field("level", 1).endObject())
.execute().actionGet();
.get();
client().prepareIndex("my-index", PercolatorService.TYPE_NAME, "2")
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).field("level", 2).endObject())
.execute().actionGet();
.get();
refresh();
PercolateResponse response = client().preparePercolate().setIndices("my-index").setDocumentType("my-type")