From 6295738d4ca853e33ba753f805b3a74274b921fe Mon Sep 17 00:00:00 2001 From: Britta Weber Date: Wed, 29 Jul 2015 16:00:37 +0200 Subject: [PATCH] make Context generic so we don't have to cast --- .../org/elasticsearch/search/fetch/FetchSubPhase.java | 4 ++-- .../search/fetch/FetchSubPhaseParseElement.java | 8 ++++---- .../fetch/fielddata/FieldDataFieldsParseElement.java | 5 ++--- .../org/elasticsearch/search/internal/SearchContext.java | 2 +- .../search/fetch/FetchSubPhasePluginTests.java | 5 ++--- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/fetch/FetchSubPhase.java b/core/src/main/java/org/elasticsearch/search/fetch/FetchSubPhase.java index 6005313ad29..91cc7034401 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/FetchSubPhase.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/FetchSubPhase.java @@ -121,7 +121,7 @@ public interface FetchSubPhase { * Fetch phases that use the plugin mechanism must provide a ContextFactory to the SearchContext that creates the fetch phase context and also associates them with a name. * See {@link SearchContext#getFetchSubPhaseContext(FetchSubPhase.ContextFactory)} */ - public interface ContextFactory { + public interface ContextFactory { /** * The name of the context. @@ -131,6 +131,6 @@ public interface FetchSubPhase { /** * Creates a new instance of a FetchSubPhaseContext that holds all information a FetchSubPhase needs to execute on hits. */ - public FetchSubPhaseContext newContextInstance(); + public SubPhaseContext newContextInstance(); } } diff --git a/core/src/main/java/org/elasticsearch/search/fetch/FetchSubPhaseParseElement.java b/core/src/main/java/org/elasticsearch/search/fetch/FetchSubPhaseParseElement.java index 3a6518aec04..849b4d1b7c0 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/FetchSubPhaseParseElement.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/FetchSubPhaseParseElement.java @@ -26,11 +26,11 @@ import org.elasticsearch.search.internal.SearchContext; /** * A parse element for a {@link org.elasticsearch.search.fetch.FetchSubPhase} that is used when parsing a search request. */ -public abstract class FetchSubPhaseParseElement implements SearchParseElement { +public abstract class FetchSubPhaseParseElement implements SearchParseElement { @Override final public void parse(XContentParser parser, SearchContext context) throws Exception { - FetchSubPhaseContext fetchSubPhaseContext = context.getFetchSubPhaseContext(getContextFactory()); + SubPhaseContext fetchSubPhaseContext = context.getFetchSubPhaseContext(getContextFactory()); // this is to make sure that the SubFetchPhase knows it should execute fetchSubPhaseContext.setHitExecutionNeeded(true); innerParse(parser, fetchSubPhaseContext); @@ -39,10 +39,10 @@ public abstract class FetchSubPhaseParseElement implements SearchParseElement { /** * Implement the actual parsing here. */ - protected abstract void innerParse(XContentParser parser, FetchSubPhaseContext fetchSubPhaseContext) throws Exception; + protected abstract void innerParse(XContentParser parser, SubPhaseContext fetchSubPhaseContext) throws Exception; /** * Return the ContextFactory for this FetchSubPhase. */ - protected abstract FetchSubPhase.ContextFactory getContextFactory(); + protected abstract FetchSubPhase.ContextFactory getContextFactory(); } diff --git a/core/src/main/java/org/elasticsearch/search/fetch/fielddata/FieldDataFieldsParseElement.java b/core/src/main/java/org/elasticsearch/search/fetch/fielddata/FieldDataFieldsParseElement.java index 993a2c45252..689fd123ee2 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/fielddata/FieldDataFieldsParseElement.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/fielddata/FieldDataFieldsParseElement.java @@ -36,11 +36,10 @@ import org.elasticsearch.search.internal.SearchContext; * } * */ -public class FieldDataFieldsParseElement extends FetchSubPhaseParseElement { +public class FieldDataFieldsParseElement extends FetchSubPhaseParseElement { @Override - protected void innerParse(XContentParser parser, FetchSubPhaseContext fetchSubPhaseContext) throws Exception { - FieldDataFieldsContext fieldDataFieldsContext = (FieldDataFieldsContext) fetchSubPhaseContext; + protected void innerParse(XContentParser parser, FieldDataFieldsContext fieldDataFieldsContext) throws Exception { XContentParser.Token token = parser.currentToken(); if (token == XContentParser.Token.START_ARRAY) { while (parser.nextToken() != XContentParser.Token.END_ARRAY) { diff --git a/core/src/main/java/org/elasticsearch/search/internal/SearchContext.java b/core/src/main/java/org/elasticsearch/search/internal/SearchContext.java index 1ab98b9d21a..901b721c3b5 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/SearchContext.java +++ b/core/src/main/java/org/elasticsearch/search/internal/SearchContext.java @@ -164,7 +164,7 @@ public abstract class SearchContext implements Releasable, HasContextAndHeaders public abstract SearchContext aggregations(SearchContextAggregations aggregations); - public abstract FetchSubPhaseContext getFetchSubPhaseContext(FetchSubPhase.ContextFactory contextFactory); + public abstract SubPhaseContext getFetchSubPhaseContext(FetchSubPhase.ContextFactory contextFactory); public abstract SearchContextHighlight highlight(); diff --git a/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginTests.java b/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginTests.java index 29af400ba58..12a11efa3a6 100644 --- a/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginTests.java +++ b/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginTests.java @@ -183,12 +183,11 @@ public class FetchSubPhasePluginTests extends ElasticsearchIntegrationTest { } } - public static class TermVectorsFetchParseElement extends FetchSubPhaseParseElement { + public static class TermVectorsFetchParseElement extends FetchSubPhaseParseElement { @Override - protected void innerParse(XContentParser parser, FetchSubPhaseContext fetchSubPhaseContext) throws Exception { + protected void innerParse(XContentParser parser, TermVectorsFetchContext termVectorsFetchContext) throws Exception { XContentParser.Token token = parser.currentToken(); - TermVectorsFetchContext termVectorsFetchContext = (TermVectorsFetchContext) fetchSubPhaseContext; if (token == XContentParser.Token.VALUE_STRING) { String fieldName = parser.text(); termVectorsFetchContext.setField(fieldName);