Example usage for org.apache.lucene.search.vectorhighlight FieldFragList getFragInfos

List of usage examples for org.apache.lucene.search.vectorhighlight FieldFragList getFragInfos

Introduction

In this page you can find the example usage for org.apache.lucene.search.vectorhighlight FieldFragList getFragInfos.

Prototype

public List<WeightedFragInfo> getFragInfos() 

Source Link

Document

return the list of WeightedFragInfos.

Usage

From source file:com.github.hotware.lucene.extension.highlight.BaseObjectFragmentsBuilder.java

License:BEER-WARE LICENSE

@Override
public <T> List<T> createFragments(IndexReader reader, int docId, String fieldName, FieldFragList fieldFragList,
        int maxNumFragments, ObjectEncoder<T> encoder) throws IOException {

    if (maxNumFragments < 0) {
        throw new IllegalArgumentException("maxNumFragments(" + maxNumFragments + ") must be positive number.");
    }//w  w  w .j  a  v  a  2s . c  o  m

    List<WeightedFragInfo> fragInfos = fieldFragList.getFragInfos();
    Field[] values = getFields(reader, docId, fieldName);
    if (values.length == 0) {
        return null;
    }

    if (discreteMultiValueHighlighting && values.length > 1) {
        fragInfos = discreteMultiValueHighlighting(fragInfos, values);
    }

    fragInfos = getWeightedFragInfoList(fragInfos);
    int limitFragments = maxNumFragments < fragInfos.size() ? maxNumFragments : fragInfos.size();
    List<T> fragments = new ArrayList<>(limitFragments);

    for (int i = 0; i < limitFragments; ++i) {
        fragments.add(encoder.encode(fragInfos.get(i), values));
    }
    return fragments;
}