mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-01 08:29:09 +00:00
Add ShardId and Index to SuggestionContext
Suggesters might need access to the shard they run on as well as the index they operate on. This patch adds indexname and shard ID to the SuggestionContext Closes #3199
This commit is contained in:
parent
d41c37fdfa
commit
c9c68fced7
@ -158,7 +158,7 @@ public class TransportSuggestAction extends TransportBroadcastOperationAction<Su
|
||||
if (parser.nextToken() != XContentParser.Token.START_OBJECT) {
|
||||
throw new ElasticSearchIllegalArgumentException("suggest content missing");
|
||||
}
|
||||
final SuggestionSearchContext context = suggestPhase.parseElement().parseInternal(parser, indexService.mapperService());
|
||||
final SuggestionSearchContext context = suggestPhase.parseElement().parseInternal(parser, indexService.mapperService(), request.index(), request.shardId());
|
||||
final Suggest result = suggestPhase.execute(context, searcher.reader());
|
||||
return new ShardSuggestResponse(request.index(), request.shardId(), result);
|
||||
}
|
||||
|
@ -18,6 +18,8 @@
|
||||
*/
|
||||
package org.elasticsearch.search.suggest;
|
||||
|
||||
import org.elasticsearch.search.SearchShardTarget;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
@ -32,7 +34,7 @@ import org.elasticsearch.search.suggest.SuggestionSearchContext.SuggestionContex
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class SuggestParseElement implements SearchParseElement {
|
||||
public final class SuggestParseElement implements SearchParseElement {
|
||||
private Suggesters suggesters;
|
||||
|
||||
@Inject
|
||||
@ -42,11 +44,11 @@ public class SuggestParseElement implements SearchParseElement {
|
||||
|
||||
@Override
|
||||
public void parse(XContentParser parser, SearchContext context) throws Exception {
|
||||
SuggestionSearchContext suggestionSearchContext = parseInternal(parser, context.mapperService());
|
||||
SuggestionSearchContext suggestionSearchContext = parseInternal(parser, context.mapperService(), context.shardTarget().index(), context.shardTarget().shardId());
|
||||
context.suggest(suggestionSearchContext);
|
||||
}
|
||||
|
||||
public SuggestionSearchContext parseInternal(XContentParser parser, MapperService mapperService) throws IOException {
|
||||
public SuggestionSearchContext parseInternal(XContentParser parser, MapperService mapperService, String index, int shardId) throws IOException {
|
||||
SuggestionSearchContext suggestionSearchContext = new SuggestionSearchContext();
|
||||
BytesRef globalText = null;
|
||||
String fieldName = null;
|
||||
@ -81,7 +83,12 @@ public class SuggestParseElement implements SearchParseElement {
|
||||
throw new ElasticSearchIllegalArgumentException("Suggester[" + fieldName + "] not supported");
|
||||
}
|
||||
final SuggestContextParser contextParser = suggesters.get(fieldName).getContextParser();
|
||||
parseAndVerify(parser, mapperService, suggestionSearchContext, globalText, suggestionName, suggestText, contextParser);
|
||||
SuggestionContext suggestion = contextParser.parse(parser, mapperService);
|
||||
suggestion.setText(suggestText);
|
||||
suggestion.setShard(shardId);
|
||||
suggestion.setIndex(index);
|
||||
SuggestUtils.verifySuggestion(mapperService, globalText, suggestion);
|
||||
suggestionSearchContext.addSuggestion(suggestionName, suggestion);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -89,13 +96,6 @@ public class SuggestParseElement implements SearchParseElement {
|
||||
return suggestionSearchContext;
|
||||
}
|
||||
|
||||
public void parseAndVerify(XContentParser parser, MapperService mapperService, SuggestionSearchContext suggestionSearchContext,
|
||||
BytesRef globalText, String suggestionName, BytesRef suggestText, SuggestContextParser suggestParser ) throws IOException {
|
||||
SuggestionContext suggestion = suggestParser.parse(parser, mapperService);
|
||||
suggestion.setText(suggestText);
|
||||
SuggestUtils.verifySuggestion(mapperService, globalText, suggestion);
|
||||
suggestionSearchContext.addSuggestion(suggestionName, suggestion);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -91,3 +91,4 @@ public class SuggestPhase extends AbstractComponent implements SearchPhase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,8 @@ public class SuggestionSearchContext {
|
||||
private Analyzer analyzer;
|
||||
private int size = 5;
|
||||
private int shardSize = -1;
|
||||
private int shardId;
|
||||
private String index;
|
||||
|
||||
public BytesRef getText() {
|
||||
return text;
|
||||
@ -100,6 +102,24 @@ public class SuggestionSearchContext {
|
||||
}
|
||||
this.shardSize = shardSize;
|
||||
}
|
||||
|
||||
public void setShard(int shardId) {
|
||||
this.shardId = shardId;
|
||||
}
|
||||
|
||||
public void setIndex(String index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public String getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public int getShard() {
|
||||
return shardId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user