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