From ab144c418e3bd50621075b3af66e191a61635d16 Mon Sep 17 00:00:00 2001 From: javanna Date: Thu, 12 Jan 2017 17:58:26 +0100 Subject: [PATCH] replace ShardSearchRequest.FilterParser functional interface with CheckedFunction --- .../index/query/functionscore/ScoreFunctionParser.java | 3 +-- .../java/org/elasticsearch/indices/IndicesService.java | 4 +++- .../org/elasticsearch/search/internal/AliasFilter.java | 3 ++- .../search/internal/ShardSearchRequest.java | 9 +++------ .../internal/ShardSearchTransportRequestTests.java | 3 ++- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/query/functionscore/ScoreFunctionParser.java b/core/src/main/java/org/elasticsearch/index/query/functionscore/ScoreFunctionParser.java index 3c01c2d92f3..1a2fad90c46 100644 --- a/core/src/main/java/org/elasticsearch/index/query/functionscore/ScoreFunctionParser.java +++ b/core/src/main/java/org/elasticsearch/index/query/functionscore/ScoreFunctionParser.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.query.functionscore; -import org.elasticsearch.common.ParsingException; import org.elasticsearch.index.query.QueryParseContext; import java.io.IOException; @@ -29,5 +28,5 @@ import java.io.IOException; */ @FunctionalInterface public interface ScoreFunctionParser> { - FB fromXContent(QueryParseContext context) throws IOException, ParsingException; + FB fromXContent(QueryParseContext context) throws IOException; } diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesService.java b/core/src/main/java/org/elasticsearch/indices/IndicesService.java index 77a948ecb14..6778b941219 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -42,6 +42,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.routing.RecoverySource; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.breaker.CircuitBreaker; import org.elasticsearch.common.bytes.BytesArray; @@ -87,6 +88,7 @@ import org.elasticsearch.index.get.GetStats; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.merge.MergeStats; +import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.recovery.RecoveryStats; import org.elasticsearch.index.refresh.RefreshStats; @@ -1251,7 +1253,7 @@ public class IndicesService extends AbstractLifecycleComponent public AliasFilter buildAliasFilter(ClusterState state, String index, String... expressions) { /* Being static, parseAliasFilter doesn't have access to whatever guts it needs to parse a query. Instead of passing in a bunch * of dependencies we pass in a function that can perform the parsing. */ - ShardSearchRequest.FilterParser filterParser = bytes -> { + CheckedFunction filterParser = bytes -> { try (XContentParser parser = XContentFactory.xContent(bytes).createParser(xContentRegistry, bytes)) { return new QueryParseContext(parser).parseInnerQueryBuilder(); } diff --git a/core/src/main/java/org/elasticsearch/search/internal/AliasFilter.java b/core/src/main/java/org/elasticsearch/search/internal/AliasFilter.java index 8d55dfbab07..ed82cbd1b69 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/AliasFilter.java +++ b/core/src/main/java/org/elasticsearch/search/internal/AliasFilter.java @@ -21,6 +21,7 @@ package org.elasticsearch.search.internal; import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -66,7 +67,7 @@ public final class AliasFilter implements Writeable { final IndexMetaData indexMetaData = context.getIndexSettings().getIndexMetaData(); /* Being static, parseAliasFilter doesn't have access to whatever guts it needs to parse a query. Instead of passing in a bunch * of dependencies we pass in a function that can perform the parsing. */ - ShardSearchRequest.FilterParser filterParser = bytes -> { + CheckedFunction filterParser = bytes -> { try (XContentParser parser = XContentFactory.xContent(bytes).createParser(context.getXContentRegistry(), bytes)) { return context.newParseContext(parser).parseInnerQueryBuilder(); } diff --git a/core/src/main/java/org/elasticsearch/search/internal/ShardSearchRequest.java b/core/src/main/java/org/elasticsearch/search/internal/ShardSearchRequest.java index f021d7730cf..dd08cb49353 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/ShardSearchRequest.java +++ b/core/src/main/java/org/elasticsearch/search/internal/ShardSearchRequest.java @@ -22,6 +22,7 @@ package org.elasticsearch.search.internal; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.index.Index; @@ -88,17 +89,13 @@ public interface ShardSearchRequest { */ void rewrite(QueryShardContext context) throws IOException; - @FunctionalInterface - public interface FilterParser { - QueryBuilder parse(byte[] bytes) throws IOException; - } /** * Returns the filter associated with listed filtering aliases. *

* The list of filtering aliases should be obtained by calling MetaData.filteringAliases. * Returns null if no filtering is required.

*/ - static QueryBuilder parseAliasFilter(FilterParser filterParser, + static QueryBuilder parseAliasFilter(CheckedFunction filterParser, IndexMetaData metaData, String... aliasNames) { if (aliasNames == null || aliasNames.length == 0) { return null; @@ -110,7 +107,7 @@ public interface ShardSearchRequest { return null; } try { - return filterParser.parse(alias.filter().uncompressed()); + return filterParser.apply(alias.filter().uncompressed()); } catch (IOException ex) { throw new AliasFilterParsingException(index, alias.getAlias(), "Invalid alias filter", ex); } diff --git a/core/src/test/java/org/elasticsearch/search/internal/ShardSearchTransportRequestTests.java b/core/src/test/java/org/elasticsearch/search/internal/ShardSearchTransportRequestTests.java index 728eee4a850..d0132cca7ad 100644 --- a/core/src/test/java/org/elasticsearch/search/internal/ShardSearchTransportRequestTests.java +++ b/core/src/test/java/org/elasticsearch/search/internal/ShardSearchTransportRequestTests.java @@ -23,6 +23,7 @@ import org.elasticsearch.Version; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; @@ -161,7 +162,7 @@ public class ShardSearchTransportRequestTests extends AbstractSearchTestCase { } public QueryBuilder aliasFilter(IndexMetaData indexMetaData, String... aliasNames) { - ShardSearchRequest.FilterParser filterParser = bytes -> { + CheckedFunction filterParser = bytes -> { try (XContentParser parser = XContentFactory.xContent(bytes).createParser(xContentRegistry(), bytes)) { return new QueryParseContext(parser).parseInnerQueryBuilder(); }