Java Code Examples for org.apache.lucene.index.TermEnum

The following examples show how to use org.apache.lucene.index.TermEnum. These examples are extracted from open source projects. 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 Project: netbeans   Source File: MemoryIndex.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <T> void queryTerms(
        @NonNull Collection<? super T> result,
        @NullAllowed Term start,
        @NonNull StoppableConvertor<Term, T> filter,
        @NullAllowed AtomicBoolean cancel) throws IOException, InterruptedException {
    Parameters.notNull("result", result);   //NOI18N
    Parameters.notNull("filter", filter); //NOI18N
    
    lock.readLock().lock();
    try {
        final IndexReader in = getReader();
        if (in == null) {
            return;
        }
        final TermEnum terms = start == null ? in.terms () : in.terms (start);
        try {
            do {
                if (cancel != null && cancel.get()) {
                    throw new InterruptedException ();
                }
                final Term currentTerm = terms.term();
                if (currentTerm != null) {                    
                    final T vote = filter.convert(currentTerm);
                    if (vote != null) {
                        result.add(vote);
                    }
                }
            } while (terms.next());
        } catch (StoppableConvertor.Stop stop) {
            //Stop iteration of TermEnum
        } finally {
            terms.close();
        }
    } finally {
        lock.readLock().unlock();
    }
}
 
Example 2
Source Project: netbeans   Source File: Convertors.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public T convert(@NonNull final TermEnum terms) throws StoppableConvertor.Stop {
    final Term currentTerm = terms.term();
    if (currentTerm == null) {
        return null;
    }
    return delegate.convert(currentTerm);
}
 
Example 3
Source Project: netbeans   Source File: Convertors.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public T convert(TermEnum terms) throws StoppableConvertor.Stop {
    final Term currentTerm = terms.term();
    if (currentTerm == null) {
        return null;
    }
    final int freq = terms.docFreq();
    return delegate.convert(accessor.setTermFreq(tf, currentTerm, freq));
}
 
Example 4
Source Project: imhotep   Source File: LuceneUnsortedIntTermDocIterator.java    License: Apache License 2.0 5 votes vote down vote up
static LuceneUnsortedIntTermDocIterator create(final IndexReader r, final String field) throws IOException {
    final TermEnum terms = r.terms(new Term(field, ""));
    final TermDocs termDocs;
    try {
        termDocs = r.termDocs();
    } catch (IOException e) {
        try {
            terms.close();
        } catch (IOException e1) {
            log.error("error closing TermEnum", e1);
        }
        throw e;
    }
    return new LuceneUnsortedIntTermDocIterator(field, terms, termDocs);
}
 
Example 5
Source Project: netbeans   Source File: QueryUtil.java    License: Apache License 2.0 4 votes vote down vote up
private TermEnum getTermEnum(@NonNull final IndexReader reader) {
    return new TermEnum () {
        private Iterator<String> pkgsIt = pkgs.iterator();
        private String current;
        {
            next();
        }

        @Override
        public boolean next() {
            if (pkgsIt == null) {
                throw new IllegalStateException("Already closed."); //NOI18N
            }
            if (pkgsIt.hasNext()) {
                current = pkgsIt.next();
                return true;
            } else {
                current = null;
                return false;
            }
        }

        @Override
        public Term term() {
            return current == null ?
                null :
                new Term (DocumentUtil.FIELD_PACKAGE_NAME, current);
        }

        @Override
        public int docFreq() {
            return current == null ?
                -1 :
                 0;
        }

        @Override
        public void close() throws IOException {
            pkgsIt = null;
        }
    };
}
 
Example 6
Source Project: netbeans   Source File: Convertors.java    License: Apache License 2.0 4 votes vote down vote up
static <T> StoppableConvertor<TermEnum,T> newTermEnumToTermConvertor(
    @NonNull StoppableConvertor<Term,T> delegate) {
    return new TermEnumToTerm<T>(delegate);
}
 
Example 7
Source Project: netbeans   Source File: Convertors.java    License: Apache License 2.0 4 votes vote down vote up
static <T> StoppableConvertor<TermEnum,T> newTermEnumToFreqConvertor(
    @NonNull StoppableConvertor<Index.WithTermFrequencies.TermFreq,T> delegate) {
    return new TermEnumToFreq<T>(delegate);
}
 
Example 8
public void seek(TermEnum termEnum) throws IOException
{
    // Seek is left to the base implementation
    in.seek(termEnum);
}
 
Example 9
public void seek(TermEnum termEnum) throws IOException
{
   throw new UnsupportedOperationException();
}
 
Example 10
Source Project: imhotep   Source File: LuceneIntTermIterator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public TermEnum termEnum() {
    sanityCheck();
    return prefixQueue.element().termEnum;
}
 
Example 11
Source Project: imhotep   Source File: LuceneUnsortedIntTermDocIterator.java    License: Apache License 2.0 4 votes vote down vote up
LuceneUnsortedIntTermDocIterator(String field, TermEnum terms, TermDocs termDocs) {
    this.field = field.intern();
    this.terms = terms;
    this.termDocs = termDocs;
}
 
Example 12
Source Project: imhotep   Source File: LuceneStringTermIterator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public TermEnum termEnum() {
    sanityCheck();
    return termEnum;
}
 
Example 13
Source Project: imhotep   Source File: LuceneTermIterator.java    License: Apache License 2.0 votes vote down vote up
public TermEnum termEnum();