Search in sources :

Example 1 with CompletionTerms

use of org.apache.lucene.search.suggest.document.CompletionTerms in project elasticsearch by elastic.

the class CompletionFieldStats method completionStats.

/**
     * Returns total in-heap bytes used by all suggesters.  This method has CPU cost <code>O(numIndexedFields)</code>.
     *
     * @param fieldNamePatterns if non-null, any completion field name matching any of these patterns will break out its in-heap bytes
     * separately in the returned {@link CompletionStats}
     */
public static CompletionStats completionStats(IndexReader indexReader, String... fieldNamePatterns) {
    long sizeInBytes = 0;
    ObjectLongHashMap<String> completionFields = null;
    if (fieldNamePatterns != null && fieldNamePatterns.length > 0) {
        completionFields = new ObjectLongHashMap<>(fieldNamePatterns.length);
    }
    for (LeafReaderContext atomicReaderContext : indexReader.leaves()) {
        LeafReader atomicReader = atomicReaderContext.reader();
        try {
            Fields fields = atomicReader.fields();
            for (String fieldName : fields) {
                Terms terms = fields.terms(fieldName);
                if (terms instanceof CompletionTerms) {
                    // TODO: currently we load up the suggester for reporting its size
                    long fstSize = ((CompletionTerms) terms).suggester().ramBytesUsed();
                    if (fieldNamePatterns != null && fieldNamePatterns.length > 0 && Regex.simpleMatch(fieldNamePatterns, fieldName)) {
                        completionFields.addTo(fieldName, fstSize);
                    }
                    sizeInBytes += fstSize;
                }
            }
        } catch (IOException ioe) {
            throw new ElasticsearchException(ioe);
        }
    }
    return new CompletionStats(sizeInBytes, completionFields == null ? null : new FieldMemoryStats(completionFields));
}
Also used : LeafReader(org.apache.lucene.index.LeafReader) Terms(org.apache.lucene.index.Terms) CompletionTerms(org.apache.lucene.search.suggest.document.CompletionTerms) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) CompletionTerms(org.apache.lucene.search.suggest.document.CompletionTerms) Fields(org.apache.lucene.index.Fields) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) FieldMemoryStats(org.elasticsearch.common.FieldMemoryStats)

Aggregations

IOException (java.io.IOException)1 Fields (org.apache.lucene.index.Fields)1 LeafReader (org.apache.lucene.index.LeafReader)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 Terms (org.apache.lucene.index.Terms)1 CompletionTerms (org.apache.lucene.search.suggest.document.CompletionTerms)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 FieldMemoryStats (org.elasticsearch.common.FieldMemoryStats)1