Remove FetchSubPhaseParseElement
With the search refactoring we don't use SearchParseElement anymore to define our own parsing code but only for plugins. There was an abstract subclass called FetchSubPhaseParseElement in our production code, only used in one of our tests. We can remove that abstract class as it is not needed and not that useful for the test that depends on it.
This commit is contained in:
parent
0d21d9ff6e
commit
a96c76dcbd
|
@ -761,7 +761,11 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
|
|||
XContentParser extParser = null;
|
||||
try {
|
||||
extParser = XContentFactory.xContent(source.ext()).createParser(source.ext());
|
||||
XContentParser.Token token = extParser.nextToken();
|
||||
if (extParser.nextToken() != XContentParser.Token.START_OBJECT) {
|
||||
throw new SearchParseException(context, "expected start object, found [" + extParser.currentToken() + "] instead",
|
||||
extParser.getTokenLocation());
|
||||
}
|
||||
XContentParser.Token token;
|
||||
String currentFieldName = null;
|
||||
while ((token = extParser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
|
|
|
@ -31,7 +31,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Sub phase within the fetch phase used to fetch things *about* the documents like highlghting or matched queries.
|
||||
* Sub phase within the fetch phase used to fetch things *about* the documents like highlighting or matched queries.
|
||||
*/
|
||||
public interface FetchSubPhase {
|
||||
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.fetch;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.search.SearchParseElement;
|
||||
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<SubPhaseContext extends FetchSubPhaseContext> implements SearchParseElement {
|
||||
|
||||
@Override
|
||||
public final void parse(XContentParser parser, SearchContext context) throws Exception {
|
||||
SubPhaseContext fetchSubPhaseContext = context.getFetchSubPhaseContext(getContextFactory());
|
||||
// this is to make sure that the SubFetchPhase knows it should execute
|
||||
fetchSubPhaseContext.setHitExecutionNeeded(true);
|
||||
innerParse(parser, fetchSubPhaseContext, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement the actual parsing here.
|
||||
*/
|
||||
protected abstract void innerParse(XContentParser parser, SubPhaseContext fetchSubPhaseContext, SearchContext searchContext) throws Exception;
|
||||
|
||||
/**
|
||||
* Return the ContextFactory for this FetchSubPhase.
|
||||
*/
|
||||
protected abstract FetchSubPhase.ContextFactory<SubPhaseContext> getContextFactory();
|
||||
}
|
|
@ -43,8 +43,8 @@ import org.elasticsearch.test.ESIntegTestCase.Scope;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -56,14 +56,11 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ClusterScope(scope = Scope.SUITE, supportsDedicatedMasters = false, numDataNodes = 1)
|
||||
public class FetchSubPhasePluginIT extends ESIntegTestCase {
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return Arrays.asList(FetchTermVectorsPlugin.class);
|
||||
return Collections.singletonList(FetchTermVectorsPlugin.class);
|
||||
}
|
||||
|
||||
public void testPlugin() throws Exception {
|
||||
|
@ -158,24 +155,21 @@ public class FetchSubPhasePluginIT extends ESIntegTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public static class TermVectorsFetchParseElement extends FetchSubPhaseParseElement<TermVectorsFetchContext> {
|
||||
public static class TermVectorsFetchParseElement implements SearchParseElement {
|
||||
|
||||
@Override
|
||||
protected void innerParse(XContentParser parser, TermVectorsFetchContext termVectorsFetchContext, SearchContext searchContext)
|
||||
throws Exception {
|
||||
public void parse(XContentParser parser, SearchContext context) throws Exception {
|
||||
TermVectorsFetchContext fetchSubPhaseContext = context.getFetchSubPhaseContext(TermVectorsFetchSubPhase.CONTEXT_FACTORY);
|
||||
// this is to make sure that the SubFetchPhase knows it should execute
|
||||
fetchSubPhaseContext.setHitExecutionNeeded(true);
|
||||
XContentParser.Token token = parser.currentToken();
|
||||
if (token == XContentParser.Token.VALUE_STRING) {
|
||||
String fieldName = parser.text();
|
||||
termVectorsFetchContext.setField(fieldName);
|
||||
fetchSubPhaseContext.setField(fieldName);
|
||||
} else {
|
||||
throw new IllegalStateException("Expected a VALUE_STRING but got " + token);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FetchSubPhase.ContextFactory getContextFactory() {
|
||||
return TermVectorsFetchSubPhase.CONTEXT_FACTORY;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TermVectorsFetchContext extends FetchSubPhaseContext {
|
||||
|
|
Loading…
Reference in New Issue