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