remove hasFetchSubPhaseContext

This commit is contained in:
Britta Weber 2015-07-27 00:38:47 +02:00
parent df339f4cb9
commit ea14f675b2
11 changed files with 76 additions and 35 deletions

View File

@ -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() {

View File

@ -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;
}
} }

View File

@ -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();
}

View File

@ -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;

View File

@ -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

View File

@ -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) {
@ -50,4 +54,9 @@ public class FieldDataFieldsParseElement implements SearchParseElement {
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;
}
} }

View File

@ -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;

View File

@ -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);
}
} }

View File

@ -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.
*/ */

View File

@ -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;

View File

@ -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;