Example usage for org.apache.lucene.index MultiTerms getTerms

List of usage examples for org.apache.lucene.index MultiTerms getTerms

Introduction

In this page you can find the example usage for org.apache.lucene.index MultiTerms getTerms.

Prototype

public static Terms getTerms(IndexReader r, String field) throws IOException 

Source Link

Document

This method may return null if the field does not exist or if it has no terms.

Usage

From source file:org.apache.tika.eval.tools.SlowCompositeReaderWrapper.java

License:Apache License

@Override
public Terms terms(String field) throws IOException {
    ensureOpen();// w  w w. j  a  v  a2s  .  co  m
    try {
        return cachedTerms.computeIfAbsent(field, f -> {
            try {
                return MultiTerms.getTerms(in, f);
            } catch (IOException e) { // yuck!  ...sigh... checked exceptions with built-in lambdas are a pain
                throw new RuntimeException("unwrapMe", e);
            }
        });
    } catch (RuntimeException e) {
        if (e.getMessage().equals("unwrapMe") && e.getCause() instanceof IOException) {
            throw (IOException) e.getCause();
        }
        throw e;
    }
}

From source file:uk.ac.ebi.biostudies.efo.Autocompletion.java

License:Apache License

public List<String> getTerms(String fieldName, int minFreq) throws IOException {
    List<String> termsList = new ArrayList<>();

    try {/*  ww w  .  j  av  a2s.  c o m*/
        IndexReader reader = indexManager.getIndexReader();
        Terms terms = MultiTerms.getTerms(reader, fieldName);
        if (null != terms) {
            TermsEnum iterator = terms.iterator();
            BytesRef byteRef;
            while ((byteRef = iterator.next()) != null) {
                if (iterator.docFreq() >= minFreq) {
                    termsList.add(byteRef.utf8ToString());
                }
            }
        }
    } catch (Exception ex) {
        logger.error("getTerms problem", ex);
    }
    return termsList;
}