Changing parse signature in QueryParseElement
This commit is contained in:
parent
e883febfb8
commit
4b736d2e0c
|
@ -39,6 +39,7 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.IndexService;
|
import org.elasticsearch.index.IndexService;
|
||||||
import org.elasticsearch.index.engine.Engine;
|
import org.elasticsearch.index.engine.Engine;
|
||||||
|
import org.elasticsearch.index.query.QueryShardContext;
|
||||||
import org.elasticsearch.index.shard.IndexShard;
|
import org.elasticsearch.index.shard.IndexShard;
|
||||||
import org.elasticsearch.index.suggest.stats.ShardSuggestMetric;
|
import org.elasticsearch.index.suggest.stats.ShardSuggestMetric;
|
||||||
import org.elasticsearch.indices.IndicesService;
|
import org.elasticsearch.indices.IndicesService;
|
||||||
|
@ -131,6 +132,7 @@ public class TransportSuggestAction extends TransportBroadcastAction<SuggestRequ
|
||||||
protected ShardSuggestResponse shardOperation(ShardSuggestRequest request) {
|
protected ShardSuggestResponse shardOperation(ShardSuggestRequest request) {
|
||||||
IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
|
IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
|
||||||
IndexShard indexShard = indexService.getShard(request.shardId().id());
|
IndexShard indexShard = indexService.getShard(request.shardId().id());
|
||||||
|
QueryShardContext shardContext = indexShard.getQueryShardContext();
|
||||||
ShardSuggestMetric suggestMetric = indexShard.getSuggestMetric();
|
ShardSuggestMetric suggestMetric = indexShard.getSuggestMetric();
|
||||||
suggestMetric.preSuggest();
|
suggestMetric.preSuggest();
|
||||||
long startTime = System.nanoTime();
|
long startTime = System.nanoTime();
|
||||||
|
@ -142,8 +144,7 @@ public class TransportSuggestAction extends TransportBroadcastAction<SuggestRequ
|
||||||
if (parser.nextToken() != XContentParser.Token.START_OBJECT) {
|
if (parser.nextToken() != XContentParser.Token.START_OBJECT) {
|
||||||
throw new IllegalArgumentException("suggest content missing");
|
throw new IllegalArgumentException("suggest content missing");
|
||||||
}
|
}
|
||||||
final SuggestionSearchContext context = suggestPhase.parseElement().parseInternal(parser, indexService.mapperService(),
|
final SuggestionSearchContext context = suggestPhase.parseElement().parseInternal(parser, indexShard.getQueryShardContext());
|
||||||
indexService.fieldData(), request.shardId().getIndexName(), request.shardId().id());
|
|
||||||
final Suggest result = suggestPhase.execute(context, searcher.searcher());
|
final Suggest result = suggestPhase.execute(context, searcher.searcher());
|
||||||
return new ShardSuggestResponse(request.shardId(), result);
|
return new ShardSuggestResponse(request.shardId(), result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,11 @@
|
||||||
package org.elasticsearch.search.suggest;
|
package org.elasticsearch.search.suggest;
|
||||||
|
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.fielddata.IndexFieldDataService;
|
import org.elasticsearch.index.query.QueryShardContext;
|
||||||
import org.elasticsearch.index.mapper.MapperService;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public interface SuggestContextParser {
|
public interface SuggestContextParser {
|
||||||
SuggestionSearchContext.SuggestionContext parse(XContentParser parser, MapperService mapperService, IndexFieldDataService indexFieldDataService) throws IOException;
|
SuggestionSearchContext.SuggestionContext parse(XContentParser parser, QueryShardContext shardContext) throws IOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,8 @@ package org.elasticsearch.search.suggest;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.fielddata.IndexFieldDataService;
|
|
||||||
import org.elasticsearch.index.mapper.MapperService;
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
|
import org.elasticsearch.index.query.QueryShardContext;
|
||||||
import org.elasticsearch.search.SearchParseElement;
|
import org.elasticsearch.search.SearchParseElement;
|
||||||
import org.elasticsearch.search.internal.SearchContext;
|
import org.elasticsearch.search.internal.SearchContext;
|
||||||
import org.elasticsearch.search.suggest.SuggestionSearchContext.SuggestionContext;
|
import org.elasticsearch.search.suggest.SuggestionSearchContext.SuggestionContext;
|
||||||
|
@ -44,14 +44,13 @@ public final class SuggestParseElement implements SearchParseElement {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void parse(XContentParser parser, SearchContext context) throws Exception {
|
public void parse(XContentParser parser, SearchContext context) throws Exception {
|
||||||
SuggestionSearchContext suggestionSearchContext = parseInternal(parser, context.mapperService(), context.fieldData(),
|
SuggestionSearchContext suggestionSearchContext = parseInternal(parser, context.indexShard().getQueryShardContext());
|
||||||
context.shardTarget().index(), context.shardTarget().shardId());
|
|
||||||
context.suggest(suggestionSearchContext);
|
context.suggest(suggestionSearchContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SuggestionSearchContext parseInternal(XContentParser parser, MapperService mapperService, IndexFieldDataService fieldDataService,
|
public SuggestionSearchContext parseInternal(XContentParser parser, QueryShardContext shardContext) throws IOException {
|
||||||
String index, int shardId) throws IOException {
|
|
||||||
SuggestionSearchContext suggestionSearchContext = new SuggestionSearchContext();
|
SuggestionSearchContext suggestionSearchContext = new SuggestionSearchContext();
|
||||||
|
MapperService mapperService = shardContext.getMapperService();
|
||||||
|
|
||||||
BytesRef globalText = null;
|
BytesRef globalText = null;
|
||||||
String fieldName = null;
|
String fieldName = null;
|
||||||
|
@ -95,7 +94,7 @@ public final class SuggestParseElement implements SearchParseElement {
|
||||||
throw new IllegalArgumentException("Suggester[" + fieldName + "] not supported");
|
throw new IllegalArgumentException("Suggester[" + fieldName + "] not supported");
|
||||||
}
|
}
|
||||||
final SuggestContextParser contextParser = suggesters.get(fieldName).getContextParser();
|
final SuggestContextParser contextParser = suggesters.get(fieldName).getContextParser();
|
||||||
suggestionContext = contextParser.parse(parser, mapperService, fieldDataService);
|
suggestionContext = contextParser.parse(parser, shardContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (suggestionContext != null) {
|
if (suggestionContext != null) {
|
||||||
|
@ -109,7 +108,10 @@ public final class SuggestParseElement implements SearchParseElement {
|
||||||
suggestionContext.setRegex(regex);
|
suggestionContext.setRegex(regex);
|
||||||
suggestionContext.setText(regex);
|
suggestionContext.setText(regex);
|
||||||
}
|
}
|
||||||
|
suggestionContext.setShardContext(shardContext);
|
||||||
suggestionContexts.put(suggestionName, suggestionContext);
|
suggestionContexts.put(suggestionName, suggestionContext);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("suggestion context could not be parsed correctly");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.elasticsearch.search.suggest;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
|
import org.elasticsearch.index.query.QueryShardContext;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -47,6 +48,7 @@ public class SuggestionSearchContext {
|
||||||
private Analyzer analyzer;
|
private Analyzer analyzer;
|
||||||
private int size = 5;
|
private int size = 5;
|
||||||
private int shardSize = -1;
|
private int shardSize = -1;
|
||||||
|
private QueryShardContext shardContext;
|
||||||
|
|
||||||
public BytesRef getText() {
|
public BytesRef getText() {
|
||||||
return text;
|
return text;
|
||||||
|
@ -117,6 +119,14 @@ public class SuggestionSearchContext {
|
||||||
}
|
}
|
||||||
this.shardSize = shardSize;
|
this.shardSize = shardSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setShardContext(QueryShardContext context) {
|
||||||
|
this.shardContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueryShardContext getShardContext() {
|
||||||
|
return this.shardContext;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,17 +20,16 @@ package org.elasticsearch.search.suggest.completion;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.elasticsearch.ElasticsearchException;
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.common.ParseField;
|
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.unit.Fuzziness;
|
import org.elasticsearch.common.unit.Fuzziness;
|
||||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.fielddata.IndexFieldDataService;
|
|
||||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||||
import org.elasticsearch.index.mapper.MapperService;
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
import org.elasticsearch.index.mapper.core.CompletionFieldMapper;
|
import org.elasticsearch.index.mapper.core.CompletionFieldMapper;
|
||||||
|
import org.elasticsearch.index.query.QueryShardContext;
|
||||||
import org.elasticsearch.index.query.RegexpFlag;
|
import org.elasticsearch.index.query.RegexpFlag;
|
||||||
import org.elasticsearch.search.suggest.SuggestContextParser;
|
import org.elasticsearch.search.suggest.SuggestContextParser;
|
||||||
import org.elasticsearch.search.suggest.SuggestUtils.Fields;
|
import org.elasticsearch.search.suggest.SuggestUtils.Fields;
|
||||||
|
@ -135,8 +134,9 @@ public class CompletionSuggestParser implements SuggestContextParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SuggestionSearchContext.SuggestionContext parse(XContentParser parser, MapperService mapperService, IndexFieldDataService fieldDataService) throws IOException {
|
public SuggestionSearchContext.SuggestionContext parse(XContentParser parser, QueryShardContext shardContext) throws IOException {
|
||||||
final CompletionSuggestionContext suggestion = new CompletionSuggestionContext(completionSuggester, mapperService, fieldDataService);
|
MapperService mapperService = shardContext.getMapperService();
|
||||||
|
final CompletionSuggestionContext suggestion = new CompletionSuggestionContext(completionSuggester, mapperService);
|
||||||
final ContextAndSuggest contextAndSuggest = new ContextAndSuggest(mapperService);
|
final ContextAndSuggest contextAndSuggest = new ContextAndSuggest(mapperService);
|
||||||
TLP_PARSER.parse(parser, suggestion, contextAndSuggest);
|
TLP_PARSER.parse(parser, suggestion, contextAndSuggest);
|
||||||
final XContentParser contextParser = contextAndSuggest.contextParser;
|
final XContentParser contextParser = contextAndSuggest.contextParser;
|
||||||
|
|
|
@ -35,6 +35,7 @@ import org.elasticsearch.index.fielddata.AtomicFieldData;
|
||||||
import org.elasticsearch.index.fielddata.ScriptDocValues;
|
import org.elasticsearch.index.fielddata.ScriptDocValues;
|
||||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||||
import org.elasticsearch.index.mapper.core.CompletionFieldMapper;
|
import org.elasticsearch.index.mapper.core.CompletionFieldMapper;
|
||||||
|
import org.elasticsearch.index.query.QueryShardContext;
|
||||||
import org.elasticsearch.search.suggest.Suggest;
|
import org.elasticsearch.search.suggest.Suggest;
|
||||||
import org.elasticsearch.search.suggest.SuggestContextParser;
|
import org.elasticsearch.search.suggest.SuggestContextParser;
|
||||||
import org.elasticsearch.search.suggest.Suggester;
|
import org.elasticsearch.search.suggest.Suggester;
|
||||||
|
@ -90,7 +91,8 @@ public class CompletionSuggester extends Suggester<CompletionSuggestionContext>
|
||||||
for (String field : payloadFields) {
|
for (String field : payloadFields) {
|
||||||
MappedFieldType payloadFieldType = suggestionContext.getMapperService().fullName(field);
|
MappedFieldType payloadFieldType = suggestionContext.getMapperService().fullName(field);
|
||||||
if (payloadFieldType != null) {
|
if (payloadFieldType != null) {
|
||||||
final AtomicFieldData data = suggestionContext.getIndexFieldDataService().getForField(payloadFieldType)
|
QueryShardContext shardContext = suggestionContext.getShardContext();
|
||||||
|
final AtomicFieldData data = shardContext.getForField(payloadFieldType)
|
||||||
.load(subReaderContext);
|
.load(subReaderContext);
|
||||||
final ScriptDocValues scriptValues = data.getScriptValues();
|
final ScriptDocValues scriptValues = data.getScriptValues();
|
||||||
scriptValues.setNextDocId(subDocId);
|
scriptValues.setNextDocId(subDocId);
|
||||||
|
|
|
@ -20,7 +20,6 @@ package org.elasticsearch.search.suggest.completion;
|
||||||
|
|
||||||
import org.apache.lucene.search.suggest.document.CompletionQuery;
|
import org.apache.lucene.search.suggest.document.CompletionQuery;
|
||||||
import org.elasticsearch.common.unit.Fuzziness;
|
import org.elasticsearch.common.unit.Fuzziness;
|
||||||
import org.elasticsearch.index.fielddata.IndexFieldDataService;
|
|
||||||
import org.elasticsearch.index.mapper.MapperService;
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
import org.elasticsearch.index.mapper.core.CompletionFieldMapper;
|
import org.elasticsearch.index.mapper.core.CompletionFieldMapper;
|
||||||
import org.elasticsearch.search.suggest.Suggester;
|
import org.elasticsearch.search.suggest.Suggester;
|
||||||
|
@ -44,12 +43,10 @@ public class CompletionSuggestionContext extends SuggestionSearchContext.Suggest
|
||||||
private CompletionSuggestionBuilder.RegexOptionsBuilder regexOptionsBuilder;
|
private CompletionSuggestionBuilder.RegexOptionsBuilder regexOptionsBuilder;
|
||||||
private Map<String, List<ContextMapping.QueryContext>> queryContexts = Collections.emptyMap();
|
private Map<String, List<ContextMapping.QueryContext>> queryContexts = Collections.emptyMap();
|
||||||
private final MapperService mapperService;
|
private final MapperService mapperService;
|
||||||
private final IndexFieldDataService indexFieldDataService;
|
|
||||||
private Set<String> payloadFields = Collections.emptySet();
|
private Set<String> payloadFields = Collections.emptySet();
|
||||||
|
|
||||||
CompletionSuggestionContext(Suggester suggester, MapperService mapperService, IndexFieldDataService indexFieldDataService) {
|
CompletionSuggestionContext(Suggester suggester, MapperService mapperService) {
|
||||||
super(suggester);
|
super(suggester);
|
||||||
this.indexFieldDataService = indexFieldDataService;
|
|
||||||
this.mapperService = mapperService;
|
this.mapperService = mapperService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,10 +75,6 @@ public class CompletionSuggestionContext extends SuggestionSearchContext.Suggest
|
||||||
return mapperService;
|
return mapperService;
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexFieldDataService getIndexFieldDataService() {
|
|
||||||
return indexFieldDataService;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPayloadFields(Set<String> fields) {
|
void setPayloadFields(Set<String> fields) {
|
||||||
this.payloadFields = fields;
|
this.payloadFields = fields;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,9 @@ import org.elasticsearch.common.ParseFieldMatcher;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser.Token;
|
import org.elasticsearch.common.xcontent.XContentParser.Token;
|
||||||
import org.elasticsearch.index.analysis.ShingleTokenFilterFactory;
|
import org.elasticsearch.index.analysis.ShingleTokenFilterFactory;
|
||||||
import org.elasticsearch.index.fielddata.IndexFieldDataService;
|
|
||||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||||
import org.elasticsearch.index.mapper.MapperService;
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
|
import org.elasticsearch.index.query.QueryShardContext;
|
||||||
import org.elasticsearch.script.CompiledScript;
|
import org.elasticsearch.script.CompiledScript;
|
||||||
import org.elasticsearch.script.ScriptContext;
|
import org.elasticsearch.script.ScriptContext;
|
||||||
import org.elasticsearch.script.Template;
|
import org.elasticsearch.script.Template;
|
||||||
|
@ -51,7 +51,8 @@ public final class PhraseSuggestParser implements SuggestContextParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SuggestionSearchContext.SuggestionContext parse(XContentParser parser, MapperService mapperService, IndexFieldDataService fieldDataService) throws IOException {
|
public SuggestionSearchContext.SuggestionContext parse(XContentParser parser, QueryShardContext shardContext) throws IOException {
|
||||||
|
MapperService mapperService = shardContext.getMapperService();
|
||||||
PhraseSuggestionContext suggestion = new PhraseSuggestionContext(suggester);
|
PhraseSuggestionContext suggestion = new PhraseSuggestionContext(suggester);
|
||||||
ParseFieldMatcher parseFieldMatcher = mapperService.getIndexSettings().getParseFieldMatcher();
|
ParseFieldMatcher parseFieldMatcher = mapperService.getIndexSettings().getParseFieldMatcher();
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
|
|
|
@ -42,6 +42,7 @@ import org.elasticsearch.search.suggest.SuggestContextParser;
|
||||||
import org.elasticsearch.search.suggest.SuggestUtils;
|
import org.elasticsearch.search.suggest.SuggestUtils;
|
||||||
import org.elasticsearch.search.suggest.Suggester;
|
import org.elasticsearch.search.suggest.Suggester;
|
||||||
import org.elasticsearch.search.suggest.SuggestionBuilder;
|
import org.elasticsearch.search.suggest.SuggestionBuilder;
|
||||||
|
import org.elasticsearch.search.suggest.SuggestionSearchContext.SuggestionContext;
|
||||||
import org.elasticsearch.search.suggest.phrase.NoisyChannelSpellChecker.Result;
|
import org.elasticsearch.search.suggest.phrase.NoisyChannelSpellChecker.Result;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -143,7 +144,7 @@ public final class PhraseSuggester extends Suggester<PhraseSuggestionContext> {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PhraseSuggestion.Entry buildResultEntry(PhraseSuggestionContext suggestion, CharsRefBuilder spare, double cutoffScore) {
|
private PhraseSuggestion.Entry buildResultEntry(SuggestionContext suggestion, CharsRefBuilder spare, double cutoffScore) {
|
||||||
spare.copyUTF8Bytes(suggestion.getText());
|
spare.copyUTF8Bytes(suggestion.getText());
|
||||||
return new PhraseSuggestion.Entry(new Text(spare.toString()), 0, spare.length(), cutoffScore);
|
return new PhraseSuggestion.Entry(new Text(spare.toString()), 0, spare.length(), cutoffScore);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ package org.elasticsearch.search.suggest.phrase;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.index.query.QueryShardContext;
|
|
||||||
import org.elasticsearch.script.CompiledScript;
|
import org.elasticsearch.script.CompiledScript;
|
||||||
import org.elasticsearch.search.suggest.DirectSpellcheckerSettings;
|
import org.elasticsearch.search.suggest.DirectSpellcheckerSettings;
|
||||||
import org.elasticsearch.search.suggest.Suggester;
|
import org.elasticsearch.search.suggest.Suggester;
|
||||||
|
@ -31,7 +30,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
class PhraseSuggestionContext extends SuggestionContext {
|
public class PhraseSuggestionContext extends SuggestionContext {
|
||||||
static final boolean DEFAULT_COLLATE_PRUNE = false;
|
static final boolean DEFAULT_COLLATE_PRUNE = false;
|
||||||
static final boolean DEFAULT_REQUIRE_UNIGRAM = true;
|
static final boolean DEFAULT_REQUIRE_UNIGRAM = true;
|
||||||
static final float DEFAULT_CONFIDENCE = 1.0f;
|
static final float DEFAULT_CONFIDENCE = 1.0f;
|
||||||
|
@ -54,7 +53,6 @@ class PhraseSuggestionContext extends SuggestionContext {
|
||||||
private List<DirectCandidateGenerator> generators = new ArrayList<>();
|
private List<DirectCandidateGenerator> generators = new ArrayList<>();
|
||||||
private Map<String, Object> collateScriptParams = new HashMap<>(1);
|
private Map<String, Object> collateScriptParams = new HashMap<>(1);
|
||||||
private WordScorer.WordScorerFactory scorer;
|
private WordScorer.WordScorerFactory scorer;
|
||||||
private QueryShardContext shardContext;
|
|
||||||
|
|
||||||
public PhraseSuggestionContext(Suggester<? extends PhraseSuggestionContext> suggester) {
|
public PhraseSuggestionContext(Suggester<? extends PhraseSuggestionContext> suggester) {
|
||||||
super(suggester);
|
super(suggester);
|
||||||
|
@ -216,12 +214,4 @@ class PhraseSuggestionContext extends SuggestionContext {
|
||||||
return prune;
|
return prune;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShardContext(QueryShardContext context) {
|
|
||||||
this.shardContext = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public QueryShardContext getShardContext() {
|
|
||||||
return this.shardContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,8 @@ package org.elasticsearch.search.suggest.term;
|
||||||
|
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
import org.elasticsearch.common.ParseFieldMatcher;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.fielddata.IndexFieldDataService;
|
|
||||||
import org.elasticsearch.index.mapper.MapperService;
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
|
import org.elasticsearch.index.query.QueryShardContext;
|
||||||
import org.elasticsearch.search.suggest.DirectSpellcheckerSettings;
|
import org.elasticsearch.search.suggest.DirectSpellcheckerSettings;
|
||||||
import org.elasticsearch.search.suggest.SuggestContextParser;
|
import org.elasticsearch.search.suggest.SuggestContextParser;
|
||||||
import org.elasticsearch.search.suggest.SuggestUtils;
|
import org.elasticsearch.search.suggest.SuggestUtils;
|
||||||
|
@ -38,7 +38,8 @@ public final class TermSuggestParser implements SuggestContextParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SuggestionSearchContext.SuggestionContext parse(XContentParser parser, MapperService mapperService, IndexFieldDataService fieldDataService) throws IOException {
|
public SuggestionSearchContext.SuggestionContext parse(XContentParser parser, QueryShardContext shardContext) throws IOException {
|
||||||
|
MapperService mapperService = shardContext.getMapperService();
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
String fieldName = null;
|
String fieldName = null;
|
||||||
TermSuggestionContext suggestion = new TermSuggestionContext(suggester);
|
TermSuggestionContext suggestion = new TermSuggestionContext(suggester);
|
||||||
|
|
|
@ -271,7 +271,7 @@ public abstract class AbstractSuggestionBuilderTestCase<SB extends SuggestionBui
|
||||||
|
|
||||||
XContentParser parser = XContentHelper.createParser(xContentBuilder.bytes());
|
XContentParser parser = XContentHelper.createParser(xContentBuilder.bytes());
|
||||||
parser.nextToken(); // set cursor to START_OBJECT
|
parser.nextToken(); // set cursor to START_OBJECT
|
||||||
SuggestionSearchContext suggestionSearchContext = parseElement.parseInternal(parser, mockMapperService, null, "test", 1);
|
SuggestionSearchContext suggestionSearchContext = parseElement.parseInternal(parser, mockShardContext);
|
||||||
SuggestionContext oldSchoolContext = suggestionSearchContext.suggestions().get(suggestionBuilder.name());
|
SuggestionContext oldSchoolContext = suggestionSearchContext.suggestions().get(suggestionBuilder.name());
|
||||||
|
|
||||||
SuggestionContext newSchoolContext = suggestionBuilder.build(mockShardContext);
|
SuggestionContext newSchoolContext = suggestionBuilder.build(mockShardContext);
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class CustomSuggester extends Suggester<CustomSuggester.CustomSuggestions
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SuggestContextParser getContextParser() {
|
public SuggestContextParser getContextParser() {
|
||||||
return (parser, mapperService, fieldData) -> {
|
return (parser, shardContext) -> {
|
||||||
Map<String, Object> options = parser.map();
|
Map<String, Object> options = parser.map();
|
||||||
CustomSuggestionsContext suggestionContext = new CustomSuggestionsContext(CustomSuggester.this, options);
|
CustomSuggestionsContext suggestionContext = new CustomSuggestionsContext(CustomSuggester.this, options);
|
||||||
suggestionContext.setField((String) options.get("field"));
|
suggestionContext.setField((String) options.get("field"));
|
||||||
|
|
Loading…
Reference in New Issue