Skip to content

Commit

Permalink
Percolator: Wrongly using analyzer configured for the actual index on…
Browse files Browse the repository at this point in the history
… percolator filtering, closes #1948.
  • Loading branch information
kimchy committed May 13, 2012
1 parent 3b33e3f commit 0c732b8
Showing 1 changed file with 12 additions and 7 deletions.
Expand Up @@ -282,7 +282,7 @@ public Response percolate(final SourceRequest request) throws ElasticSearchExcep
}
} else if (token == XContentParser.Token.START_OBJECT) {
if ("query".equals(currentFieldName)) {
query = queryParserService.parse(parser).query();
query = percolatorIndexServiceSafe().queryParserService().parse(parser).query();
}
} else if (token == null) {
break;
Expand All @@ -306,12 +306,12 @@ public Response percolate(final SourceRequest request) throws ElasticSearchExcep
public Response percolate(DocAndSourceQueryRequest request) throws ElasticSearchException {
Query query = null;
if (Strings.hasLength(request.query()) && !request.query().equals("*")) {
query = queryParserService.parse(QueryBuilders.queryString(request.query())).query();
query = percolatorIndexServiceSafe().queryParserService().parse(QueryBuilders.queryString(request.query())).query();
}
return percolate(new DocAndQueryRequest(request.doc(), query));
}

public Response percolate(DocAndQueryRequest request) throws ElasticSearchException {
private Response percolate(DocAndQueryRequest request) throws ElasticSearchException {
// first, parse the source doc into a MemoryIndex
final CustomMemoryIndex memoryIndex = new CustomMemoryIndex();

Expand Down Expand Up @@ -367,10 +367,7 @@ public Response percolate(DocAndQueryRequest request) throws ElasticSearchExcept
}
}
} else {
IndexService percolatorIndex = indicesService.indexService(PercolatorService.INDEX_NAME);
if (percolatorIndex == null) {
throw new PercolateIndexUnavailable(new Index(PercolatorService.INDEX_NAME));
}
IndexService percolatorIndex = percolatorIndexServiceSafe();
if (percolatorIndex.numberOfShards() == 0) {
throw new PercolateIndexUnavailable(new Index(PercolatorService.INDEX_NAME));
}
Expand All @@ -392,6 +389,14 @@ public Response percolate(DocAndQueryRequest request) throws ElasticSearchExcept
return new Response(matches, request.doc().mappersAdded());
}

private IndexService percolatorIndexServiceSafe() {
IndexService indexService = indicesService.indexService(PercolatorService.INDEX_NAME);
if (indexService == null) {
throw new PercolateIndexUnavailable(new Index(PercolatorService.INDEX_NAME));
}
return indexService;
}

static class QueryCollector extends Collector {
private final IndexSearcher searcher;
private final IndexService percolatorIndex;
Expand Down

0 comments on commit 0c732b8

Please sign in to comment.