Java Code Examples for org.apache.lucene.index.Terms#getMin()

The following examples show how to use org.apache.lucene.index.Terms#getMin() . 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: LuceneIndexCorpus.java    From word2vec-lucene with Apache License 2.0 6 votes vote down vote up
@Override
public void learnVocab() throws IOException {
  super.learnVocab();

  final String field = ((LuceneIndexConfig)config).getField();
  final Terms terms = MultiFields.getTerms(reader, field);
  final BytesRef maxTerm = terms.getMax();
  final BytesRef minTerm = terms.getMin();
  Query q = new TermRangeQuery(field, minTerm, maxTerm, true, true);
  IndexSearcher searcher = new IndexSearcher(reader);
  topDocs = searcher.search(q, Integer.MAX_VALUE);

  TermsEnum termsEnum = null;
  termsEnum = terms.iterator(termsEnum);

  termsEnum.seekCeil(new BytesRef());
  BytesRef term = termsEnum.term();
  while(term != null){
    int p = addWordToVocab(term.utf8ToString());
    vocab[p].setCn((int)termsEnum.totalTermFreq());
    term = termsEnum.next();
  }
}
 
Example 2
Source File: LegacyNumericUtils.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the minimum int value indexed into this
 * numeric field or null if no terms exist.
 */
public static Integer getMinInt(Terms terms) throws IOException {
  // All shift=0 terms are sorted first, so we don't need
  // to filter the incoming terms; we can just get the
  // min:
  BytesRef min = terms.getMin();
  return (min != null) ? LegacyNumericUtils.prefixCodedToInt(min) : null;
}
 
Example 3
Source File: LegacyNumericUtils.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the minimum long value indexed into this
 * numeric field or null if no terms exist.
 */
public static Long getMinLong(Terms terms) throws IOException {
  // All shift=0 terms are sorted first, so we don't need
  // to filter the incoming terms; we can just get the
  // min:
  BytesRef min = terms.getMin();
  return (min != null) ? LegacyNumericUtils.prefixCodedToLong(min) : null;
}
 
Example 4
Source File: MappedFieldType.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * @return a {@link FieldStats} instance that maps to the type of this field based on the provided {@link Terms} instance.
 */
public FieldStats stats(Terms terms, int maxDoc) throws IOException {
    return new FieldStats.Text(
        maxDoc, terms.getDocCount(), terms.getSumDocFreq(), terms.getSumTotalTermFreq(), terms.getMin(), terms.getMax()
    );
}