Make TermVectorService static
This commit is contained in:
parent
75802515ea
commit
59a20015d6
|
@ -42,16 +42,14 @@ public class TransportShardMultiTermsVectorAction extends TransportSingleShardAc
|
|||
private final IndicesService indicesService;
|
||||
|
||||
private static final String ACTION_NAME = MultiTermVectorsAction.NAME + "[shard]";
|
||||
private final TermVectorsService termVectorsService;
|
||||
|
||||
@Inject
|
||||
public TransportShardMultiTermsVectorAction(Settings settings, ClusterService clusterService, TransportService transportService,
|
||||
IndicesService indicesService, ThreadPool threadPool, ActionFilters actionFilters,
|
||||
IndexNameExpressionResolver indexNameExpressionResolver, TermVectorsService termVectorsService) {
|
||||
IndexNameExpressionResolver indexNameExpressionResolver) {
|
||||
super(settings, ACTION_NAME, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver,
|
||||
MultiTermVectorsShardRequest::new, ThreadPool.Names.GET);
|
||||
this.indicesService = indicesService;
|
||||
this.termVectorsService = termVectorsService;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -83,7 +81,7 @@ public class TransportShardMultiTermsVectorAction extends TransportSingleShardAc
|
|||
try {
|
||||
IndexService indexService = indicesService.indexServiceSafe(request.index());
|
||||
IndexShard indexShard = indexService.getShard(shardId.id());
|
||||
TermVectorsResponse termVectorsResponse = termVectorsService.getTermVectors(indexShard, termVectorsRequest);
|
||||
TermVectorsResponse termVectorsResponse = TermVectorsService.getTermVectors(indexShard, termVectorsRequest);
|
||||
termVectorsResponse.updateTookInMillis(termVectorsRequest.startTime());
|
||||
response.add(request.locations.get(i), termVectorsResponse);
|
||||
} catch (Throwable t) {
|
||||
|
|
|
@ -43,7 +43,6 @@ import org.elasticsearch.transport.TransportService;
|
|||
public class TransportTermVectorsAction extends TransportSingleShardAction<TermVectorsRequest, TermVectorsResponse> {
|
||||
|
||||
private final IndicesService indicesService;
|
||||
private final TermVectorsService termVectorsService;
|
||||
|
||||
@Override
|
||||
protected void doExecute(TermVectorsRequest request, ActionListener<TermVectorsResponse> listener) {
|
||||
|
@ -54,11 +53,10 @@ public class TransportTermVectorsAction extends TransportSingleShardAction<TermV
|
|||
@Inject
|
||||
public TransportTermVectorsAction(Settings settings, ClusterService clusterService, TransportService transportService,
|
||||
IndicesService indicesService, ThreadPool threadPool, ActionFilters actionFilters,
|
||||
IndexNameExpressionResolver indexNameExpressionResolver, TermVectorsService termVectorsService) {
|
||||
IndexNameExpressionResolver indexNameExpressionResolver) {
|
||||
super(settings, TermVectorsAction.NAME, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver,
|
||||
TermVectorsRequest::new, ThreadPool.Names.GET);
|
||||
this.indicesService = indicesService;
|
||||
this.termVectorsService = termVectorsService;
|
||||
|
||||
}
|
||||
|
||||
|
@ -87,7 +85,7 @@ public class TransportTermVectorsAction extends TransportSingleShardAction<TermV
|
|||
protected TermVectorsResponse shardOperation(TermVectorsRequest request, ShardId shardId) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
|
||||
IndexShard indexShard = indexService.getShard(shardId.id());
|
||||
TermVectorsResponse response = termVectorsService.getTermVectors(indexShard, request);
|
||||
TermVectorsResponse response = TermVectorsService.getTermVectors(indexShard, request);
|
||||
response.updateTookInMillis(request.startTime());
|
||||
return response;
|
||||
}
|
||||
|
|
|
@ -66,7 +66,10 @@ import static org.elasticsearch.index.mapper.SourceToParse.source;
|
|||
|
||||
public class TermVectorsService {
|
||||
|
||||
public TermVectorsResponse getTermVectors(IndexShard indexShard, TermVectorsRequest request) {
|
||||
|
||||
private TermVectorsService() {}
|
||||
|
||||
public static TermVectorsResponse getTermVectors(IndexShard indexShard, TermVectorsRequest request) {
|
||||
final TermVectorsResponse termVectorsResponse = new TermVectorsResponse(indexShard.shardId().getIndex().getName(), request.type(), request.id());
|
||||
final Term uidTerm = new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(request.type(), request.id()));
|
||||
|
||||
|
@ -145,7 +148,7 @@ public class TermVectorsService {
|
|||
return termVectorsResponse;
|
||||
}
|
||||
|
||||
private void handleFieldWildcards(IndexShard indexShard, TermVectorsRequest request) {
|
||||
private static void handleFieldWildcards(IndexShard indexShard, TermVectorsRequest request) {
|
||||
Set<String> fieldNames = new HashSet<>();
|
||||
for (String pattern : request.selectedFields()) {
|
||||
fieldNames.addAll(indexShard.mapperService().simpleMatchToIndexNames(pattern));
|
||||
|
@ -153,7 +156,7 @@ public class TermVectorsService {
|
|||
request.selectedFields(fieldNames.toArray(Strings.EMPTY_ARRAY));
|
||||
}
|
||||
|
||||
private boolean isValidField(MappedFieldType fieldType) {
|
||||
private static boolean isValidField(MappedFieldType fieldType) {
|
||||
// must be a string
|
||||
if (!(fieldType instanceof StringFieldMapper.StringFieldType)) {
|
||||
return false;
|
||||
|
@ -165,7 +168,7 @@ public class TermVectorsService {
|
|||
return true;
|
||||
}
|
||||
|
||||
private Fields addGeneratedTermVectors(IndexShard indexShard, Engine.GetResult get, Fields termVectorsByField, TermVectorsRequest request, Set<String> selectedFields) throws IOException {
|
||||
private static Fields addGeneratedTermVectors(IndexShard indexShard, Engine.GetResult get, Fields termVectorsByField, TermVectorsRequest request, Set<String> selectedFields) throws IOException {
|
||||
/* only keep valid fields */
|
||||
Set<String> validFields = new HashSet<>();
|
||||
for (String field : selectedFields) {
|
||||
|
@ -198,7 +201,7 @@ public class TermVectorsService {
|
|||
}
|
||||
}
|
||||
|
||||
private Analyzer getAnalyzerAtField(IndexShard indexShard, String field, @Nullable Map<String, String> perFieldAnalyzer) {
|
||||
private static Analyzer getAnalyzerAtField(IndexShard indexShard, String field, @Nullable Map<String, String> perFieldAnalyzer) {
|
||||
MapperService mapperService = indexShard.mapperService();
|
||||
Analyzer analyzer;
|
||||
if (perFieldAnalyzer != null && perFieldAnalyzer.containsKey(field)) {
|
||||
|
@ -212,7 +215,7 @@ public class TermVectorsService {
|
|||
return analyzer;
|
||||
}
|
||||
|
||||
private Set<String> getFieldsToGenerate(Map<String, String> perAnalyzerField, Fields fieldsObject) {
|
||||
private static Set<String> getFieldsToGenerate(Map<String, String> perAnalyzerField, Fields fieldsObject) {
|
||||
Set<String> selectedFields = new HashSet<>();
|
||||
for (String fieldName : fieldsObject) {
|
||||
if (perAnalyzerField.containsKey(fieldName)) {
|
||||
|
@ -222,7 +225,7 @@ public class TermVectorsService {
|
|||
return selectedFields;
|
||||
}
|
||||
|
||||
private Fields generateTermVectors(IndexShard indexShard, Collection<GetField> getFields, boolean withOffsets, @Nullable Map<String, String> perFieldAnalyzer, Set<String> fields)
|
||||
private static Fields generateTermVectors(IndexShard indexShard, Collection<GetField> getFields, boolean withOffsets, @Nullable Map<String, String> perFieldAnalyzer, Set<String> fields)
|
||||
throws IOException {
|
||||
/* store document in memory index */
|
||||
MemoryIndex index = new MemoryIndex(withOffsets);
|
||||
|
@ -241,7 +244,7 @@ public class TermVectorsService {
|
|||
return MultiFields.getFields(index.createSearcher().getIndexReader());
|
||||
}
|
||||
|
||||
private Fields generateTermVectorsFromDoc(IndexShard indexShard, TermVectorsRequest request, boolean doAllFields) throws Throwable {
|
||||
private static Fields generateTermVectorsFromDoc(IndexShard indexShard, TermVectorsRequest request, boolean doAllFields) throws Throwable {
|
||||
// parse the document, at the moment we do update the mapping, just like percolate
|
||||
ParsedDocument parsedDocument = parseDocument(indexShard, indexShard.shardId().getIndexName(), request.type(), request.doc());
|
||||
|
||||
|
@ -272,7 +275,7 @@ public class TermVectorsService {
|
|||
return generateTermVectors(indexShard, getFields, request.offsets(), request.perFieldAnalyzer(), seenFields);
|
||||
}
|
||||
|
||||
private ParsedDocument parseDocument(IndexShard indexShard, String index, String type, BytesReference doc) throws Throwable {
|
||||
private static ParsedDocument parseDocument(IndexShard indexShard, String index, String type, BytesReference doc) throws Throwable {
|
||||
MapperService mapperService = indexShard.mapperService();
|
||||
DocumentMapperForType docMapper = mapperService.documentMapperWithAutoCreate(type);
|
||||
ParsedDocument parsedDocument = docMapper.getDocumentMapper().parse(source(doc).index(index).type(type).id("_id_for_tv_api"));
|
||||
|
@ -282,7 +285,7 @@ public class TermVectorsService {
|
|||
return parsedDocument;
|
||||
}
|
||||
|
||||
private Fields mergeFields(Fields fields1, Fields fields2) throws IOException {
|
||||
private static Fields mergeFields(Fields fields1, Fields fields2) throws IOException {
|
||||
ParallelFields parallelFields = new ParallelFields();
|
||||
for (String fieldName : fields2) {
|
||||
Terms terms = fields2.terms(fieldName);
|
||||
|
|
|
@ -172,7 +172,6 @@ public class IndicesModule extends AbstractModule {
|
|||
bind(UpdateHelper.class).asEagerSingleton();
|
||||
bind(MetaDataIndexUpgradeService.class).asEagerSingleton();
|
||||
bind(IndicesFieldDataCacheListener.class).asEagerSingleton();
|
||||
bind(TermVectorsService.class).asEagerSingleton();
|
||||
bind(NodeServicesProvider.class).asEagerSingleton();
|
||||
}
|
||||
|
||||
|
|
|
@ -129,11 +129,6 @@ public class FetchSubPhasePluginIT extends ESIntegTestCase {
|
|||
return new TermVectorsFetchContext();
|
||||
}
|
||||
};
|
||||
private final TermVectorsService termVectorsService;
|
||||
|
||||
public TermVectorsFetchSubPhase(TermVectorsService termVectorsService) {
|
||||
this.termVectorsService = termVectorsService;
|
||||
}
|
||||
|
||||
public static final String[] NAMES = {"term_vectors_fetch"};
|
||||
|
||||
|
@ -168,7 +163,7 @@ public class FetchSubPhasePluginIT extends ESIntegTestCase {
|
|||
hitField = new InternalSearchHitField(NAMES[0], new ArrayList<>(1));
|
||||
hitContext.hit().fields().put(NAMES[0], hitField);
|
||||
}
|
||||
TermVectorsResponse termVector = termVectorsService.getTermVectors(context.indexShard(), new TermVectorsRequest(context.indexShard().shardId().getIndex().getName(), hitContext.hit().type(), hitContext.hit().id()));
|
||||
TermVectorsResponse termVector = TermVectorsService.getTermVectors(context.indexShard(), new TermVectorsRequest(context.indexShard().shardId().getIndex().getName(), hitContext.hit().type(), hitContext.hit().id()));
|
||||
try {
|
||||
Map<String, Integer> tv = new HashMap<>();
|
||||
TermsEnum terms = termVector.getFields().terms(field).iterator();
|
||||
|
|
Loading…
Reference in New Issue