org.elasticsearch.action.termvectors.TermVectorsResponse Java Examples

The following examples show how to use org.elasticsearch.action.termvectors.TermVectorsResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MoreLikeThisFetchService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public 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);
}
 
Example #2
Source File: RestTermVectorsAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
    TermVectorsRequest termVectorsRequest = new TermVectorsRequest(request.param("index"), request.param("type"), request.param("id"));
    if (RestActions.hasBodyContent(request)) {
        try (XContentParser parser = XContentFactory.xContent(RestActions.guessBodyContentType(request)).createParser(RestActions.getRestContent(request))){
            TermVectorsRequest.parseRequest(termVectorsRequest, parser);
        }
    }
    readURIParameters(termVectorsRequest, request);

    client.termVectors(termVectorsRequest, new RestToXContentListener<TermVectorsResponse>(channel));
}
 
Example #3
Source File: ESIndex.java    From pyramid with Apache License 2.0 5 votes vote down vote up
private Map<Integer,String> getTermVectorWithException(String field, String id) throws IOException {
    TermVectorsResponse response = client.prepareTermVector(indexName, documentType, id)
            .setOffsets(false).setPositions(true).setFieldStatistics(false)
            .setTermStatistics(false)
            .setSelectedFields(field).
                    execute().actionGet();

    Map<Integer,String> map = new HashMap<>();
    Terms terms = response.getFields().terms(field);
    if (terms==null){
        return map;
    }
    TermsEnum iterator = terms.iterator();
    PostingsEnum postings = null;
    
    for (BytesRef termBytes = null; (termBytes = iterator.next()) != null; ) {
    	String term = termBytes.utf8ToString();
    	
    	postings = iterator.postings(postings, PostingsEnum.ALL);
    	
    	//there can only be one doc since we are getting with id. get the doc and the position 
    	postings.nextDoc();
    	
    	int tf = postings.freq();
    	
    	for (int i = 0; i < tf; i++) {
    		int pos = postings.nextPosition();
            map.put(pos,term);
    	}
    	
    }
    
    return map;
}
 
Example #4
Source File: ClientWithStats.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public ActionFuture<TermVectorsResponse> termVectors(TermVectorsRequest request) {
	return wrapped.termVectors(request);
}
 
Example #5
Source File: ClientWithStats.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void termVectors(TermVectorsRequest request, ActionListener<TermVectorsResponse> listener) {
	wrapped.termVectors(request, listener);
}
 
Example #6
Source File: ClientWithStats.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
@Deprecated
public ActionFuture<TermVectorsResponse> termVector(TermVectorsRequest request) {
	return wrapped.termVector(request);
}
 
Example #7
Source File: ClientWithStats.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
@Deprecated
public void termVector(TermVectorsRequest request, ActionListener<TermVectorsResponse> listener) {
	wrapped.termVector(request, listener);
}
 
Example #8
Source File: FessEsClient.java    From fess with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<TermVectorsResponse> termVectors(final TermVectorsRequest request) {
    return client.termVectors(request);
}
 
Example #9
Source File: FessEsClient.java    From fess with Apache License 2.0 4 votes vote down vote up
@Override
public void termVectors(final TermVectorsRequest request, final ActionListener<TermVectorsResponse> listener) {
    client.termVectors(request, listener);
}