Search in sources :

Example 1 with MultiTermVectorsItemResponse

use of org.elasticsearch.action.termvectors.MultiTermVectorsItemResponse in project elasticsearch by elastic.

the class MoreLikeThisQueryBuilder method getFieldsFor.

private static Fields[] getFieldsFor(MultiTermVectorsResponse responses) throws IOException {
    List<Fields> likeFields = new ArrayList<>();
    for (MultiTermVectorsItemResponse response : responses) {
        if (response.isFailed()) {
            continue;
        }
        TermVectorsResponse getResponse = response.getResponse();
        if (!getResponse.isExists()) {
            continue;
        }
        likeFields.add(getResponse.getFields());
    }
    return likeFields.toArray(Fields.EMPTY_ARRAY);
}
Also used : MultiTermVectorsItemResponse(org.elasticsearch.action.termvectors.MultiTermVectorsItemResponse) MultiTermVectorsResponse(org.elasticsearch.action.termvectors.MultiTermVectorsResponse) TermVectorsResponse(org.elasticsearch.action.termvectors.TermVectorsResponse) Fields(org.apache.lucene.index.Fields) ArrayList(java.util.ArrayList)

Example 2 with MultiTermVectorsItemResponse

use of org.elasticsearch.action.termvectors.MultiTermVectorsItemResponse in project elasticsearch by elastic.

the class MoreLikeThisQueryBuilderTests method executeMultiTermVectors.

@Override
protected MultiTermVectorsResponse executeMultiTermVectors(MultiTermVectorsRequest mtvRequest) {
    try {
        MultiTermVectorsItemResponse[] responses = new MultiTermVectorsItemResponse[mtvRequest.size()];
        int i = 0;
        for (TermVectorsRequest request : mtvRequest) {
            TermVectorsResponse response = new TermVectorsResponse(request.index(), request.type(), request.id());
            response.setExists(true);
            Fields generatedFields;
            if (request.doc() != null) {
                generatedFields = generateFields(randomFields, request.doc().utf8ToString());
            } else {
                generatedFields = generateFields(request.selectedFields().toArray(new String[request.selectedFields().size()]), request.id());
            }
            EnumSet<TermVectorsRequest.Flag> flags = EnumSet.of(TermVectorsRequest.Flag.Positions, TermVectorsRequest.Flag.Offsets);
            response.setFields(generatedFields, request.selectedFields(), flags, generatedFields);
            responses[i++] = new MultiTermVectorsItemResponse(response, null);
        }
        return new MultiTermVectorsResponse(responses);
    } catch (IOException ex) {
        throw new ElasticsearchException("boom", ex);
    }
}
Also used : TermVectorsRequest(org.elasticsearch.action.termvectors.TermVectorsRequest) MultiTermVectorsRequest(org.elasticsearch.action.termvectors.MultiTermVectorsRequest) MultiTermVectorsItemResponse(org.elasticsearch.action.termvectors.MultiTermVectorsItemResponse) MultiTermVectorsResponse(org.elasticsearch.action.termvectors.MultiTermVectorsResponse) TermVectorsResponse(org.elasticsearch.action.termvectors.TermVectorsResponse) Fields(org.apache.lucene.index.Fields) MultiFields(org.apache.lucene.index.MultiFields) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) MultiTermVectorsResponse(org.elasticsearch.action.termvectors.MultiTermVectorsResponse)

Aggregations

Fields (org.apache.lucene.index.Fields)2 MultiTermVectorsItemResponse (org.elasticsearch.action.termvectors.MultiTermVectorsItemResponse)2 MultiTermVectorsResponse (org.elasticsearch.action.termvectors.MultiTermVectorsResponse)2 TermVectorsResponse (org.elasticsearch.action.termvectors.TermVectorsResponse)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 MultiFields (org.apache.lucene.index.MultiFields)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 MultiTermVectorsRequest (org.elasticsearch.action.termvectors.MultiTermVectorsRequest)1 TermVectorsRequest (org.elasticsearch.action.termvectors.TermVectorsRequest)1