make Context generic so we don't have to cast
This commit is contained in:
parent
24c4b27978
commit
6295738d4c
|
@ -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<SubPhaseContext extends FetchSubPhaseContext> {
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<SubPhaseContext extends FetchSubPhaseContext> 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<SubPhaseContext> getContextFactory();
|
||||
}
|
||||
|
|
|
@ -36,11 +36,10 @@ import org.elasticsearch.search.internal.SearchContext;
|
|||
* }
|
||||
* </pre>
|
||||
*/
|
||||
public class FieldDataFieldsParseElement extends FetchSubPhaseParseElement {
|
||||
public class FieldDataFieldsParseElement extends FetchSubPhaseParseElement<FieldDataFieldsContext> {
|
||||
|
||||
@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) {
|
||||
|
|
|
@ -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 extends FetchSubPhaseContext> SubPhaseContext getFetchSubPhaseContext(FetchSubPhase.ContextFactory<SubPhaseContext> contextFactory);
|
||||
|
||||
public abstract SearchContextHighlight highlight();
|
||||
|
||||
|
|
|
@ -183,12 +183,11 @@ public class FetchSubPhasePluginTests extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
}
|
||||
|
||||
public static class TermVectorsFetchParseElement extends FetchSubPhaseParseElement {
|
||||
public static class TermVectorsFetchParseElement extends FetchSubPhaseParseElement<TermVectorsFetchContext> {
|
||||
|
||||
@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);
|
||||
|
|
Loading…
Reference in New Issue