Index: lucene/contrib/sandbox/src/java/org/apache/lucene/sandbox/queries/SlowCollatedTermRangeTermsEnum.java =================================================================== --- lucene/contrib/sandbox/src/java/org/apache/lucene/sandbox/queries/SlowCollatedTermRangeTermsEnum.java (revision 1170711) +++ lucene/contrib/sandbox/src/java/org/apache/lucene/sandbox/queries/SlowCollatedTermRangeTermsEnum.java (working copy) @@ -21,7 +21,7 @@ import java.text.Collator; import org.apache.lucene.index.TermsEnum; -import org.apache.lucene.search.FilteredTermsEnum; +import org.apache.lucene.index.FilteredTermsEnum; import org.apache.lucene.util.BytesRef; /** Index: lucene/contrib/sandbox/src/java/org/apache/lucene/sandbox/queries/regex/RegexQuery.java =================================================================== --- lucene/contrib/sandbox/src/java/org/apache/lucene/sandbox/queries/regex/RegexQuery.java (revision 1170711) +++ lucene/contrib/sandbox/src/java/org/apache/lucene/sandbox/queries/regex/RegexQuery.java (working copy) @@ -18,7 +18,7 @@ */ import org.apache.lucene.search.MultiTermQuery; -import org.apache.lucene.search.FilteredTermsEnum; +import org.apache.lucene.index.FilteredTermsEnum; import org.apache.lucene.search.RegexpQuery; // javadoc import org.apache.lucene.index.Term; import org.apache.lucene.index.Terms; Index: lucene/contrib/sandbox/src/java/org/apache/lucene/sandbox/queries/regex/RegexTermsEnum.java =================================================================== --- lucene/contrib/sandbox/src/java/org/apache/lucene/sandbox/queries/regex/RegexTermsEnum.java (revision 1170711) +++ lucene/contrib/sandbox/src/java/org/apache/lucene/sandbox/queries/regex/RegexTermsEnum.java (working copy) @@ -17,7 +17,7 @@ * limitations under the License. */ -import org.apache.lucene.search.FilteredTermsEnum; +import org.apache.lucene.index.FilteredTermsEnum; import org.apache.lucene.index.Term; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.util.BytesRef; Index: lucene/src/test/org/apache/lucene/search/TestAutomatonQuery.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestAutomatonQuery.java (revision 1170711) +++ lucene/src/test/org/apache/lucene/search/TestAutomatonQuery.java (working copy) @@ -25,6 +25,7 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.MultiFields; import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.index.SingleTermsEnum; import org.apache.lucene.index.Term; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; Index: lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java (revision 1170711) +++ lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java (working copy) @@ -27,6 +27,7 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.StringField; +import org.apache.lucene.index.FilteredTermsEnum; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; Index: lucene/src/test/org/apache/lucene/search/TestPrefixRandom.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestPrefixRandom.java (revision 1170711) +++ lucene/src/test/org/apache/lucene/search/TestPrefixRandom.java (working copy) @@ -24,11 +24,12 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.StringField; +import org.apache.lucene.index.FilteredTermsEnum; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; -import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.codecs.CodecProvider; import org.apache.lucene.store.Directory; import org.apache.lucene.util.AttributeSource; Index: lucene/src/java/org/apache/lucene/search/MultiTermQuery.java =================================================================== --- lucene/src/java/org/apache/lucene/search/MultiTermQuery.java (revision 1170711) +++ lucene/src/java/org/apache/lucene/search/MultiTermQuery.java (working copy) @@ -19,7 +19,9 @@ import java.io.IOException; +import org.apache.lucene.index.FilteredTermsEnum; // javadocs import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.SingleTermsEnum; // javadocs import org.apache.lucene.index.Term; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; Index: lucene/src/java/org/apache/lucene/search/FuzzyQuery.java =================================================================== --- lucene/src/java/org/apache/lucene/search/FuzzyQuery.java (revision 1170711) +++ lucene/src/java/org/apache/lucene/search/FuzzyQuery.java (working copy) @@ -17,6 +17,9 @@ * limitations under the License. */ +import java.io.IOException; + +import org.apache.lucene.index.SingleTermsEnum; import org.apache.lucene.index.Term; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; @@ -24,8 +27,6 @@ import org.apache.lucene.util.ToStringUtils; import org.apache.lucene.util.automaton.LevenshteinAutomata; -import java.io.IOException; - /** Implements the fuzzy search query. The similarity measurement * is based on the Levenshtein (edit distance) algorithm. * Index: lucene/src/java/org/apache/lucene/search/PrefixTermsEnum.java =================================================================== --- lucene/src/java/org/apache/lucene/search/PrefixTermsEnum.java (revision 1170711) +++ lucene/src/java/org/apache/lucene/search/PrefixTermsEnum.java (working copy) @@ -19,6 +19,7 @@ import java.io.IOException; +import org.apache.lucene.index.FilteredTermsEnum; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.util.BytesRef; Index: lucene/src/java/org/apache/lucene/search/FilteredTermsEnum.java =================================================================== --- lucene/src/java/org/apache/lucene/search/FilteredTermsEnum.java (revision 1170711) +++ lucene/src/java/org/apache/lucene/search/FilteredTermsEnum.java (working copy) @@ -1,248 +0,0 @@ -package org.apache.lucene.search; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.io.IOException; -import java.util.Comparator; - -import org.apache.lucene.util.BytesRef; -import org.apache.lucene.index.TermState; -import org.apache.lucene.index.TermsEnum; -import org.apache.lucene.index.DocsEnum; -import org.apache.lucene.index.DocsAndPositionsEnum; -import org.apache.lucene.util.AttributeSource; -import org.apache.lucene.util.Bits; - -// TODO: move this class to oal.index - -/** - * Abstract class for enumerating a subset of all terms. - * - *

Term enumerations are always ordered by - * {@link #getComparator}. Each term in the enumeration is - * greater than all that precede it.

- *

Please note: Consumers of this enum cannot - * call {@code seek()}, it is forward only; it throws - * {@link UnsupportedOperationException} when a seeking method - * is called. - */ -public abstract class FilteredTermsEnum extends TermsEnum { - - private BytesRef initialSeekTerm = null; - private boolean doSeek; - private BytesRef actualTerm = null; - - private final TermsEnum tenum; - - /** Return value, if term should be accepted or the iteration should - * {@code END}. The {@code *_SEEK} values denote, that after handling the current term - * the enum should call {@link #nextSeekTerm} and step forward. - * @see #accept(BytesRef) - */ - protected static enum AcceptStatus {YES, YES_AND_SEEK, NO, NO_AND_SEEK, END}; - - /** Return if term is accepted, not accepted or the iteration should ended - * (and possibly seek). - */ - protected abstract AcceptStatus accept(BytesRef term) throws IOException; - - /** - * Creates a filtered {@link TermsEnum} on a terms enum. - * @param tenum the terms enumeration to filter. - */ - public FilteredTermsEnum(final TermsEnum tenum) { - this(tenum, true); - } - - /** - * Creates a filtered {@link TermsEnum} on a terms enum. - * @param tenum the terms enumeration to filter. - */ - public FilteredTermsEnum(final TermsEnum tenum, final boolean startWithSeek) { - assert tenum != null; - this.tenum = tenum; - doSeek = startWithSeek; - } - - /** - * Use this method to set the initial {@link BytesRef} - * to seek before iterating. This is a convenience method for - * subclasses that do not override {@link #nextSeekTerm}. - * If the initial seek term is {@code null} (default), - * the enum is empty. - *

You can only use this method, if you keep the default - * implementation of {@link #nextSeekTerm}. - */ - protected final void setInitialSeekTerm(BytesRef term) throws IOException { - this.initialSeekTerm = term; - } - - /** On the first call to {@link #next} or if {@link #accept} returns - * {@link AcceptStatus#YES_AND_SEEK} or {@link AcceptStatus#NO_AND_SEEK}, - * this method will be called to eventually seek the underlying TermsEnum - * to a new position. - * On the first call, {@code currentTerm} will be {@code null}, later - * calls will provide the term the underlying enum is positioned at. - * This method returns per default only one time the initial seek term - * and then {@code null}, so no repositioning is ever done. - *

Override this method, if you want a more sophisticated TermsEnum, - * that repositions the iterator during enumeration. - * If this method always returns {@code null} the enum is empty. - *

Please note: This method should always provide a greater term - * than the last enumerated term, else the behaviour of this enum - * violates the contract for TermsEnums. - */ - protected BytesRef nextSeekTerm(final BytesRef currentTerm) throws IOException { - final BytesRef t = initialSeekTerm; - initialSeekTerm = null; - return t; - } - - /** - * Returns the related attributes, the returned {@link AttributeSource} - * is shared with the delegate {@code TermsEnum}. - */ - @Override - public AttributeSource attributes() { - return tenum.attributes(); - } - - @Override - public BytesRef term() throws IOException { - return tenum.term(); - } - - @Override - public Comparator getComparator() throws IOException { - return tenum.getComparator(); - } - - @Override - public int docFreq() throws IOException { - return tenum.docFreq(); - } - - @Override - public long totalTermFreq() throws IOException { - return tenum.totalTermFreq(); - } - - /** This enum does not support seeking! - * @throws UnsupportedOperationException - */ - @Override - public boolean seekExact(BytesRef term, boolean useCache) throws IOException { - throw new UnsupportedOperationException(getClass().getName()+" does not support seeking"); - } - - /** This enum does not support seeking! - * @throws UnsupportedOperationException - */ - @Override - public SeekStatus seekCeil(BytesRef term, boolean useCache) throws IOException { - throw new UnsupportedOperationException(getClass().getName()+" does not support seeking"); - } - - /** This enum does not support seeking! - * @throws UnsupportedOperationException - */ - @Override - public void seekExact(long ord) throws IOException { - throw new UnsupportedOperationException(getClass().getName()+" does not support seeking"); - } - - @Override - public long ord() throws IOException { - return tenum.ord(); - } - - @Override - public DocsEnum docs(Bits bits, DocsEnum reuse) throws IOException { - return tenum.docs(bits, reuse); - } - - @Override - public DocsAndPositionsEnum docsAndPositions(Bits bits, DocsAndPositionsEnum reuse) throws IOException { - return tenum.docsAndPositions(bits, reuse); - } - - /** This enum does not support seeking! - * @throws UnsupportedOperationException - */ - @Override - public void seekExact(BytesRef term, TermState state) throws IOException { - throw new UnsupportedOperationException(getClass().getName()+" does not support seeking"); - } - - /** - * Returns the filtered enums term state - */ - @Override - public TermState termState() throws IOException { - assert tenum != null; - return tenum.termState(); - } - - @SuppressWarnings("fallthrough") - @Override - public BytesRef next() throws IOException { - //System.out.println("FTE.next doSeek=" + doSeek); - //new Throwable().printStackTrace(System.out); - for (;;) { - // Seek or forward the iterator - if (doSeek) { - doSeek = false; - final BytesRef t = nextSeekTerm(actualTerm); - //System.out.println(" seek to t=" + (t == null ? "null" : t.utf8ToString()) + " tenum=" + tenum); - // Make sure we always seek forward: - assert actualTerm == null || t == null || getComparator().compare(t, actualTerm) > 0: "curTerm=" + actualTerm + " seekTerm=" + t; - if (t == null || tenum.seekCeil(t, false) == SeekStatus.END) { - // no more terms to seek to or enum exhausted - //System.out.println(" return null"); - return null; - } - actualTerm = tenum.term(); - //System.out.println(" got term=" + actualTerm.utf8ToString()); - } else { - actualTerm = tenum.next(); - if (actualTerm == null) { - // enum exhausted - return null; - } - } - - // check if term is accepted - switch (accept(actualTerm)) { - case YES_AND_SEEK: - doSeek = true; - // term accepted, but we need to seek so fall-through - case YES: - // term accepted - return actualTerm; - case NO_AND_SEEK: - // invalid term, seek next time - doSeek = true; - break; - case END: - // we are supposed to end the enum - return null; - } - } - } - -} Index: lucene/src/java/org/apache/lucene/search/TermRangeTermsEnum.java =================================================================== --- lucene/src/java/org/apache/lucene/search/TermRangeTermsEnum.java (revision 1170711) +++ lucene/src/java/org/apache/lucene/search/TermRangeTermsEnum.java (working copy) @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.Comparator; +import org.apache.lucene.index.FilteredTermsEnum; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.util.BytesRef; Index: lucene/src/java/org/apache/lucene/search/NumericRangeQuery.java =================================================================== --- lucene/src/java/org/apache/lucene/search/NumericRangeQuery.java (revision 1170711) +++ lucene/src/java/org/apache/lucene/search/NumericRangeQuery.java (working copy) @@ -18,17 +18,18 @@ */ import java.io.IOException; +import java.util.Comparator; import java.util.LinkedList; -import java.util.Comparator; import org.apache.lucene.analysis.NumericTokenStream; // for javadocs import org.apache.lucene.document.NumericField; // for javadocs -import org.apache.lucene.util.NumericUtils; -import org.apache.lucene.util.ToStringUtils; +import org.apache.lucene.index.FilteredTermsEnum; import org.apache.lucene.index.Terms; +import org.apache.lucene.index.TermsEnum; import org.apache.lucene.util.AttributeSource; import org.apache.lucene.util.BytesRef; -import org.apache.lucene.index.TermsEnum; +import org.apache.lucene.util.NumericUtils; +import org.apache.lucene.util.ToStringUtils; /** *

A {@link Query} that matches numeric values within a @@ -169,7 +170,7 @@ // For bigger precisionSteps this query likely // hits too many terms, so set to CONSTANT_SCORE_FILTER right off - // (especially as the FilteredTermEnum is costly if wasted only for AUTO tests because it + // (especially as the FilteredTermsEnum is costly if wasted only for AUTO tests because it // creates new enums from IndexReader for each sub-range) switch (valSize) { case 64: Index: lucene/src/java/org/apache/lucene/search/SingleTermsEnum.java =================================================================== --- lucene/src/java/org/apache/lucene/search/SingleTermsEnum.java (revision 1170711) +++ lucene/src/java/org/apache/lucene/search/SingleTermsEnum.java (working copy) @@ -1,52 +0,0 @@ -package org.apache.lucene.search; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.io.IOException; - -import org.apache.lucene.index.TermsEnum; -import org.apache.lucene.util.BytesRef; - -/** - * Subclass of FilteredTermsEnum for enumerating a single term. - *

- * This can be used by {@link MultiTermQuery}s that need only visit one term, - * but want to preserve MultiTermQuery semantics such as - * {@link MultiTermQuery#rewriteMethod}. - */ -public final class SingleTermsEnum extends FilteredTermsEnum { - private final BytesRef singleRef; - - /** - * Creates a new SingleTermsEnum. - *

- * After calling the constructor the enumeration is already pointing to the term, - * if it exists. - */ - public SingleTermsEnum(TermsEnum tenum, BytesRef termText) throws IOException { - super(tenum); - singleRef = termText; - setInitialSeekTerm(termText); - } - - @Override - protected AcceptStatus accept(BytesRef term) { - return term.equals(singleRef) ? AcceptStatus.YES : AcceptStatus.END; - } - -} Index: lucene/src/java/org/apache/lucene/search/FuzzyTermsEnum.java =================================================================== --- lucene/src/java/org/apache/lucene/search/FuzzyTermsEnum.java (revision 1170711) +++ lucene/src/java/org/apache/lucene/search/FuzzyTermsEnum.java (working copy) @@ -28,6 +28,7 @@ import org.apache.lucene.index.TermState; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; +import org.apache.lucene.index.FilteredTermsEnum; import org.apache.lucene.util.Attribute; import org.apache.lucene.util.AttributeImpl; import org.apache.lucene.util.AttributeSource; Index: lucene/src/java/org/apache/lucene/index/SingleTermsEnum.java =================================================================== --- lucene/src/java/org/apache/lucene/index/SingleTermsEnum.java (revision 1170711) +++ lucene/src/java/org/apache/lucene/index/SingleTermsEnum.java (working copy) @@ -1,4 +1,4 @@ -package org.apache.lucene.search; +package org.apache.lucene.index; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -19,15 +19,16 @@ import java.io.IOException; -import org.apache.lucene.index.TermsEnum; +import org.apache.lucene.search.MultiTermQuery; // javadocs import org.apache.lucene.util.BytesRef; /** * Subclass of FilteredTermsEnum for enumerating a single term. *

- * This can be used by {@link MultiTermQuery}s that need only visit one term, - * but want to preserve MultiTermQuery semantics such as - * {@link MultiTermQuery#rewriteMethod}. + * For example, this can be used by {@link MultiTermQuery}s + * that need only visit one term, but want to preserve + * MultiTermQuery semantics such as {@link + * MultiTermQuery#rewriteMethod}. */ public final class SingleTermsEnum extends FilteredTermsEnum { private final BytesRef singleRef; Index: lucene/src/java/org/apache/lucene/index/FilteredTermsEnum.java =================================================================== --- lucene/src/java/org/apache/lucene/index/FilteredTermsEnum.java (revision 1170711) +++ lucene/src/java/org/apache/lucene/index/FilteredTermsEnum.java (working copy) @@ -1,4 +1,4 @@ -package org.apache.lucene.search; +package org.apache.lucene.index; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -21,15 +21,9 @@ import java.util.Comparator; import org.apache.lucene.util.BytesRef; -import org.apache.lucene.index.TermState; -import org.apache.lucene.index.TermsEnum; -import org.apache.lucene.index.DocsEnum; -import org.apache.lucene.index.DocsAndPositionsEnum; import org.apache.lucene.util.AttributeSource; import org.apache.lucene.util.Bits; -// TODO: move this class to oal.index - /** * Abstract class for enumerating a subset of all terms. * Index: lucene/src/java/org/apache/lucene/index/AutomatonTermsEnum.java =================================================================== --- lucene/src/java/org/apache/lucene/index/AutomatonTermsEnum.java (revision 1170711) +++ lucene/src/java/org/apache/lucene/index/AutomatonTermsEnum.java (working copy) @@ -20,7 +20,6 @@ import java.io.IOException; import java.util.Comparator; -import org.apache.lucene.search.FilteredTermsEnum; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.IntsRef; import org.apache.lucene.util.automaton.ByteRunAutomaton; Index: lucene/src/java/org/apache/lucene/util/automaton/CompiledAutomaton.java =================================================================== --- lucene/src/java/org/apache/lucene/util/automaton/CompiledAutomaton.java (revision 1170711) +++ lucene/src/java/org/apache/lucene/util/automaton/CompiledAutomaton.java (working copy) @@ -24,7 +24,7 @@ import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.search.PrefixTermsEnum; -import org.apache.lucene.search.SingleTermsEnum; +import org.apache.lucene.index.SingleTermsEnum; import org.apache.lucene.util.BytesRef; /**