remove hasFetchSubPhaseContext
This commit is contained in:
parent
df339f4cb9
commit
ea14f675b2
|
@ -294,11 +294,6 @@ public class PercolateContext extends SearchContext {
|
|||
return subPhaseContexts.get(subPhaseName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFetchSubPhaseContext(FetchSubPhase.ContextFactory contextFactory) {
|
||||
return subPhaseContexts.get(contextFactory.getName()) != null;
|
||||
}
|
||||
|
||||
// Unused:
|
||||
@Override
|
||||
public void preProcess() {
|
||||
|
|
|
@ -19,6 +19,16 @@
|
|||
|
||||
package org.elasticsearch.search.fetch;
|
||||
|
||||
public interface FetchSubPhaseContext {
|
||||
public class FetchSubPhaseContext {
|
||||
|
||||
private boolean hitExecutionNeeded = false;
|
||||
|
||||
void setHitExecutionNeeded(boolean hitExecutionNeeded) {
|
||||
this.hitExecutionNeeded = hitExecutionNeeded;
|
||||
}
|
||||
|
||||
public boolean hitExecutionNeeded() {
|
||||
return hitExecutionNeeded;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
public abstract class FetchSubPhaseParseElement implements SearchParseElement {
|
||||
|
||||
@Override
|
||||
public void parse(XContentParser parser, SearchContext context) throws Exception {
|
||||
FetchSubPhaseContext fetchSubPhaseContext = context.getFetchSubPhaseContext(getContextFactory());
|
||||
fetchSubPhaseContext.setHitExecutionNeeded(true);
|
||||
innerParse(parser, fetchSubPhaseContext);
|
||||
}
|
||||
|
||||
protected abstract void innerParse(XContentParser parser, FetchSubPhaseContext fetchSubPhaseContext) throws Exception;
|
||||
|
||||
protected abstract FetchSubPhase.ContextFactory getContextFactory();
|
||||
}
|
|
@ -26,7 +26,7 @@ import java.util.List;
|
|||
/**
|
||||
* All the required context to pull a field from the field data cache.
|
||||
*/
|
||||
public class FieldDataFieldsContext implements FetchSubPhaseContext{
|
||||
public class FieldDataFieldsContext extends FetchSubPhaseContext {
|
||||
|
||||
public static class FieldDataField {
|
||||
private final String name;
|
||||
|
|
|
@ -81,7 +81,7 @@ public class FieldDataFieldsFetchSubPhase implements FetchSubPhase {
|
|||
|
||||
@Override
|
||||
public boolean hitExecutionNeeded(SearchContext context) {
|
||||
return context.hasFetchSubPhaseContext(CONTEXT_FACTORY);
|
||||
return context.getFetchSubPhaseContext(CONTEXT_FACTORY).hitExecutionNeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,12 +20,15 @@ package org.elasticsearch.search.fetch.fielddata;
|
|||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.search.SearchParseElement;
|
||||
import org.elasticsearch.search.fetch.FetchSubPhase;
|
||||
import org.elasticsearch.search.fetch.FetchSubPhaseContext;
|
||||
import org.elasticsearch.search.fetch.FetchSubPhaseParseElement;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
/**
|
||||
* Parses field name values from the {@code fielddata_fields} parameter in a
|
||||
* search request.
|
||||
*
|
||||
* <p/>
|
||||
* <pre>
|
||||
* {
|
||||
* "query": {...},
|
||||
|
@ -33,10 +36,11 @@ import org.elasticsearch.search.internal.SearchContext;
|
|||
* }
|
||||
* </pre>
|
||||
*/
|
||||
public class FieldDataFieldsParseElement implements SearchParseElement {
|
||||
public class FieldDataFieldsParseElement extends FetchSubPhaseParseElement {
|
||||
|
||||
@Override
|
||||
public void parse(XContentParser parser, SearchContext context) throws Exception {
|
||||
FieldDataFieldsContext fieldDataFieldsContext = (FieldDataFieldsContext)context.getFetchSubPhaseContext(FieldDataFieldsFetchSubPhase.CONTEXT_FACTORY);
|
||||
protected void innerParse(XContentParser parser, FetchSubPhaseContext fetchSubPhaseContext) throws Exception {
|
||||
FieldDataFieldsContext fieldDataFieldsContext = (FieldDataFieldsContext) fetchSubPhaseContext;
|
||||
XContentParser.Token token = parser.currentToken();
|
||||
if (token == XContentParser.Token.START_ARRAY) {
|
||||
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
|
||||
|
@ -50,4 +54,9 @@ public class FieldDataFieldsParseElement implements SearchParseElement {
|
|||
throw new IllegalStateException("Expected either a VALUE_STRING or an START_ARRAY but got " + token);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FetchSubPhase.ContextFactory getContextFactory() {
|
||||
return FieldDataFieldsFetchSubPhase.CONTEXT_FACTORY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -727,11 +727,6 @@ public class DefaultSearchContext extends SearchContext {
|
|||
return timeEstimateCounter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFetchSubPhaseContext(FetchSubPhase.ContextFactory contextFactory) {
|
||||
return subPhaseContexts.get(contextFactory.getName()) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void innerHits(InnerHitsContext innerHitsContext) {
|
||||
this.innerHitsContext = innerHitsContext;
|
||||
|
|
|
@ -625,9 +625,4 @@ public abstract class FilteredSearchContext extends SearchContext {
|
|||
public FetchSubPhaseContext getFetchSubPhaseContext(FetchSubPhase.ContextFactory subPhase) {
|
||||
return in.getFetchSubPhaseContext(subPhase);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFetchSubPhaseContext(FetchSubPhase.ContextFactory contextFactory) {
|
||||
return in.hasFetchSubPhaseContext(contextFactory);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -360,8 +360,6 @@ public abstract class SearchContext implements Releasable, HasContextAndHeaders
|
|||
|
||||
public abstract Counter timeEstimateCounter();
|
||||
|
||||
public abstract boolean hasFetchSubPhaseContext(FetchSubPhase.ContextFactory contextFactory);
|
||||
|
||||
/**
|
||||
* The life time of an object that is used during search execution.
|
||||
*/
|
||||
|
|
|
@ -153,7 +153,7 @@ public class FetchSubPhasePluginTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Override
|
||||
public boolean hitExecutionNeeded(SearchContext context) {
|
||||
return context.hasFetchSubPhaseContext(CONTEXT_FACTORY);
|
||||
return context.getFetchSubPhaseContext(CONTEXT_FACTORY).hitExecutionNeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -183,21 +183,27 @@ public class FetchSubPhasePluginTests extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
}
|
||||
|
||||
public static class TermVectorsFetchParseElement implements SearchParseElement {
|
||||
public static class TermVectorsFetchParseElement extends FetchSubPhaseParseElement {
|
||||
|
||||
@Override
|
||||
public void parse(XContentParser parser, SearchContext context) throws Exception {
|
||||
protected void innerParse(XContentParser parser, FetchSubPhaseContext fetchSubPhaseContext) throws Exception {
|
||||
XContentParser.Token token = parser.currentToken();
|
||||
TermVectorsFetchContext termVectorsFetchContext = (TermVectorsFetchContext) fetchSubPhaseContext;
|
||||
if (token == XContentParser.Token.VALUE_STRING) {
|
||||
String fieldName = parser.text();
|
||||
((TermVectorsFetchContext) context.getFetchSubPhaseContext(TermVectorsFetchSubPhase.CONTEXT_FACTORY)).setField(fieldName);
|
||||
termVectorsFetchContext.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 implements FetchSubPhaseContext {
|
||||
public static class TermVectorsFetchContext extends FetchSubPhaseContext {
|
||||
|
||||
private String field = null;
|
||||
|
||||
|
|
|
@ -213,11 +213,6 @@ public class TestSearchContext extends SearchContext {
|
|||
return subPhaseContexts.get(subPhaseName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFetchSubPhaseContext(FetchSubPhase.ContextFactory contextFactory) {
|
||||
return subPhaseContexts.get(contextFactory.getName()) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchContextHighlight highlight() {
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue