Index: src/test/org/apache/lucene/TestExternalCodecs.java =================================================================== --- src/test/org/apache/lucene/TestExternalCodecs.java (revision 900009) +++ src/test/org/apache/lucene/TestExternalCodecs.java (working copy) @@ -37,9 +37,9 @@ // For fun, test that we can override how terms are // sorted, and basic things still work -- this comparator // sorts in reversed unicode code point order: - private static final TermRef.Comparator reverseUnicodeComparator = new TermRef.Comparator() { + private static final BytesRef.Comparator reverseUnicodeComparator = new BytesRef.Comparator() { @Override - public int compare(TermRef t1, TermRef t2) { + public int compare(BytesRef t1, BytesRef t2) { byte[] b1 = t1.bytes; byte[] b2 = t2.bytes; int b1Stop; @@ -110,7 +110,7 @@ } @Override - public TermRef.Comparator getTermComparator() { + public BytesRef.Comparator getComparator() { return reverseUnicodeComparator; } } @@ -166,7 +166,7 @@ } @Override - public DocsConsumer startTerm(TermRef text) { + public DocsConsumer startTerm(BytesRef text) { final String term = text.toString(); current = new RAMTerm(term); docsConsumer.reset(current); @@ -175,12 +175,12 @@ @Override - public TermRef.Comparator getTermComparator() { - return TermRef.getUTF8SortedAsUTF16Comparator(); + public BytesRef.Comparator getComparator() { + return BytesRef.getUTF8SortedAsUTF16Comparator(); } @Override - public void finishTerm(TermRef text, int numDocs) { + public void finishTerm(BytesRef text, int numDocs) { // nocommit -- are we even called when numDocs == 0? if (numDocs > 0) { assert numDocs == current.docs.size(); @@ -270,12 +270,12 @@ } @Override - public TermRef.Comparator getTermComparator() { - return TermRef.getUTF8SortedAsUTF16Comparator(); + public BytesRef.Comparator getComparator() { + return BytesRef.getUTF8SortedAsUTF16Comparator(); } @Override - public TermRef next() { + public BytesRef next() { if (it == null) { if (current == null) { it = ramField.termToDocs.keySet().iterator(); @@ -285,14 +285,14 @@ } if (it.hasNext()) { current = it.next(); - return new TermRef(current); + return new BytesRef(current); } else { return null; } } @Override - public SeekStatus seek(TermRef term) { + public SeekStatus seek(BytesRef term) { current = term.toString(); if (ramField.termToDocs.containsKey(current)) { return SeekStatus.FOUND; @@ -317,9 +317,9 @@ } @Override - public TermRef term() { - // TODO: reuse TermRef - return new TermRef(current); + public BytesRef term() { + // TODO: reuse BytesRef + return new BytesRef(current); } @Override @@ -824,20 +824,20 @@ private void testTermsOrder(IndexReader r) throws Exception { // Verify sort order matches what my comparator said: - TermRef lastTermRef = null; + BytesRef lastBytesRef = null; TermsEnum terms = r.fields().terms("id").iterator(); //System.out.println("id terms:"); while(true) { - TermRef t = terms.next(); + BytesRef t = terms.next(); if (t == null) { break; } //System.out.println(" " + t); - if (lastTermRef == null) { - lastTermRef = new TermRef(t); + if (lastBytesRef == null) { + lastBytesRef = new BytesRef(t); } else { - assertTrue("terms in wrong order last=" + lastTermRef + " current=" + t, reverseUnicodeComparator.compare(lastTermRef, t) < 0); - lastTermRef.copy(t); + assertTrue("terms in wrong order last=" + lastBytesRef + " current=" + t, reverseUnicodeComparator.compare(lastBytesRef, t) < 0); + lastBytesRef.copy(t); } } } Index: src/test/org/apache/lucene/search/TestSort.java =================================================================== --- src/test/org/apache/lucene/search/TestSort.java (revision 900009) +++ src/test/org/apache/lucene/search/TestSort.java (working copy) @@ -35,7 +35,7 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.queryParser.ParseException; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.store.LockObtainFailedException; @@ -334,7 +334,7 @@ sort.setSort (new SortField[] { new SortField ("parser", new FieldCache.IntParser(){ - public final int parseInt(final TermRef term) { + public final int parseInt(final BytesRef term) { return (term.bytes[term.offset]-'A') * 123456; } }), SortField.FIELD_DOC }); @@ -343,7 +343,7 @@ fc.purgeAllCaches(); sort.setSort (new SortField[] { new SortField ("parser", new FieldCache.FloatParser(){ - public final float parseFloat(final TermRef term) { + public final float parseFloat(final BytesRef term) { return (float) Math.sqrt( term.bytes[term.offset] ); } }), SortField.FIELD_DOC }); @@ -352,7 +352,7 @@ fc.purgeAllCaches(); sort.setSort (new SortField[] { new SortField ("parser", new FieldCache.LongParser(){ - public final long parseLong(final TermRef term) { + public final long parseLong(final BytesRef term) { return (term.bytes[term.offset]-'A') * 1234567890L; } }), SortField.FIELD_DOC }); @@ -361,7 +361,7 @@ fc.purgeAllCaches(); sort.setSort (new SortField[] { new SortField ("parser", new FieldCache.DoubleParser(){ - public final double parseDouble(final TermRef term) { + public final double parseDouble(final BytesRef term) { return Math.pow( term.bytes[term.offset], (term.bytes[term.offset]-'A') ); } }), SortField.FIELD_DOC }); @@ -370,7 +370,7 @@ fc.purgeAllCaches(); sort.setSort (new SortField[] { new SortField ("parser", new FieldCache.ByteParser(){ - public final byte parseByte(final TermRef term) { + public final byte parseByte(final BytesRef term) { return (byte) (term.bytes[term.offset]-'A'); } }), SortField.FIELD_DOC }); @@ -379,7 +379,7 @@ fc.purgeAllCaches(); sort.setSort (new SortField[] { new SortField ("parser", new FieldCache.ShortParser(){ - public final short parseShort(final TermRef term) { + public final short parseShort(final BytesRef term) { return (short) (term.bytes[term.offset]-'A'); } }), SortField.FIELD_DOC }); @@ -440,7 +440,7 @@ @Override public void setNextReader(IndexReader reader, int docBase) throws IOException { docValues = FieldCache.DEFAULT.getInts(reader, "parser", new FieldCache.IntParser() { - public final int parseInt(final TermRef term) { + public final int parseInt(final BytesRef term) { return (term.bytes[term.offset]-'A') * 123456; } }); Index: src/test/org/apache/lucene/search/JustCompileSearch.java =================================================================== --- src/test/org/apache/lucene/search/JustCompileSearch.java (revision 900009) +++ src/test/org/apache/lucene/search/JustCompileSearch.java (working copy) @@ -25,7 +25,7 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; import org.apache.lucene.index.DocsEnum; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.PriorityQueue; /** @@ -203,7 +203,7 @@ static final class JustCompileExtendedFieldCacheLongParser implements FieldCache.LongParser { - public long parseLong(TermRef string) { + public long parseLong(BytesRef string) { throw new UnsupportedOperationException(UNSUPPORTED_MSG); } @@ -211,7 +211,7 @@ static final class JustCompileExtendedFieldCacheDoubleParser implements FieldCache.DoubleParser { - public double parseDouble(TermRef term) { + public double parseDouble(BytesRef term) { throw new UnsupportedOperationException(UNSUPPORTED_MSG); } Index: src/test/org/apache/lucene/search/TestNumericRangeQuery32.java =================================================================== --- src/test/org/apache/lucene/search/TestNumericRangeQuery32.java (revision 900009) +++ src/test/org/apache/lucene/search/TestNumericRangeQuery32.java (working copy) @@ -24,9 +24,8 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.NumericField; import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.index.IndexWriter.MaxFieldLength; -import org.apache.lucene.index.Term; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.LuceneTestCase; @@ -446,7 +445,7 @@ TermsEnum termEnum = q.getTermsEnum(searcher.getIndexReader()); int count = 0; while (termEnum.next() != null) { - final TermRef t = termEnum.term(); + final BytesRef t = termEnum.term(); if (t != null) { final int val = NumericUtils.prefixCodedToInt(t.toString()); assertTrue("value not in bounds " + val + " >= " + lower + " && " Index: src/test/org/apache/lucene/index/TestIndexWriter.java =================================================================== --- src/test/org/apache/lucene/index/TestIndexWriter.java (revision 900009) +++ src/test/org/apache/lucene/index/TestIndexWriter.java (working copy) @@ -72,6 +72,7 @@ import org.apache.lucene.util._TestUtil; import org.apache.lucene.util.Version; import org.apache.lucene.util.ThreadInterruptedException; +import org.apache.lucene.util.BytesRef; public class TestIndexWriter extends LuceneTestCase { public TestIndexWriter(String name) { @@ -4691,7 +4692,7 @@ UnicodeUtil.UTF16Result utf16 = new UnicodeUtil.UTF16Result(); while(true) { - final TermRef term = terms.next(); + final BytesRef term = terms.next(); if (term == null) { break; } @@ -4725,7 +4726,7 @@ // Test seeking: Iterator it = seenTerms.iterator(); while(it.hasNext()) { - TermRef tr = new TermRef(it.next()); + BytesRef tr = new BytesRef(it.next()); assertEquals("seek failed for term=" + termDesc(tr.toString()), TermsEnum.SeekStatus.FOUND, terms.seek(tr)); Index: src/test/org/apache/lucene/index/TestCodecs.java =================================================================== --- src/test/org/apache/lucene/index/TestCodecs.java (revision 900009) +++ src/test/org/apache/lucene/index/TestCodecs.java (working copy) @@ -140,13 +140,13 @@ class TermData implements Comparable { String text2; - final TermRef text; + final BytesRef text; int[] docs; PositionData[][] positions; FieldData field; public TermData(String text, int[] docs, PositionData[][] positions) { - this.text = new TermRef(text); + this.text = new BytesRef(text); this.text2 = text; this.docs = docs; this.positions = positions; @@ -272,14 +272,14 @@ assertNotNull(fieldsEnum.next()); TermsEnum termsEnum = fieldsEnum.terms(); for(int i=0;i= Byte.MIN_VALUE && num <= Byte.MAX_VALUE) { return (byte) num; @@ -168,7 +168,7 @@ /** The default parser for short values, which are encoded by {@link Short#toString(short)} */ public static final ShortParser DEFAULT_SHORT_PARSER = new ShortParser() { - public short parseShort(TermRef term) { + public short parseShort(BytesRef term) { final long num = FieldCacheImpl.parseLong(term); if (num >= Short.MIN_VALUE && num <= Short.MAX_VALUE) { return (short) num; @@ -187,7 +187,7 @@ /** The default parser for int values, which are encoded by {@link Integer#toString(int)} */ public static final IntParser DEFAULT_INT_PARSER = new IntParser() { - public int parseInt(TermRef term) { + public int parseInt(BytesRef term) { final long num = FieldCacheImpl.parseLong(term); if (num >= Integer.MIN_VALUE && num <= Integer.MAX_VALUE) { return (int) num; @@ -206,7 +206,7 @@ /** The default parser for float values, which are encoded by {@link Float#toString(float)} */ public static final FloatParser DEFAULT_FLOAT_PARSER = new FloatParser() { - public float parseFloat(TermRef term) { + public float parseFloat(BytesRef term) { // TODO: would be far better to directly parse // the UTF-8 bytes into float, but that's tricky? return Float.parseFloat(term.toString()); @@ -222,7 +222,7 @@ /** The default parser for long values, which are encoded by {@link Long#toString(long)} */ public static final LongParser DEFAULT_LONG_PARSER = new LongParser() { - public long parseLong(TermRef term) { + public long parseLong(BytesRef term) { return FieldCacheImpl.parseLong(term); } protected Object readResolve() { @@ -236,7 +236,7 @@ /** The default parser for double values, which are encoded by {@link Double#toString(double)} */ public static final DoubleParser DEFAULT_DOUBLE_PARSER = new DoubleParser() { - public double parseDouble(TermRef term) { + public double parseDouble(BytesRef term) { // TODO: would be far better to directly parse // the UTF-8 bytes into float, but that's tricky? return Double.parseDouble(term.toString()); @@ -255,7 +255,7 @@ * via {@link NumericField}/{@link NumericTokenStream}. */ public static final IntParser NUMERIC_UTILS_INT_PARSER=new IntParser(){ - public int parseInt(TermRef val) { + public int parseInt(BytesRef val) { final int shift = val.bytes[val.offset]-NumericUtils.SHIFT_START_INT; if (shift>0 && shift<=31) throw new FieldCacheImpl.StopFillCacheException(); @@ -275,7 +275,7 @@ * via {@link NumericField}/{@link NumericTokenStream}. */ public static final FloatParser NUMERIC_UTILS_FLOAT_PARSER=new FloatParser(){ - public float parseFloat(TermRef term) { + public float parseFloat(BytesRef term) { final int shift = term.bytes[term.offset]-NumericUtils.SHIFT_START_INT; if (shift>0 && shift<=31) throw new FieldCacheImpl.StopFillCacheException(); @@ -295,7 +295,7 @@ * via {@link NumericField}/{@link NumericTokenStream}. */ public static final LongParser NUMERIC_UTILS_LONG_PARSER = new LongParser(){ - public long parseLong(TermRef term) { + public long parseLong(BytesRef term) { final int shift = term.bytes[term.offset]-NumericUtils.SHIFT_START_LONG; if (shift>0 && shift<=63) throw new FieldCacheImpl.StopFillCacheException(); @@ -315,7 +315,7 @@ * via {@link NumericField}/{@link NumericTokenStream}. */ public static final DoubleParser NUMERIC_UTILS_DOUBLE_PARSER = new DoubleParser(){ - public double parseDouble(TermRef term) { + public double parseDouble(BytesRef term) { final int shift = term.bytes[term.offset]-NumericUtils.SHIFT_START_LONG; if (shift>0 && shift<=63) throw new FieldCacheImpl.StopFillCacheException(); Index: src/java/org/apache/lucene/search/MultiTermQuery.java =================================================================== --- src/java/org/apache/lucene/search/MultiTermQuery.java (revision 900009) +++ src/java/org/apache/lucene/search/MultiTermQuery.java (working copy) @@ -20,12 +20,11 @@ import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; -import java.util.Collection; import java.util.PriorityQueue; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.queryParser.QueryParser; // for javadoc import org.apache.lucene.util.Attribute; @@ -183,7 +182,7 @@ throw new NullPointerException("If you implement getTermsEnum(), you must specify a non-null field in the constructor of MultiTermQuery."); collector.boostAtt = boostAtt; int count = 0; - TermRef term; + BytesRef term; final Term placeholderTerm = new Term(query.field); while ((term = termsEnum.next()) != null) { if (collector.collect(placeholderTerm.createTerm(term.toString()), boostAtt.getBoost())) { @@ -464,7 +463,7 @@ // should not be costly, because 1) the // query/filter will load the TermInfo when it // runs, and 2) the terms dict has a cache: - // @deprecated: in 4.0 use TermRef for collectTerms() + // @deprecated: in 4.0 use BytesRef for collectTerms() docVisitCount += reader.docFreq(t); return true; } Index: src/java/org/apache/lucene/search/FuzzyQuery.java =================================================================== --- src/java/org/apache/lucene/search/FuzzyQuery.java (revision 900009) +++ src/java/org/apache/lucene/search/FuzzyQuery.java (working copy) @@ -19,7 +19,6 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermRef; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.util.ToStringUtils; Index: src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java =================================================================== --- src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java (revision 900009) +++ src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java (working copy) @@ -23,7 +23,6 @@ import org.apache.lucene.index.Term; import org.apache.lucene.index.TermDocs; import org.apache.lucene.index.TermEnum; -import org.apache.lucene.index.TermRef; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.index.DocsEnum; import org.apache.lucene.util.OpenBitSet; Index: src/java/org/apache/lucene/search/PrefixTermsEnum.java =================================================================== --- src/java/org/apache/lucene/search/PrefixTermsEnum.java (revision 900009) +++ src/java/org/apache/lucene/search/PrefixTermsEnum.java (working copy) @@ -21,7 +21,7 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; /** * Subclass of FilteredTermEnum for enumerating all terms that match the @@ -32,15 +32,15 @@ */ public class PrefixTermsEnum extends FilteredTermsEnum { - private final TermRef prefixRef; + private final BytesRef prefixRef; public PrefixTermsEnum(IndexReader reader, Term prefix) throws IOException { super(reader, prefix.field()); - setInitialSeekTerm(prefixRef = new TermRef(prefix.text())); + setInitialSeekTerm(prefixRef = new BytesRef(prefix.text())); } @Override - protected AcceptStatus accept(TermRef term) { + protected AcceptStatus accept(BytesRef term) { if (term.startsWith(prefixRef)) { return AcceptStatus.YES; } else { Index: src/java/org/apache/lucene/search/FilteredTermsEnum.java =================================================================== --- src/java/org/apache/lucene/search/FilteredTermsEnum.java (revision 900009) +++ src/java/org/apache/lucene/search/FilteredTermsEnum.java (working copy) @@ -20,7 +20,7 @@ import java.io.IOException; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Terms; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.index.DocsEnum; import org.apache.lucene.util.AttributeSource; @@ -39,23 +39,23 @@ */ public abstract class FilteredTermsEnum extends TermsEnum { - private TermRef initialSeekTerm = null; + private BytesRef initialSeekTerm = null; private boolean doSeek = true; - private TermRef actualTerm = null; + 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(TermRef) + * @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(TermRef term) throws IOException; + protected abstract AcceptStatus accept(BytesRef term) throws IOException; /** * Creates a filtered {@link TermsEnum} for the given field name and reader. @@ -75,7 +75,7 @@ } /** - * Use this method to set the initial {@link TermRef} + * 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), @@ -83,7 +83,7 @@ *

You can only use this method, if you keep the default * implementation of {@link #nextSeekTerm}. */ - protected final void setInitialSeekTerm(TermRef term) throws IOException { + protected final void setInitialSeekTerm(BytesRef term) throws IOException { this.initialSeekTerm = term; } @@ -102,8 +102,8 @@ * than the last enumerated term, else the behaviour of this enum * violates the contract for TermsEnums. */ - protected TermRef nextSeekTerm(final TermRef currentTerm) throws IOException { - final TermRef t = initialSeekTerm; + protected BytesRef nextSeekTerm(final BytesRef currentTerm) throws IOException { + final BytesRef t = initialSeekTerm; initialSeekTerm = null; return t; } @@ -121,13 +121,13 @@ } @Override - public TermRef term() throws IOException { + public BytesRef term() throws IOException { return (tenum == null) ? null : tenum.term(); } @Override - public TermRef.Comparator getTermComparator() throws IOException { - return (tenum == null) ? null : tenum.getTermComparator(); + public BytesRef.Comparator getComparator() throws IOException { + return (tenum == null) ? null : tenum.getComparator(); } @Override @@ -139,7 +139,7 @@ * @throws UnsupportedOperationException */ @Override - public SeekStatus seek(TermRef term) throws IOException { + public SeekStatus seek(BytesRef term) throws IOException { throw new UnsupportedOperationException(getClass().getName()+" does not support seeking"); } @@ -162,14 +162,14 @@ } @Override - public TermRef next() throws IOException { + public BytesRef next() throws IOException { if (tenum == null) return null; for (;;) { // Seek or forward the iterator if (doSeek) { doSeek = false; - final TermRef t = nextSeekTerm(actualTerm); + final BytesRef t = nextSeekTerm(actualTerm); if (t == null || tenum.seek(t) == SeekStatus.END) { // no more terms to seek to or enum exhausted return null; Index: src/java/org/apache/lucene/search/spans/SpanTermQuery.java =================================================================== --- src/java/org/apache/lucene/search/spans/SpanTermQuery.java (revision 900009) +++ src/java/org/apache/lucene/search/spans/SpanTermQuery.java (working copy) @@ -19,7 +19,7 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.ToStringUtils; import java.io.IOException; @@ -83,7 +83,7 @@ public Spans getSpans(final IndexReader reader) throws IOException { return new TermSpans(reader.termDocsEnum(reader.getDeletedDocs(), term.field(), - new TermRef(term.text())), term); + new BytesRef(term.text())), term); } } Index: src/java/org/apache/lucene/search/MultiPhraseQuery.java =================================================================== --- src/java/org/apache/lucene/search/MultiPhraseQuery.java (revision 900009) +++ src/java/org/apache/lucene/search/MultiPhraseQuery.java (working copy) @@ -24,7 +24,7 @@ import org.apache.lucene.index.Term; import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.PositionsEnum; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.ToStringUtils; import org.apache.lucene.util.PriorityQueue; import org.apache.lucene.util.Bits; @@ -180,7 +180,7 @@ } else { docsEnum = reader.termDocsEnum(reader.getDeletedDocs(), terms[0].field(), - new TermRef(terms[0].text())); + new BytesRef(terms[0].text())); } if (docsEnum == null) { @@ -461,7 +461,7 @@ for (int i = 0; i < terms.length; i++) { DocsEnum docs = indexReader.termDocsEnum(delDocs, terms[i].field(), - new TermRef(terms[i].text())); + new BytesRef(terms[i].text())); if (docs != null) { docsEnums.add(docs); } Index: src/java/org/apache/lucene/search/TermRangeTermsEnum.java =================================================================== --- src/java/org/apache/lucene/search/TermRangeTermsEnum.java (revision 900009) +++ src/java/org/apache/lucene/search/TermRangeTermsEnum.java (working copy) @@ -21,8 +21,7 @@ import java.text.Collator; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.TermRef; -import org.apache.lucene.util.StringHelper; +import org.apache.lucene.util.BytesRef; /** * Subclass of FilteredTermEnum for enumerating all terms that match the @@ -38,9 +37,9 @@ private String lowerTermText; private boolean includeLower; private boolean includeUpper; - final private TermRef lowerTermRef; - final private TermRef upperTermRef; - private final TermRef.Comparator termComp; + final private BytesRef lowerBytesRef; + final private BytesRef upperBytesRef; + private final BytesRef.Comparator termComp; /** * Enumerates all terms greater/equal than lowerTerm @@ -84,28 +83,28 @@ this.lowerTermText = ""; this.includeLower = true; } - lowerTermRef = new TermRef(this.lowerTermText); + lowerBytesRef = new BytesRef(this.lowerTermText); if (this.upperTermText == null) { this.includeUpper = true; - upperTermRef = null; + upperBytesRef = null; } else { - upperTermRef = new TermRef(upperTermText); + upperBytesRef = new BytesRef(upperTermText); } - TermRef startTermRef = (collator == null) ? lowerTermRef : new TermRef(""); - setInitialSeekTerm(startTermRef); - termComp = getTermComparator(); + BytesRef startBytesRef = (collator == null) ? lowerBytesRef : new BytesRef(""); + setInitialSeekTerm(startBytesRef); + termComp = getComparator(); } @Override - protected AcceptStatus accept(TermRef term) { + protected AcceptStatus accept(BytesRef term) { if (collator == null) { - if (!this.includeLower && term.equals(lowerTermRef)) + if (!this.includeLower && term.equals(lowerBytesRef)) return AcceptStatus.NO; // Use this field's default sort ordering - if (upperTermRef != null) { - final int cmp = termComp.compare(upperTermRef, term); + if (upperBytesRef != null) { + final int cmp = termComp.compare(upperBytesRef, term); /* * if beyond the upper term, or is exclusive and this is equal to * the upper term, break out Index: src/java/org/apache/lucene/search/NumericRangeQuery.java =================================================================== --- src/java/org/apache/lucene/search/NumericRangeQuery.java (revision 900009) +++ src/java/org/apache/lucene/search/NumericRangeQuery.java (working copy) @@ -24,10 +24,8 @@ import org.apache.lucene.document.NumericField; // for javadocs import org.apache.lucene.util.NumericUtils; import org.apache.lucene.util.ToStringUtils; -import org.apache.lucene.util.StringHelper; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.index.TermsEnum; /** @@ -381,10 +379,10 @@ */ private final class NumericRangeTermsEnum extends FilteredTermsEnum { - private final TermRef currentLowerBound = new TermRef(), currentUpperBound = new TermRef(); + private final BytesRef currentLowerBound = new BytesRef(), currentUpperBound = new BytesRef(); private final LinkedList rangeBounds = new LinkedList(); - private final TermRef.Comparator termComp; + private final BytesRef.Comparator termComp; NumericRangeTermsEnum(final IndexReader reader) throws IOException { super(reader, getField()); @@ -464,11 +462,11 @@ throw new IllegalArgumentException("valSize must be 32 or 64"); } - termComp = getTermComparator(); + termComp = getComparator(); } @Override - protected final TermRef nextSeekTerm(TermRef term) throws IOException { + protected final BytesRef nextSeekTerm(BytesRef term) throws IOException { if (rangeBounds.size() >= 2) { assert rangeBounds.size() % 2 == 0; @@ -486,7 +484,7 @@ } @Override - protected AcceptStatus accept(TermRef term) { + protected AcceptStatus accept(BytesRef term) { return (currentUpperBound != null && termComp.compare(term, currentUpperBound) <= 0) ? AcceptStatus.YES : AcceptStatus.NO_AND_SEEK; } Index: src/java/org/apache/lucene/search/PhraseQuery.java =================================================================== --- src/java/org/apache/lucene/search/PhraseQuery.java (revision 900009) +++ src/java/org/apache/lucene/search/PhraseQuery.java (working copy) @@ -22,7 +22,7 @@ import java.util.ArrayList; import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.Explanation.IDFExplanation; @@ -158,7 +158,7 @@ final Term t = terms.get(i); DocsEnum docsEnum = reader.termDocsEnum(delDocs, t.field(), - new TermRef(t.text())); + new BytesRef(t.text())); if (docsEnum == null) { return null; } Index: src/java/org/apache/lucene/search/TermQuery.java =================================================================== --- src/java/org/apache/lucene/search/TermQuery.java (revision 900009) +++ src/java/org/apache/lucene/search/TermQuery.java (working copy) @@ -22,7 +22,7 @@ import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.Explanation.IDFExplanation; import org.apache.lucene.util.ToStringUtils; @@ -72,7 +72,7 @@ @Override public Scorer scorer(IndexReader reader, boolean scoreDocsInOrder, boolean topScorer) throws IOException { - DocsEnum docs = reader.termDocsEnum(reader.getDeletedDocs(), term.field(), new TermRef(term.text())); + DocsEnum docs = reader.termDocsEnum(reader.getDeletedDocs(), term.field(), new BytesRef(term.text())); if (docs == null) { return null; } @@ -115,7 +115,7 @@ Explanation tfExplanation = new Explanation(); int tf = 0; - DocsEnum docs = reader.termDocsEnum(reader.getDeletedDocs(), term.field(), new TermRef(term.text())); + DocsEnum docs = reader.termDocsEnum(reader.getDeletedDocs(), term.field(), new BytesRef(term.text())); if (docs != null) { int newDoc = docs.advance(doc); if (newDoc == doc) { Index: src/java/org/apache/lucene/search/EmptyTermsEnum.java =================================================================== --- src/java/org/apache/lucene/search/EmptyTermsEnum.java (revision 900009) +++ src/java/org/apache/lucene/search/EmptyTermsEnum.java (working copy) @@ -17,7 +17,7 @@ * limitations under the License. */ -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.index.TermsEnum; /** @@ -38,13 +38,13 @@ @Override /** Always returns {@link AcceptStatus#END}. */ - protected AcceptStatus accept(TermRef term) { + protected AcceptStatus accept(BytesRef term) { return AcceptStatus.END; } /** Always returns {@link SeekStatus#END}. */ @Override - public SeekStatus seek(TermRef term) { + public SeekStatus seek(BytesRef term) { return SeekStatus.END; } Index: src/java/org/apache/lucene/search/AutomatonTermsEnum.java =================================================================== --- src/java/org/apache/lucene/search/AutomatonTermsEnum.java (revision 900009) +++ src/java/org/apache/lucene/search/AutomatonTermsEnum.java (working copy) @@ -22,7 +22,7 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.UnicodeUtil; import org.apache.lucene.util.automaton.Automaton; import org.apache.lucene.util.automaton.RunAutomaton; @@ -68,19 +68,19 @@ // true if this enum will not seek around private final boolean linearMode; // common suffix of the automaton - private final TermRef commonSuffixRef; + private final BytesRef commonSuffixRef; // true if the automaton accepts a finite language private final boolean finite; // array of sorted transitions for each state, indexed by state number private final Transition[][] allTransitions; // for path tracking: each bit is a numbered state private final BitSet visited; - // used for unicode conversion from TermRef byte[] to char[] + // used for unicode conversion from BytesRef byte[] to char[] private final UnicodeUtil.UTF16Result utf16 = new UnicodeUtil.UTF16Result(); - // used for unicode conversion from char[] to TermRef byte[] + // used for unicode conversion from char[] to BytesRef byte[] private final UnicodeUtil.UTF8Result utf8 = new UnicodeUtil.UTF8Result(); // the reference used for seeking forwards through the term dictionary - private final TermRef seekTermRef = new TermRef(); + private final BytesRef seekBytesRef = new BytesRef(); // this accept stati will be returned by accept() dependent on internal mode private final AcceptStatus NO_MATCH, YES_MATCH; @@ -109,7 +109,7 @@ this.finite = false; allTransitions = null; visited = null; - commonSuffixRef = new TermRef(getValidUTF16Suffix(SpecialOperations + commonSuffixRef = new BytesRef(getValidUTF16Suffix(SpecialOperations .getCommonSuffix(automaton))); NO_MATCH = AcceptStatus.NO; YES_MATCH = AcceptStatus.YES; @@ -120,7 +120,7 @@ // we will seek each time anyway (and take the unicode conversion hit). // its also currently expensive to calculate, because getCommonSuffix is // a bit expensive. - commonSuffixRef = new TermRef(""); + commonSuffixRef = new BytesRef(""); // build a cache of sorted transitions for every state allTransitions = new Transition[runAutomaton.getSize()][]; for (State state : this.automaton.getStates()) @@ -189,7 +189,7 @@ * In smart mode, it will never do this. */ @Override - protected AcceptStatus accept(final TermRef term) { + protected AcceptStatus accept(final BytesRef term) { if (term.endsWith(commonSuffixRef)) { UnicodeUtil.UTF8toUTF16(term.bytes, term.offset, term.length, utf16); return runAutomaton.run(utf16.result, 0, utf16.length) ? YES_MATCH : NO_MATCH; @@ -199,22 +199,22 @@ } @Override - protected TermRef nextSeekTerm(final TermRef term) throws IOException { + protected BytesRef nextSeekTerm(final BytesRef term) throws IOException { if (term == null) { // return the first seek term if (linearMode) { - seekTermRef.copy(""); + seekBytesRef.copy(""); } else { utf16.copyText(""); if (!nextString()) return null; UnicodeUtil.nextValidUTF16String(utf16); UnicodeUtil.UTF16toUTF8(utf16.result, 0, utf16.length, utf8); - seekTermRef.bytes = utf8.result; - seekTermRef.offset = 0; - seekTermRef.length = utf8.length; + seekBytesRef.bytes = utf8.result; + seekBytesRef.offset = 0; + seekBytesRef.length = utf8.length; } - return seekTermRef; + return seekBytesRef; } else if (!linearMode) { // seek to the next possible string UnicodeUtil.UTF8toUTF16(term.bytes, term.offset, term.length, utf16); @@ -222,10 +222,10 @@ // reposition UnicodeUtil.nextValidUTF16String(utf16); UnicodeUtil.UTF16toUTF8(utf16.result, 0, utf16.length, utf8); - seekTermRef.bytes = utf8.result; - seekTermRef.offset = 0; - seekTermRef.length = utf8.length; - return seekTermRef; + seekBytesRef.bytes = utf8.result; + seekBytesRef.offset = 0; + seekBytesRef.length = utf8.length; + return seekBytesRef; } } // no more possible strings can match Index: src/java/org/apache/lucene/search/SingleTermsEnum.java =================================================================== --- src/java/org/apache/lucene/search/SingleTermsEnum.java (revision 900009) +++ src/java/org/apache/lucene/search/SingleTermsEnum.java (working copy) @@ -21,8 +21,7 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermRef; -import org.apache.lucene.index.Terms; +import org.apache.lucene.util.BytesRef; /** * Subclass of FilteredTermsEnum for enumerating a single term. @@ -32,7 +31,7 @@ * {@link MultiTermQuery#rewriteMethod}. */ public final class SingleTermsEnum extends FilteredTermsEnum { - private final TermRef singleRef; + private final BytesRef singleRef; /** * Creates a new SingleTermsEnum. @@ -42,12 +41,12 @@ */ public SingleTermsEnum(IndexReader reader, Term singleTerm) throws IOException { super(reader, singleTerm.field()); - singleRef = new TermRef(singleTerm.text()); + singleRef = new BytesRef(singleTerm.text()); setInitialSeekTerm(singleRef); } @Override - protected AcceptStatus accept(TermRef term) { + protected AcceptStatus accept(BytesRef term) { return term.equals(singleRef) ? AcceptStatus.YES : AcceptStatus.END; } Index: src/java/org/apache/lucene/search/FuzzyTermsEnum.java =================================================================== --- src/java/org/apache/lucene/search/FuzzyTermsEnum.java (revision 900009) +++ src/java/org/apache/lucene/search/FuzzyTermsEnum.java (working copy) @@ -19,7 +19,7 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import java.io.IOException; @@ -121,22 +121,22 @@ this.text = searchTerm.text().substring(realPrefixLength); this.prefix = searchTerm.text().substring(0, realPrefixLength); - prefixTermRef = new TermRef(prefix); + prefixBytesRef = new BytesRef(prefix); initializeMaxDistances(); this.d = initDistanceArray(); - setInitialSeekTerm(prefixTermRef); + setInitialSeekTerm(prefixBytesRef); } - private final TermRef prefixTermRef; + private final BytesRef prefixBytesRef; /** * The termCompare method in FuzzyTermEnum uses Levenshtein distance to * calculate the distance between the given term and the comparing term. */ @Override - protected final AcceptStatus accept(TermRef term) { - if (term.startsWith(prefixTermRef)) { + protected final AcceptStatus accept(BytesRef term) { + if (term.startsWith(prefixBytesRef)) { // TODO: costly that we create intermediate String: final String target = term.toString().substring(prefix.length()); final float similarity = similarity(target); Index: src/java/org/apache/lucene/search/FieldCacheImpl.java =================================================================== --- src/java/org/apache/lucene/search/FieldCacheImpl.java (revision 900009) +++ src/java/org/apache/lucene/search/FieldCacheImpl.java (working copy) @@ -29,9 +29,7 @@ import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; -import org.apache.lucene.index.TermEnum; -import org.apache.lucene.index.TermDocs; // deprecated -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.Bits; import org.apache.lucene.util.StringHelper; import org.apache.lucene.util.FieldCacheSanityChecker; @@ -288,7 +286,7 @@ final Bits delDocs = reader.getDeletedDocs(); try { while(true) { - final TermRef term = termsEnum.next(); + final BytesRef term = termsEnum.next(); if (term == null) { break; } @@ -341,7 +339,7 @@ final Bits delDocs = reader.getDeletedDocs(); try { while(true) { - final TermRef term = termsEnum.next(); + final BytesRef term = termsEnum.next(); if (term == null) { break; } @@ -399,7 +397,7 @@ final Bits delDocs = reader.getDeletedDocs(); try { while(true) { - final TermRef term = termsEnum.next(); + final BytesRef term = termsEnum.next(); if (term == null) { break; } @@ -470,7 +468,7 @@ final Bits delDocs = reader.getDeletedDocs(); try { while(true) { - final TermRef term = termsEnum.next(); + final BytesRef term = termsEnum.next(); if (term == null) { break; } @@ -536,7 +534,7 @@ final Bits delDocs = reader.getDeletedDocs(); try { while(true) { - final TermRef term = termsEnum.next(); + final BytesRef term = termsEnum.next(); if (term == null) { break; } @@ -604,7 +602,7 @@ final Bits delDocs = reader.getDeletedDocs(); try { while(true) { - final TermRef term = termsEnum.next(); + final BytesRef term = termsEnum.next(); if (term == null) { break; } @@ -654,7 +652,7 @@ final TermsEnum termsEnum = terms.iterator(); final Bits delDocs = reader.getDeletedDocs(); while(true) { - final TermRef term = termsEnum.next(); + final BytesRef term = termsEnum.next(); if (term == null) { break; } @@ -705,7 +703,7 @@ final TermsEnum termsEnum = terms.iterator(); final Bits delDocs = reader.getDeletedDocs(); while(true) { - final TermRef term = termsEnum.next(); + final BytesRef term = termsEnum.next(); if (term == null) { break; } @@ -754,7 +752,7 @@ // Directly parses a numeric value from UTF8 bytes // nocommit -- whitespace? +e syntax? - final static long parseLong(TermRef term) { + final static long parseLong(BytesRef term) { int upto = term.offset; final int negMul; if (term.bytes[upto] == '-') { Index: src/java/org/apache/lucene/index/TermRef.java =================================================================== --- src/java/org/apache/lucene/index/TermRef.java (revision 900009) +++ src/java/org/apache/lucene/index/TermRef.java (working copy) @@ -1,247 +0,0 @@ -package org.apache.lucene.index; - -/** - * 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 org.apache.lucene.util.ArrayUtil; -import java.io.UnsupportedEncodingException; - -/** Represents the UTF8 bytes[] for a term's text. This is - * used when reading with the flex API, to avoid having to - * materialize full char[]. */ -public final class TermRef { - - public byte[] bytes; - public int offset; - public int length; - - public TermRef() { - } - - /** - * @param text Well-formed unicode text, with no unpaired surrogates or U+FFFF. - */ - public TermRef(String text) { - copy(text); - } - - public TermRef(TermRef other) { - copy(other); - } - - // nocommit: we could do this w/ UnicodeUtil w/o requiring - // allocation of new bytes[]? - /** - * @param text Well-formed unicode text, with no unpaired surrogates or U+FFFF. - */ - public void copy(String text) { - // nocommit -- assert text has no unpaired surrogates?? - try { - bytes = text.getBytes("UTF-8"); - } catch (UnsupportedEncodingException uee) { - // should not happen: - throw new RuntimeException("unable to encode to UTF-8"); - } - offset = 0; - length = bytes.length; - } - - public boolean termEquals(TermRef other) { - if (length == other.length) { - int upto = offset; - int otherUpto = other.offset; - final byte[] otherBytes = other.bytes; - for(int i=0;i offset) { - sb.append(' '); - } - sb.append(Integer.toHexString(bytes[i]&0xff)); - } - sb.append(']'); - return sb.toString(); - } - - private final String asUnicodeChar(char c) { - return "U+" + Integer.toHexString(c); - } - - // for debugging only -- this is slow - public String toUnicodeString() { - StringBuilder sb = new StringBuilder(); - sb.append('['); - final String s = toString(); - for(int i=0;i 0) { - sb.append(' '); - } - sb.append(asUnicodeChar(s.charAt(i))); - } - sb.append(']'); - return sb.toString(); - } - - public void copy(TermRef other) { - if (bytes == null) { - bytes = new byte[other.length]; - } else { - bytes = ArrayUtil.grow(bytes, other.length); - } - System.arraycopy(other.bytes, other.offset, bytes, 0, other.length); - length = other.length; - offset = 0; - } - - public void grow(int newLength) { - bytes = ArrayUtil.grow(bytes, newLength); - } - - public abstract static class Comparator { - abstract public int compare(TermRef a, TermRef b); - } - - private final static Comparator utf8SortedAsUTF16SortOrder = new UTF8SortedAsUTF16Comparator(); - - public static Comparator getUTF8SortedAsUTF16Comparator() { - return utf8SortedAsUTF16SortOrder; - } - - public static class UTF8SortedAsUTF16Comparator extends Comparator { - public int compare(TermRef a, TermRef b) { - - final byte[] aBytes = a.bytes; - int aUpto = a.offset; - final byte[] bBytes = b.bytes; - int bUpto = b.offset; - - final int aStop; - if (a.length < b.length) { - aStop = aUpto + a.length; - } else { - aStop = aUpto + b.length; - } - - while(aUpto < aStop) { - int aByte = aBytes[aUpto++] & 0xff; - int bByte = bBytes[bUpto++] & 0xff; - - if (aByte != bByte) { - - // See http://icu-project.org/docs/papers/utf16_code_point_order.html#utf-8-in-utf-16-order - - // We know the terms are not equal, but, we may - // have to carefully fixup the bytes at the - // difference to match UTF16's sort order: - if (aByte >= 0xee && bByte >= 0xee) { - if ((aByte & 0xfe) == 0xee) { - aByte += 0x10; - } - if ((bByte&0xfe) == 0xee) { - bByte += 0x10; - } - } - return aByte - bByte; - } - } - - // One is a prefix of the other, or, they are equal: - return a.length - b.length; - } - } -} Index: src/java/org/apache/lucene/index/ByteBlockPool.java =================================================================== --- src/java/org/apache/lucene/index/ByteBlockPool.java (revision 900009) +++ src/java/org/apache/lucene/index/ByteBlockPool.java (working copy) @@ -34,6 +34,7 @@ * hit a non-zero byte. */ import java.util.Arrays; +import org.apache.lucene.util.BytesRef; final class ByteBlockPool { @@ -144,9 +145,9 @@ return newUpto+3; } - // Fill in a TermRef from terms length & bytes encoded in + // Fill in a BytesRef from term's length & bytes encoded in // byte block - final TermRef setTermRef(TermRef term, int textStart) { + final BytesRef setBytesRef(BytesRef term, int textStart) { final byte[] bytes = term.bytes = buffers[textStart >> DocumentsWriter.BYTE_BLOCK_SHIFT]; int pos = textStart & DocumentsWriter.BYTE_BLOCK_MASK; if ((bytes[pos] & 0x80) == 0) { Index: src/java/org/apache/lucene/index/DocsEnum.java =================================================================== --- src/java/org/apache/lucene/index/DocsEnum.java (revision 900009) +++ src/java/org/apache/lucene/index/DocsEnum.java (working copy) @@ -45,8 +45,11 @@ // (defined?) after this? // nocommit -- fix this API so that intblock codecs are // able to return their own int arrays, to save a copy - /** Bulk read: returns number of docs read. Subclass may - * do this more efficiently. */ + /** Bulk read: returns number of docs read. + * + *

NOTE: the default impl simply delegates to {@link + * #nextDoc}, but subclasses may do this more + * efficiently. */ public int read(int[] docs, int[] freqs) throws IOException { int count = 0; while(count < docs.length) { Index: src/java/org/apache/lucene/index/MultiReader.java =================================================================== --- src/java/org/apache/lucene/index/MultiReader.java (revision 900009) +++ src/java/org/apache/lucene/index/MultiReader.java (working copy) @@ -33,6 +33,7 @@ import org.apache.lucene.search.Similarity; import org.apache.lucene.util.Bits; import org.apache.lucene.search.FieldCache; // not great (circular); used only to purge FieldCache entry on close +import org.apache.lucene.util.BytesRef; /** An IndexReader which reads multiple indexes, appending * their content. */ @@ -405,7 +406,7 @@ } @Override - public int docFreq(String field, TermRef t) throws IOException { + public int docFreq(String field, BytesRef t) throws IOException { ensureOpen(); int total = 0; // sum freqs in segments for (int i = 0; i < subReaders.length; i++) { Index: src/java/org/apache/lucene/index/LegacyFieldsEnum.java =================================================================== --- src/java/org/apache/lucene/index/LegacyFieldsEnum.java (revision 900009) +++ src/java/org/apache/lucene/index/LegacyFieldsEnum.java (working copy) @@ -19,6 +19,7 @@ import java.io.IOException; import org.apache.lucene.util.Bits; +import org.apache.lucene.util.BytesRef; /** Implements flex API (FieldsEnum/TermsEnum) on top of * pre-flex API. Used only for IndexReader impls outside @@ -72,8 +73,8 @@ private final IndexReader r; private final String field; private TermEnum terms; - private TermRef current; - private final TermRef tr = new TermRef(); + private BytesRef current; + private final BytesRef tr = new BytesRef(); private final LegacyDocsEnum docsEnum; LegacyTermsEnum(IndexReader r, String field) throws IOException { @@ -83,13 +84,13 @@ } @Override - public TermRef.Comparator getTermComparator() { + public BytesRef.Comparator getComparator() { // Pre-flex indexes always sorted in UTF16 order - return TermRef.getUTF8SortedAsUTF16Comparator(); + return BytesRef.getUTF8SortedAsUTF16Comparator(); } @Override - public SeekStatus seek(TermRef text) throws IOException { + public SeekStatus seek(BytesRef text) throws IOException { if (terms != null) { terms.close(); } @@ -102,7 +103,7 @@ } else if (t.field() == field) { tr.copy(t.text()); current = tr; - if (text.termEquals(tr)) { + if (text.bytesEquals(tr)) { return SeekStatus.FOUND; } else { return SeekStatus.NOT_FOUND; @@ -123,7 +124,7 @@ } @Override - public TermRef next() throws IOException { + public BytesRef next() throws IOException { if (terms == null) { // first next -- seek to start of field terms = r.terms(new Term(field, "")); @@ -146,7 +147,7 @@ } @Override - public TermRef term() { + public BytesRef term() { return current; } Index: src/java/org/apache/lucene/index/DirectoryReader.java =================================================================== --- src/java/org/apache/lucene/index/DirectoryReader.java (revision 900009) +++ src/java/org/apache/lucene/index/DirectoryReader.java (working copy) @@ -39,6 +39,7 @@ import org.apache.lucene.util.PriorityQueue; import org.apache.lucene.util.Bits; import org.apache.lucene.util.ReaderUtil; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.search.FieldCache; // not great (circular); used only to purge FieldCache entry on close @@ -792,7 +793,7 @@ } @Override - public int docFreq(String field, TermRef term) throws IOException { + public int docFreq(String field, BytesRef term) throws IOException { ensureOpen(); int total = 0; // sum freqs in segments for (int i = 0; i < subReaders.length; i++) { @@ -1214,10 +1215,10 @@ final TermsEnum terms; final int base; final int length; - TermRef current; + BytesRef current; final Bits skipDocs; - public TermsEnumWithBase(FieldsEnumWithBase start, TermsEnum terms, TermRef term) { + public TermsEnumWithBase(FieldsEnumWithBase start, TermsEnum terms, BytesRef term) { this.terms = terms; current = term; skipDocs = start.skipDocs; @@ -1226,7 +1227,7 @@ assert length >= 0: "length=" + length; } - public TermsEnumWithBase(TermsWithBase start, TermsEnum terms, TermRef term) { + public TermsEnumWithBase(TermsWithBase start, TermsEnum terms, BytesRef term) { this.terms = terms; current = term; skipDocs = start.skipDocs; @@ -1253,7 +1254,7 @@ } private final static class TermMergeQueue extends PriorityQueue { - TermRef.Comparator termComp; + BytesRef.Comparator termComp; TermMergeQueue(int size) { initialize(size); } @@ -1316,21 +1317,21 @@ // sub-segments. private final static class MultiTerms extends Terms { private final TermsWithBase[] subs; - private final TermRef.Comparator termComp; + private final BytesRef.Comparator termComp; public MultiTerms(TermsWithBase[] subs) throws IOException { this.subs = subs; - TermRef.Comparator _termComp = null; + BytesRef.Comparator _termComp = null; for(int i=0;it. * @throws IOException if there is a low-level IO error - * @deprecated Use {@link #docFreq(String,TermRef)} instead. + * @deprecated Use {@link #docFreq(String,BytesRef)} instead. */ @Deprecated public abstract int docFreq(Term t) throws IOException; @@ -908,7 +909,7 @@ * t. This method does not take into * account deleted documents that have not yet been * merged away. */ - public int docFreq(String field, TermRef term) throws IOException { + public int docFreq(String field, BytesRef term) throws IOException { final Terms terms = fields().terms(field); if (terms != null) { return terms.docFreq(term); @@ -970,7 +971,7 @@ // nocommit -- tap into per-thread cache, here? // nocommit -- should we return null or NullDocsEnum? /** Returns DocsEnum for the specified field & term. */ - public DocsEnum termDocsEnum(Bits skipDocs, String field, TermRef term) throws IOException { + public DocsEnum termDocsEnum(Bits skipDocs, String field, BytesRef term) throws IOException { assert field != null; assert term != null; Index: src/java/org/apache/lucene/index/DocumentsWriter.java =================================================================== --- src/java/org/apache/lucene/index/DocumentsWriter.java (revision 900009) +++ src/java/org/apache/lucene/index/DocumentsWriter.java (working copy) @@ -41,6 +41,7 @@ import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.Constants; import org.apache.lucene.util.ThreadInterruptedException; +import org.apache.lucene.util.BytesRef; /** * This class accepts multiple added documents and directly @@ -1001,7 +1002,7 @@ TermsEnum termsEnum = null; String currentField = null; - TermRef termRef = new TermRef(); + BytesRef termRef = new BytesRef(); for (Entry entry: deletesFlushed.terms.entrySet()) { Term term = entry.getKey(); // Since we visit terms sorted, we gain performance Index: src/java/org/apache/lucene/index/TermVectorsTermsWriterPerField.java =================================================================== --- src/java/org/apache/lucene/index/TermVectorsTermsWriterPerField.java (revision 900009) +++ src/java/org/apache/lucene/index/TermVectorsTermsWriterPerField.java (working copy) @@ -22,6 +22,7 @@ import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; import org.apache.lucene.document.Fieldable; import org.apache.lucene.store.IndexOutput; +import org.apache.lucene.util.BytesRef; final class TermVectorsTermsWriterPerField extends TermsHashConsumerPerField { @@ -95,7 +96,7 @@ public void abort() {} // nocommit -- should be @ thread level not field - private final TermRef flushTerm = new TermRef(); + private final BytesRef flushTerm = new BytesRef(); /** Called once per field per document if term vectors * are enabled, to write the vectors to @@ -129,7 +130,7 @@ // nocommit -- should I sort by whatever terms dict is // sorting by? - final RawPostingList[] postings = termsHashPerField.sortPostings(TermRef.getUTF8SortedAsUTF16Comparator()); + final RawPostingList[] postings = termsHashPerField.sortPostings(BytesRef.getUTF8SortedAsUTF16Comparator()); tvf.writeVInt(numPostings); byte bits = 0x0; @@ -150,8 +151,8 @@ final TermVectorsTermsWriter.PostingList posting = (TermVectorsTermsWriter.PostingList) postings[j]; final int freq = posting.freq; - // Get TermRef - termBytePool.setTermRef(flushTerm, posting.textStart); + // Get BytesRef + termBytePool.setBytesRef(flushTerm, posting.textStart); // Compute common byte prefix between last term and // this term Index: src/java/org/apache/lucene/index/CheckIndex.java =================================================================== --- src/java/org/apache/lucene/index/CheckIndex.java (revision 900009) +++ src/java/org/apache/lucene/index/CheckIndex.java (working copy) @@ -24,6 +24,7 @@ import org.apache.lucene.document.Document; import org.apache.lucene.index.codecs.Codecs; import org.apache.lucene.util.Bits; +import org.apache.lucene.util.BytesRef; import java.text.NumberFormat; import java.io.PrintStream; @@ -599,7 +600,7 @@ final TermsEnum terms = fields.terms(); while(true) { - final TermRef term = terms.next(); + final BytesRef term = terms.next(); if (term == null) { break; } Index: src/java/org/apache/lucene/index/codecs/pulsing/PulsingCodec.java =================================================================== --- src/java/org/apache/lucene/index/codecs/pulsing/PulsingCodec.java (revision 900009) +++ src/java/org/apache/lucene/index/codecs/pulsing/PulsingCodec.java (working copy) @@ -23,7 +23,6 @@ import org.apache.lucene.index.FieldInfos; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.SegmentWriteState; -import org.apache.lucene.index.TermRef; import org.apache.lucene.index.codecs.Codec; import org.apache.lucene.index.codecs.standard.StandardDocsConsumer; import org.apache.lucene.index.codecs.standard.StandardDocsProducer; @@ -39,6 +38,7 @@ import org.apache.lucene.index.codecs.standard.StandardTermsIndexReader; import org.apache.lucene.index.codecs.standard.StandardTermsIndexWriter; import org.apache.lucene.store.Directory; +import org.apache.lucene.util.BytesRef; /** This codec "inlines" the postings for terms that have * low docFreq. It wraps another codec, which is used for @@ -79,7 +79,7 @@ // Terms dict success = false; try { - FieldsConsumer ret = new StandardTermsDictWriter(indexWriter, state, pulsingWriter, TermRef.getUTF8SortedAsUTF16Comparator()); + FieldsConsumer ret = new StandardTermsDictWriter(indexWriter, state, pulsingWriter, BytesRef.getUTF8SortedAsUTF16Comparator()); success = true; return ret; } finally { @@ -110,7 +110,7 @@ fieldInfos, si.name, indexDivisor, - TermRef.getUTF8SortedAsUTF16Comparator()); + BytesRef.getUTF8SortedAsUTF16Comparator()); success = true; } finally { if (!success) { @@ -125,7 +125,7 @@ dir, fieldInfos, si.name, docsReader, readBufferSize, - TermRef.getUTF8SortedAsUTF16Comparator()); + BytesRef.getUTF8SortedAsUTF16Comparator()); success = true; return ret; } finally { Index: src/java/org/apache/lucene/index/codecs/TermsConsumer.java =================================================================== --- src/java/org/apache/lucene/index/codecs/TermsConsumer.java (revision 900009) +++ src/java/org/apache/lucene/index/codecs/TermsConsumer.java (working copy) @@ -19,10 +19,10 @@ import java.io.IOException; -import org.apache.lucene.index.TermRef; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.index.DocsEnum; import org.apache.lucene.util.PriorityQueue; +import org.apache.lucene.util.BytesRef; /** * NOTE: this API is experimental and will likely change @@ -31,30 +31,30 @@ public abstract class TermsConsumer { /** Starts a new term in this field. */ - public abstract DocsConsumer startTerm(TermRef text) throws IOException; + public abstract DocsConsumer startTerm(BytesRef text) throws IOException; /** Finishes the current term */ - public abstract void finishTerm(TermRef text, int numDocs) throws IOException; + public abstract void finishTerm(BytesRef text, int numDocs) throws IOException; /** Called when we are done adding terms to this field */ public abstract void finish() throws IOException; - /** Return the TermRef Comparator used to sort terms + /** Return the BytesRef Comparator used to sort terms * before feeding to this API. */ - public abstract TermRef.Comparator getTermComparator() throws IOException; + public abstract BytesRef.Comparator getComparator() throws IOException; // For default merge impl public static class TermMergeState { - TermRef current; + BytesRef current; TermsEnum termsEnum; int readerIndex; } private final static class MergeQueue extends PriorityQueue { - final TermRef.Comparator termComp; + final BytesRef.Comparator termComp; - public MergeQueue(int size, TermRef.Comparator termComp) { + public MergeQueue(int size, BytesRef.Comparator termComp) { initialize(size); this.termComp = termComp; } @@ -77,7 +77,7 @@ /** Default merge impl */ public void merge(MergeState mergeState, TermMergeState[] termsStates, int count) throws IOException { - final TermRef.Comparator termComp = getTermComparator(); + final BytesRef.Comparator termComp = getComparator(); //System.out.println("merge terms field=" + mergeState.fieldInfo.name + " comp=" + termComp); @@ -119,14 +119,14 @@ matchCount++; } TermMergeState top = queue.top(); - if (top == null || !top.current.termEquals(pending[0].current)) { + if (top == null || !top.current.bytesEquals(pending[0].current)) { break; } } if (matchCount > 0) { // Merge one term - final TermRef term = pending[0].current; + final BytesRef term = pending[0].current; //System.out.println(" merge term=" + term); final DocsConsumer docsConsumer = startTerm(term); final int numDocs = docsConsumer.merge(mergeState, match, matchCount); Index: src/java/org/apache/lucene/index/codecs/sep/SepCodec.java =================================================================== --- src/java/org/apache/lucene/index/codecs/sep/SepCodec.java (revision 900009) +++ src/java/org/apache/lucene/index/codecs/sep/SepCodec.java (working copy) @@ -23,7 +23,6 @@ import org.apache.lucene.index.FieldInfos; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.SegmentWriteState; -import org.apache.lucene.index.TermRef; import org.apache.lucene.index.codecs.Codec; import org.apache.lucene.index.codecs.FieldsConsumer; import org.apache.lucene.index.codecs.FieldsProducer; @@ -36,6 +35,7 @@ import org.apache.lucene.index.codecs.standard.StandardTermsIndexReader; import org.apache.lucene.index.codecs.standard.StandardTermsIndexWriter; import org.apache.lucene.store.Directory; +import org.apache.lucene.util.BytesRef; public class SepCodec extends Codec { @@ -61,7 +61,7 @@ success = false; try { - FieldsConsumer ret = new StandardTermsDictWriter(indexWriter, state, docsWriter, TermRef.getUTF8SortedAsUTF16Comparator()); + FieldsConsumer ret = new StandardTermsDictWriter(indexWriter, state, docsWriter, BytesRef.getUTF8SortedAsUTF16Comparator()); success = true; return ret; } finally { @@ -93,7 +93,7 @@ fieldInfos, si.name, indexDivisor, - TermRef.getUTF8SortedAsUTF16Comparator()); + BytesRef.getUTF8SortedAsUTF16Comparator()); success = true; } finally { if (!success) { @@ -107,7 +107,7 @@ dir, fieldInfos, si.name, docsReader, readBufferSize, - TermRef.getUTF8SortedAsUTF16Comparator()); + BytesRef.getUTF8SortedAsUTF16Comparator()); success = true; return ret; } finally { Index: src/java/org/apache/lucene/index/codecs/Codec.java =================================================================== --- src/java/org/apache/lucene/index/codecs/Codec.java (revision 900009) +++ src/java/org/apache/lucene/index/codecs/Codec.java (working copy) @@ -85,7 +85,6 @@ // So we can easily compute headerSize (below) if (out.getFilePointer()-start != codec.length() + 9) { - System.out.println(out.getFilePointer()-start + " vs " + (codec.length() + 8)); throw new IllegalArgumentException("codec must be simple ASCII, less than 128 characters in length [got " + codec + "]"); } } Index: src/java/org/apache/lucene/index/codecs/standard/SimpleStandardTermsIndexReader.java =================================================================== --- src/java/org/apache/lucene/index/codecs/standard/SimpleStandardTermsIndexReader.java (revision 900009) +++ src/java/org/apache/lucene/index/codecs/standard/SimpleStandardTermsIndexReader.java (working copy) @@ -22,7 +22,7 @@ import org.apache.lucene.index.FieldInfos; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.SegmentInfo; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.index.codecs.Codec; import org.apache.lucene.util.ArrayUtil; @@ -64,11 +64,11 @@ final private IndexInput in; private volatile boolean indexLoaded; - private final TermRef.Comparator termComp; + private final BytesRef.Comparator termComp; final HashMap fields = new HashMap(); - public SimpleStandardTermsIndexReader(Directory dir, FieldInfos fieldInfos, String segment, int indexDivisor, TermRef.Comparator termComp) + public SimpleStandardTermsIndexReader(Directory dir, FieldInfos fieldInfos, String segment, int indexDivisor, BytesRef.Comparator termComp) throws IOException { this.termComp = termComp; @@ -246,7 +246,7 @@ } @Override - public final void getIndexOffset(TermRef term, TermsIndexResult result) throws IOException { + public final void getIndexOffset(BytesRef term, TermsIndexResult result) throws IOException { // You must call loadTermsIndex if you had specified -1 for indexDivisor if (coreIndex == null) { throw new IllegalStateException("terms index was not loaded"); @@ -381,7 +381,7 @@ blockPointer[upto] = blockUpto * BYTE_BLOCK_SIZE + blockOffset; /* - TermRef tr = new TermRef(); + BytesRef tr = new BytesRef(); tr.bytes = blocks[blockUpto]; tr.offset = blockOffset; tr.length = thisTermLength; @@ -441,7 +441,7 @@ result.offset = fileOffset[idx]; } - public final void getIndexOffset(TermRef term, TermsIndexResult result) throws IOException { + public final void getIndexOffset(BytesRef term, TermsIndexResult result) throws IOException { if (Codec.DEBUG) { System.out.println("getIndexOffset field=" + fieldInfo.name + " term=" + term + " indexLen = " + blockPointer.length + " numIndexTerms=" + fileOffset.length + " this=" + this + " numIndexedTerms=" + fileOffset.length); Index: src/java/org/apache/lucene/index/codecs/standard/StandardTermsIndexWriter.java =================================================================== --- src/java/org/apache/lucene/index/codecs/standard/StandardTermsIndexWriter.java (revision 900009) +++ src/java/org/apache/lucene/index/codecs/standard/StandardTermsIndexWriter.java (working copy) @@ -19,7 +19,7 @@ import org.apache.lucene.store.IndexOutput; import org.apache.lucene.index.FieldInfo; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import java.io.IOException; public abstract class StandardTermsIndexWriter { @@ -27,7 +27,7 @@ public abstract void setTermsOutput(IndexOutput out); public abstract class FieldWriter { - public abstract boolean checkIndexTerm(TermRef text, int docFreq) throws IOException; + public abstract boolean checkIndexTerm(BytesRef text, int docFreq) throws IOException; } public abstract FieldWriter addField(FieldInfo fieldInfo); Index: src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictReader.java =================================================================== --- src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictReader.java (revision 900009) +++ src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictReader.java (working copy) @@ -28,7 +28,6 @@ import org.apache.lucene.index.FieldsEnum; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.SegmentInfo; -import org.apache.lucene.index.TermRef; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.index.codecs.Codec; @@ -40,6 +39,7 @@ import org.apache.lucene.util.CloseableThreadLocal; import org.apache.lucene.util.cache.Cache; import org.apache.lucene.util.cache.DoubleBarrelLRUCache; +import org.apache.lucene.util.BytesRef; /** Handles a terms dict, but defers all details of postings * reading to an instance of {@TermsDictDocsReader}. This @@ -57,10 +57,10 @@ private final String segment; private StandardTermsIndexReader indexReader; - private final TermRef.Comparator termComp; + private final BytesRef.Comparator termComp; public StandardTermsDictReader(StandardTermsIndexReader indexReader, Directory dir, FieldInfos fieldInfos, String segment, StandardDocsProducer docs, int readBufferSize, - TermRef.Comparator termComp) + BytesRef.Comparator termComp) throws IOException { this.segment = segment; @@ -221,7 +221,7 @@ final StandardTermsIndexReader.FieldReader indexReader; private final static int DEFAULT_CACHE_SIZE = 1024; // Used for caching the least recently looked-up Terms - private final Cache termsCache = new DoubleBarrelLRUCache(DEFAULT_CACHE_SIZE); + private final Cache termsCache = new DoubleBarrelLRUCache(DEFAULT_CACHE_SIZE); FieldReader(StandardTermsIndexReader.FieldReader fieldIndexReader, FieldInfo fieldInfo, long numTerms, long termsStartPointer) { assert numTerms > 0; @@ -232,7 +232,7 @@ } @Override - public int docFreq(TermRef text) throws IOException { + public int docFreq(BytesRef text) throws IOException { ThreadResources resources = getThreadResources(); if (resources.termsEnum.seek(text) == TermsEnum.SeekStatus.FOUND) { return resources.termsEnum.docFreq(); @@ -242,7 +242,7 @@ } @Override - public TermRef.Comparator getTermComparator() { + public BytesRef.Comparator getComparator() { return termComp; } @@ -254,7 +254,7 @@ // own terms enum and use its seek...) /* @Override - public DocsEnum docs(Bits skipDocs, TermRef text) throws IOException { + public DocsEnum docs(Bits skipDocs, BytesRef text) throws IOException { ThreadResources resources = getThreadResources(); if (resources.termsEnum.seek(text) == TermsEnum.SeekStatus.FOUND) { return resources.termsEnum.docs(skipDocs); @@ -312,7 +312,7 @@ } @Override - public TermRef.Comparator getTermComparator() { + public BytesRef.Comparator getComparator() { return termComp; } @@ -321,10 +321,10 @@ * is found, SeekStatus.NOT_FOUND if a different term * was found, SeekStatus.END if we hit EOF */ @Override - public SeekStatus seek(TermRef term) throws IOException { + public SeekStatus seek(BytesRef term) throws IOException { CacheEntry entry = null; - TermRef entryKey = null; + BytesRef entryKey = null; if (docs.canCaptureState()) { entry = termsCache.get(term); @@ -437,7 +437,7 @@ if (docs.canCaptureState() && doSeek) { // Store in cache entry = docs.captureState(); - entryKey = (TermRef) bytesReader.term.clone(); + entryKey = (BytesRef) bytesReader.term.clone(); entry.freq = docFreq; entry.termUpTo = termUpto; entry.filePointer = in.getFilePointer(); @@ -492,7 +492,7 @@ // Now, scan: int left = (int) (pos - termUpto); while(left > 0) { - TermRef term = next(); + BytesRef term = next(); assert term != null; left--; } @@ -502,7 +502,7 @@ } @Override - public TermRef term() { + public BytesRef term() { return bytesReader.term; } @@ -512,7 +512,7 @@ } @Override - public TermRef next() throws IOException { + public BytesRef next() throws IOException { if (termUpto >= numTerms-1) { return null; } Index: src/java/org/apache/lucene/index/codecs/standard/SimpleStandardTermsIndexWriter.java =================================================================== --- src/java/org/apache/lucene/index/codecs/standard/SimpleStandardTermsIndexWriter.java (revision 900009) +++ src/java/org/apache/lucene/index/codecs/standard/SimpleStandardTermsIndexWriter.java (working copy) @@ -22,7 +22,7 @@ import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.SegmentWriteState; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.index.codecs.Codec; import java.util.List; @@ -88,7 +88,7 @@ } @Override - public boolean checkIndexTerm(TermRef text, int docFreq) throws IOException { + public boolean checkIndexTerm(BytesRef text, int docFreq) throws IOException { // First term is first indexed term: if (0 == (numTerms++ % termIndexInterval)) { final long termsPointer = termsOut.getFilePointer(); Index: src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictWriter.java =================================================================== --- src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictWriter.java (revision 900009) +++ src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictWriter.java (working copy) @@ -25,7 +25,7 @@ import org.apache.lucene.index.FieldInfos; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.SegmentWriteState; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.index.codecs.Codec; import org.apache.lucene.index.codecs.FieldsConsumer; import org.apache.lucene.index.codecs.DocsConsumer; @@ -59,12 +59,12 @@ FieldInfo currentField; private final StandardTermsIndexWriter indexWriter; private final List fields = new ArrayList(); - private final TermRef.Comparator termComp; + private final BytesRef.Comparator termComp; // nocommit private String segment; - public StandardTermsDictWriter(StandardTermsIndexWriter indexWriter, SegmentWriteState state, StandardDocsConsumer consumer, TermRef.Comparator termComp) throws IOException { + public StandardTermsDictWriter(StandardTermsIndexWriter indexWriter, SegmentWriteState state, StandardDocsConsumer consumer, BytesRef.Comparator termComp) throws IOException { final String termsFileName = IndexFileNames.segmentFileName(state.segmentName, StandardCodec.TERMS_EXTENSION); this.indexWriter = indexWriter; this.termComp = termComp; @@ -167,12 +167,12 @@ } @Override - public TermRef.Comparator getTermComparator() { + public BytesRef.Comparator getComparator() { return termComp; } @Override - public DocsConsumer startTerm(TermRef text) throws IOException { + public DocsConsumer startTerm(BytesRef text) throws IOException { consumer.startTerm(); if (Codec.DEBUG) { consumer.desc = fieldInfo.name + ":" + text; @@ -182,7 +182,7 @@ } @Override - public void finishTerm(TermRef text, int numDocs) throws IOException { + public void finishTerm(BytesRef text, int numDocs) throws IOException { // mxx if (Codec.DEBUG) { Index: src/java/org/apache/lucene/index/codecs/standard/DeltaBytesReader.java =================================================================== --- src/java/org/apache/lucene/index/codecs/standard/DeltaBytesReader.java (revision 900009) +++ src/java/org/apache/lucene/index/codecs/standard/DeltaBytesReader.java (working copy) @@ -18,13 +18,13 @@ */ import org.apache.lucene.store.IndexInput; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import java.io.IOException; // Handles reading incremental UTF8 encoded terms final class DeltaBytesReader { - final TermRef term = new TermRef(); + final BytesRef term = new BytesRef(); final IndexInput in; DeltaBytesReader(IndexInput in) { @@ -32,7 +32,7 @@ term.bytes = new byte[10]; } - void reset(TermRef text) { + void reset(BytesRef text) { term.copy(text); } Index: src/java/org/apache/lucene/index/codecs/standard/StandardTermsIndexReader.java =================================================================== --- src/java/org/apache/lucene/index/codecs/standard/StandardTermsIndexReader.java (revision 900009) +++ src/java/org/apache/lucene/index/codecs/standard/StandardTermsIndexReader.java (working copy) @@ -18,7 +18,7 @@ */ import org.apache.lucene.index.FieldInfo; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import java.io.IOException; import java.util.Collection; @@ -41,7 +41,7 @@ static class TermsIndexResult { long position; - final TermRef term = new TermRef(); + final BytesRef term = new BytesRef(); long offset; }; @@ -52,7 +52,7 @@ * expects that you'll then scan the file and * sequentially call isIndexTerm for each term * encountered. */ - public abstract void getIndexOffset(TermRef term, TermsIndexResult result) throws IOException; + public abstract void getIndexOffset(BytesRef term, TermsIndexResult result) throws IOException; public abstract void getIndexOffset(long ord, TermsIndexResult result) throws IOException; Index: src/java/org/apache/lucene/index/codecs/standard/DeltaBytesWriter.java =================================================================== --- src/java/org/apache/lucene/index/codecs/standard/DeltaBytesWriter.java (revision 900009) +++ src/java/org/apache/lucene/index/codecs/standard/DeltaBytesWriter.java (working copy) @@ -19,7 +19,7 @@ import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.store.IndexOutput; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import java.io.IOException; @@ -37,7 +37,7 @@ lastLength = 0; } - void write(TermRef text) throws IOException { + void write(BytesRef text) throws IOException { int start = 0; int upto = text.offset; final int length = text.length; Index: src/java/org/apache/lucene/index/codecs/standard/StandardCodec.java =================================================================== --- src/java/org/apache/lucene/index/codecs/standard/StandardCodec.java (revision 900009) +++ src/java/org/apache/lucene/index/codecs/standard/StandardCodec.java (working copy) @@ -23,7 +23,7 @@ import org.apache.lucene.index.FieldInfos; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.SegmentWriteState; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.index.codecs.Codec; import org.apache.lucene.index.codecs.FieldsConsumer; import org.apache.lucene.index.codecs.FieldsProducer; @@ -53,7 +53,7 @@ success = false; try { - FieldsConsumer ret = new StandardTermsDictWriter(indexWriter, state, docs, TermRef.getUTF8SortedAsUTF16Comparator()); + FieldsConsumer ret = new StandardTermsDictWriter(indexWriter, state, docs, BytesRef.getUTF8SortedAsUTF16Comparator()); success = true; return ret; } finally { @@ -80,7 +80,7 @@ fieldInfos, si.name, indexDivisor, - TermRef.getUTF8SortedAsUTF16Comparator()); + BytesRef.getUTF8SortedAsUTF16Comparator()); success = true; } finally { if (!success) { @@ -94,7 +94,7 @@ dir, fieldInfos, si.name, docs, readBufferSize, - TermRef.getUTF8SortedAsUTF16Comparator()); + BytesRef.getUTF8SortedAsUTF16Comparator()); success = true; return ret; } finally { Index: src/java/org/apache/lucene/index/codecs/FieldsConsumer.java =================================================================== --- src/java/org/apache/lucene/index/codecs/FieldsConsumer.java (revision 900009) +++ src/java/org/apache/lucene/index/codecs/FieldsConsumer.java (working copy) @@ -21,7 +21,6 @@ import org.apache.lucene.index.Fields; import org.apache.lucene.index.FieldsEnum; import org.apache.lucene.index.TermsEnum; -import org.apache.lucene.index.TermRef; import org.apache.lucene.util.PriorityQueue; import java.io.IOException; Index: src/java/org/apache/lucene/index/codecs/intblock/IntBlockCodec.java =================================================================== --- src/java/org/apache/lucene/index/codecs/intblock/IntBlockCodec.java (revision 900009) +++ src/java/org/apache/lucene/index/codecs/intblock/IntBlockCodec.java (working copy) @@ -23,7 +23,6 @@ import org.apache.lucene.index.FieldInfos; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.SegmentWriteState; -import org.apache.lucene.index.TermRef; import org.apache.lucene.index.codecs.Codec; import org.apache.lucene.index.codecs.FieldsConsumer; import org.apache.lucene.index.codecs.FieldsProducer; @@ -39,6 +38,7 @@ import org.apache.lucene.index.codecs.standard.StandardTermsIndexReader; import org.apache.lucene.index.codecs.standard.StandardTermsIndexWriter; import org.apache.lucene.store.Directory; +import org.apache.lucene.util.BytesRef; public class IntBlockCodec extends Codec { @@ -63,7 +63,7 @@ success = false; try { - FieldsConsumer ret = new StandardTermsDictWriter(indexWriter, state, docsWriter, TermRef.getUTF8SortedAsUTF16Comparator()); + FieldsConsumer ret = new StandardTermsDictWriter(indexWriter, state, docsWriter, BytesRef.getUTF8SortedAsUTF16Comparator()); success = true; return ret; } finally { @@ -96,7 +96,7 @@ fieldInfos, si.name, indexDivisor, - TermRef.getUTF8SortedAsUTF16Comparator()); + BytesRef.getUTF8SortedAsUTF16Comparator()); success = true; } finally { if (!success) { @@ -110,7 +110,7 @@ dir, fieldInfos, si.name, docsReader, readBufferSize, - TermRef.getUTF8SortedAsUTF16Comparator()); + BytesRef.getUTF8SortedAsUTF16Comparator()); success = true; return ret; } finally { Index: src/java/org/apache/lucene/index/codecs/preflex/PreFlexFields.java =================================================================== --- src/java/org/apache/lucene/index/codecs/preflex/PreFlexFields.java (revision 900009) +++ src/java/org/apache/lucene/index/codecs/preflex/PreFlexFields.java (working copy) @@ -30,7 +30,6 @@ import org.apache.lucene.index.PositionsEnum; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermRef; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.index.CompoundFileReader; @@ -39,6 +38,7 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.Bits; +import org.apache.lucene.util.BytesRef; /** Exposes flex API on a pre-flex index, as a codec. */ public class PreFlexFields extends FieldsProducer { @@ -220,9 +220,9 @@ } @Override - public TermRef.Comparator getTermComparator() { + public BytesRef.Comparator getComparator() { // Pre-flex indexes always sorted in UTF16 order - return TermRef.getUTF8SortedAsUTF16Comparator(); + return BytesRef.getUTF8SortedAsUTF16Comparator(); } } @@ -231,8 +231,8 @@ private FieldInfo fieldInfo; private final PreDocsEnum docsEnum; private boolean skipNext; - private TermRef current; - private final TermRef scratchTermRef = new TermRef(); + private BytesRef current; + private final BytesRef scratchBytesRef = new BytesRef(); public PreTermsEnum() throws IOException { docsEnum = new PreDocsEnum(); @@ -263,9 +263,9 @@ } @Override - public TermRef.Comparator getTermComparator() { + public BytesRef.Comparator getComparator() { // Pre-flex indexes always sorted in UTF16 order - return TermRef.getUTF8SortedAsUTF16Comparator(); + return BytesRef.getUTF8SortedAsUTF16Comparator(); } @Override @@ -279,7 +279,7 @@ } @Override - public SeekStatus seek(TermRef term) throws IOException { + public SeekStatus seek(BytesRef term) throws IOException { if (Codec.DEBUG) { System.out.println("pff.seek term=" + term); } @@ -287,15 +287,15 @@ termEnum = getTermsDict().terms(new Term(fieldInfo.name, term.toString())); final Term t = termEnum.term(); - final TermRef tr; + final BytesRef tr; if (t != null) { - tr = scratchTermRef; - scratchTermRef.copy(t.text()); + tr = scratchBytesRef; + scratchBytesRef.copy(t.text()); } else { tr = null; } - if (t != null && t.field() == fieldInfo.name && term.termEquals(tr)) { + if (t != null && t.field() == fieldInfo.name && term.bytesEquals(tr)) { current = tr; return SeekStatus.FOUND; } else if (t == null || t.field() != fieldInfo.name) { @@ -308,14 +308,14 @@ } @Override - public TermRef next() throws IOException { + public BytesRef next() throws IOException { if (skipNext) { skipNext = false; if (termEnum.term() == null) { return null; } else { - scratchTermRef.copy(termEnum.term().text()); - return current = scratchTermRef; + scratchBytesRef.copy(termEnum.term().text()); + return current = scratchBytesRef; } } if (termEnum.next()) { @@ -327,8 +327,8 @@ if (Codec.DEBUG) { System.out.println(" ok"); } - scratchTermRef.copy(t.text()); - current = scratchTermRef; + scratchBytesRef.copy(t.text()); + current = scratchBytesRef; return current; } else { assert !t.field().equals(fieldInfo.name); // make sure field name is interned @@ -344,7 +344,7 @@ } @Override - public TermRef term() { + public BytesRef term() { return current; } @@ -355,6 +355,8 @@ @Override public DocsEnum docs(Bits skipDocs) throws IOException { + // nocommit -- must assert that skipDocs "matches" the + // underlying deletedDocs? docsEnum.reset(termEnum, skipDocs); return docsEnum; } Index: src/java/org/apache/lucene/index/Terms.java =================================================================== --- src/java/org/apache/lucene/index/Terms.java (revision 900009) +++ src/java/org/apache/lucene/index/Terms.java (working copy) @@ -19,6 +19,7 @@ import java.io.IOException; import org.apache.lucene.util.Bits; +import org.apache.lucene.util.BytesRef; /** * NOTE: this API is experimental and will likely change @@ -29,15 +30,15 @@ /** Returns an iterator that will step through all terms */ public abstract TermsEnum iterator() throws IOException; - /** Return the TermRef Comparator used to sort terms + /** Return the BytesRef Comparator used to sort terms * provided by the iterator. NOTE: this may return null * if there are no terms. This method may be invoked * many times; it's best to cache a single instance & * reuse it. */ - public abstract TermRef.Comparator getTermComparator() throws IOException; + public abstract BytesRef.Comparator getComparator() throws IOException; /** Returns the docFreq of the specified term text. */ - public int docFreq(TermRef text) throws IOException { + public int docFreq(BytesRef text) throws IOException { // nocommit -- make thread private cache so we share // single enum // NOTE: subclasses may have more efficient impl @@ -50,7 +51,7 @@ } /** Get DocsEnum for the specified term. */ - public DocsEnum docs(Bits skipDocs, TermRef text) throws IOException { + public DocsEnum docs(Bits skipDocs, BytesRef text) throws IOException { // NOTE: subclasses may have more efficient impl final TermsEnum terms = iterator(); if (terms.seek(text) == TermsEnum.SeekStatus.FOUND) { Index: src/java/org/apache/lucene/util/BytesRef.java =================================================================== --- src/java/org/apache/lucene/util/BytesRef.java (revision 0) +++ src/java/org/apache/lucene/util/BytesRef.java (revision 0) @@ -0,0 +1,250 @@ +package org.apache.lucene.util; + +/** + * 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.UnsupportedEncodingException; + +/** Represents byte[], as a slice (offset + length) into an + * existing byte[]. */ +public final class BytesRef { + + public byte[] bytes; + public int offset; + public int length; + + public BytesRef() { + } + + /** + * @param text Initialize the byte[] from the UTF8 bytes + * for the provided Sring. This must be well-formed + * unicode text, with no unpaired surrogates or U+FFFF. + */ + public BytesRef(String text) { + copy(text); + } + + public BytesRef(BytesRef other) { + copy(other); + } + + // nocommit: we could do this w/ UnicodeUtil w/o requiring + // allocation of new bytes[]? + /** + * Copies the UTF8 bytes for this string. + * + * @param text Must be well-formed unicode text, with no + * unpaired surrogates or U+FFFF. + */ + public void copy(String text) { + // nocommit -- assert text has no unpaired surrogates?? + try { + bytes = text.getBytes("UTF-8"); + } catch (UnsupportedEncodingException uee) { + // should not happen: + throw new RuntimeException("unable to encode to UTF-8"); + } + offset = 0; + length = bytes.length; + } + + public boolean bytesEquals(BytesRef other) { + if (length == other.length) { + int upto = offset; + int otherUpto = other.offset; + final byte[] otherBytes = other.bytes; + for(int i=0;i offset) { + sb.append(' '); + } + sb.append(Integer.toHexString(bytes[i]&0xff)); + } + sb.append(']'); + return sb.toString(); + } + + private final String asUnicodeChar(char c) { + return "U+" + Integer.toHexString(c); + } + + // for debugging only -- this is slow + public String toUnicodeString() { + StringBuilder sb = new StringBuilder(); + sb.append('['); + final String s = toString(); + for(int i=0;i 0) { + sb.append(' '); + } + sb.append(asUnicodeChar(s.charAt(i))); + } + sb.append(']'); + return sb.toString(); + } + + public void copy(BytesRef other) { + if (bytes == null) { + bytes = new byte[other.length]; + } else { + bytes = ArrayUtil.grow(bytes, other.length); + } + System.arraycopy(other.bytes, other.offset, bytes, 0, other.length); + length = other.length; + offset = 0; + } + + public void grow(int newLength) { + bytes = ArrayUtil.grow(bytes, newLength); + } + + public abstract static class Comparator { + abstract public int compare(BytesRef a, BytesRef b); + } + + private final static Comparator utf8SortedAsUTF16SortOrder = new UTF8SortedAsUTF16Comparator(); + + public static Comparator getUTF8SortedAsUTF16Comparator() { + return utf8SortedAsUTF16SortOrder; + } + + public static class UTF8SortedAsUTF16Comparator extends Comparator { + public int compare(BytesRef a, BytesRef b) { + + final byte[] aBytes = a.bytes; + int aUpto = a.offset; + final byte[] bBytes = b.bytes; + int bUpto = b.offset; + + final int aStop; + if (a.length < b.length) { + aStop = aUpto + a.length; + } else { + aStop = aUpto + b.length; + } + + while(aUpto < aStop) { + int aByte = aBytes[aUpto++] & 0xff; + int bByte = bBytes[bUpto++] & 0xff; + + if (aByte != bByte) { + + // See http://icu-project.org/docs/papers/utf16_code_point_order.html#utf-8-in-utf-16-order + + // We know the terms are not equal, but, we may + // have to carefully fixup the bytes at the + // difference to match UTF16's sort order: + if (aByte >= 0xee && bByte >= 0xee) { + if ((aByte & 0xfe) == 0xee) { + aByte += 0x10; + } + if ((bByte&0xfe) == 0xee) { + bByte += 0x10; + } + } + return aByte - bByte; + } + } + + // One is a prefix of the other, or, they are equal: + return a.length - b.length; + } + } +} Property changes on: src/java/org/apache/lucene/util/BytesRef.java ___________________________________________________________________ Added: svn:eol-style + native Index: src/java/org/apache/lucene/util/NumericUtils.java =================================================================== --- src/java/org/apache/lucene/util/NumericUtils.java (revision 900009) +++ src/java/org/apache/lucene/util/NumericUtils.java (working copy) @@ -21,7 +21,6 @@ import org.apache.lucene.document.NumericField; // for javadocs import org.apache.lucene.search.NumericRangeQuery; // for javadocs import org.apache.lucene.search.NumericRangeFilter; // for javadocs -import org.apache.lucene.index.TermRef; /** * This is a helper class to generate prefix-encoded representations for numerical values @@ -220,7 +219,7 @@ return (sortableBits << shift) ^ 0x8000000000000000L; } - public static long prefixCodedToLong(final TermRef term) { + public static long prefixCodedToLong(final BytesRef term) { final int shift = term.bytes[term.offset]-SHIFT_START_LONG; if (shift>63 || shift<0) throw new NumberFormatException("Invalid shift value in prefixCoded string (is encoded value really an INT?)"); @@ -267,7 +266,7 @@ return (sortableBits << shift) ^ 0x80000000; } - public static int prefixCodedToInt(final TermRef term) { + public static int prefixCodedToInt(final BytesRef term) { final int shift = term.bytes[term.offset]-SHIFT_START_INT; if (shift>31 || shift<0) throw new NumberFormatException("Invalid shift value in prefixCoded string (is encoded value really an INT?)"); Index: contrib/surround/src/java/org/apache/lucene/queryParser/surround/query/SrndTruncQuery.java =================================================================== --- contrib/surround/src/java/org/apache/lucene/queryParser/surround/query/SrndTruncQuery.java (revision 900009) +++ contrib/surround/src/java/org/apache/lucene/queryParser/surround/query/SrndTruncQuery.java (working copy) @@ -19,7 +19,7 @@ import org.apache.lucene.index.Term; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.index.Terms; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.index.IndexReader; import java.io.IOException; @@ -42,7 +42,7 @@ private final char mask; private String prefix; - private TermRef prefixRef; + private BytesRef prefixRef; private Pattern pattern; @@ -71,7 +71,7 @@ i++; } prefix = truncated.substring(0, i); - prefixRef = new TermRef(prefix); + prefixRef = new BytesRef(prefix); StringBuilder re = new StringBuilder(); while (i < truncated.length()) { @@ -96,7 +96,7 @@ TermsEnum termsEnum = terms.iterator(); TermsEnum.SeekStatus status = termsEnum.seek(prefixRef); - TermRef text; + BytesRef text; if (status == TermsEnum.SeekStatus.FOUND) { text = prefixRef; } else if (status == TermsEnum.SeekStatus.NOT_FOUND) { Index: contrib/surround/src/java/org/apache/lucene/queryParser/surround/query/SrndPrefixQuery.java =================================================================== --- contrib/surround/src/java/org/apache/lucene/queryParser/surround/query/SrndPrefixQuery.java (revision 900009) +++ contrib/surround/src/java/org/apache/lucene/queryParser/surround/query/SrndPrefixQuery.java (working copy) @@ -18,7 +18,7 @@ import org.apache.lucene.index.Term; import org.apache.lucene.index.Terms; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.index.IndexReader; @@ -26,11 +26,11 @@ public class SrndPrefixQuery extends SimpleTerm { - private final TermRef prefixRef; + private final BytesRef prefixRef; public SrndPrefixQuery(String prefix, boolean quoted, char truncator) { super(quoted); this.prefix = prefix; - prefixRef = new TermRef(prefix); + prefixRef = new BytesRef(prefix); this.truncator = truncator; } @@ -63,7 +63,7 @@ TermsEnum termsEnum = terms.iterator(); boolean skip = false; - TermsEnum.SeekStatus status = termsEnum.seek(new TermRef(getPrefix())); + TermsEnum.SeekStatus status = termsEnum.seek(new BytesRef(getPrefix())); if (status == TermsEnum.SeekStatus.FOUND) { mtv.visitMatchingTerm(getLucenePrefixTerm(fieldName)); expanded = true; @@ -81,7 +81,7 @@ if (!skip) { while(true) { - TermRef text = termsEnum.next(); + BytesRef text = termsEnum.next(); if (text != null && text.startsWith(prefixRef)) { mtv.visitMatchingTerm(new Term(fieldName, text.toString())); expanded = true; Index: contrib/surround/src/java/org/apache/lucene/queryParser/surround/query/SrndTermQuery.java =================================================================== --- contrib/surround/src/java/org/apache/lucene/queryParser/surround/query/SrndTermQuery.java (revision 900009) +++ contrib/surround/src/java/org/apache/lucene/queryParser/surround/query/SrndTermQuery.java (working copy) @@ -22,7 +22,7 @@ import org.apache.lucene.index.Term; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.index.Terms; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; public class SrndTermQuery extends SimpleTerm { @@ -52,7 +52,7 @@ if (terms != null) { TermsEnum termsEnum = terms.iterator(); - TermsEnum.SeekStatus status = termsEnum.seek(new TermRef(getTermText())); + TermsEnum.SeekStatus status = termsEnum.seek(new BytesRef(getTermText())); if (status == TermsEnum.SeekStatus.FOUND) { mtv.visitMatchingTerm(getLuceneTerm(fieldName)); } else { Index: contrib/misc/src/java/org/apache/lucene/index/TermVectorAccessor.java =================================================================== --- contrib/misc/src/java/org/apache/lucene/index/TermVectorAccessor.java (revision 900009) +++ contrib/misc/src/java/org/apache/lucene/index/TermVectorAccessor.java (working copy) @@ -17,12 +17,11 @@ import org.apache.lucene.util.StringHelper; import org.apache.lucene.util.Bits; +import org.apache.lucene.util.BytesRef; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.Collection; -import java.util.Iterator; /** @@ -108,7 +107,7 @@ if (terms != null) { TermsEnum termsEnum = terms.iterator(); while(true) { - TermRef text = termsEnum.next(); + BytesRef text = termsEnum.next(); if (text != null) { anyTerms = true; DocsEnum docs = termsEnum.docs(delDocs); Index: contrib/misc/src/java/org/apache/lucene/misc/HighFreqTerms.java =================================================================== --- contrib/misc/src/java/org/apache/lucene/misc/HighFreqTerms.java (revision 900009) +++ contrib/misc/src/java/org/apache/lucene/misc/HighFreqTerms.java (working copy) @@ -18,10 +18,9 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.index.FieldsEnum; -import org.apache.lucene.index.Fields; import org.apache.lucene.index.Terms; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.PriorityQueue; @@ -60,7 +59,7 @@ if (terms != null) { TermsEnum termsEnum = terms.iterator(); while(true) { - TermRef term = termsEnum.next(); + BytesRef term = termsEnum.next(); if (term != null) { tiq.insertWithOverflow(new TermInfo(new Term(field, term.toString()), termsEnum.docFreq())); } else { @@ -75,7 +74,7 @@ if (field != null) { TermsEnum terms = fields.terms(); while(true) { - TermRef term = terms.next(); + BytesRef term = terms.next(); if (term != null) { tiq.insertWithOverflow(new TermInfo(new Term(field, term.toString()), terms.docFreq())); } else { Index: contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java =================================================================== --- contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java (revision 900009) +++ contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java (working copy) @@ -36,7 +36,7 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util._TestUtil; @@ -219,7 +219,7 @@ @Override public void setNextReader(IndexReader reader, int docBase) throws IOException { docValues = FieldCache.DEFAULT.getInts(reader, "parser", new FieldCache.IntParser() { - public final int parseInt(TermRef termRef) { + public final int parseInt(BytesRef termRef) { return (termRef.toString().charAt(0)-'A') * 123456; } }); Index: contrib/spellchecker/src/java/org/apache/lucene/search/spell/LuceneDictionary.java =================================================================== --- contrib/spellchecker/src/java/org/apache/lucene/search/spell/LuceneDictionary.java (revision 900009) +++ contrib/spellchecker/src/java/org/apache/lucene/search/spell/LuceneDictionary.java (working copy) @@ -22,9 +22,8 @@ import java.util.Iterator; import org.apache.lucene.index.TermsEnum; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.index.Terms; -import org.apache.lucene.index.Term; import org.apache.lucene.util.StringHelper; import java.io.*; @@ -55,8 +54,7 @@ final class LuceneIterator implements Iterator { private TermsEnum termsEnum; - private TermRef pendingTerm; - private boolean hasNextCalled; + private BytesRef pendingTerm; LuceneIterator() { try { Index: contrib/regex/src/java/org/apache/lucene/search/regex/RegexTermsEnum.java =================================================================== --- contrib/regex/src/java/org/apache/lucene/search/regex/RegexTermsEnum.java (revision 900009) +++ contrib/regex/src/java/org/apache/lucene/search/regex/RegexTermsEnum.java (working copy) @@ -20,8 +20,7 @@ import org.apache.lucene.search.FilteredTermsEnum; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; -import org.apache.lucene.index.Terms; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import java.io.IOException; @@ -38,7 +37,7 @@ public class RegexTermsEnum extends FilteredTermsEnum { private String pre = ""; private RegexCapabilities regexImpl; - private final TermRef prefixRef; + private final BytesRef prefixRef; public RegexTermsEnum(IndexReader reader, Term term, RegexCapabilities regexImpl) throws IOException { super(reader, term.field()); @@ -50,12 +49,12 @@ pre = regexImpl.prefix(); if (pre == null) pre = ""; - prefixRef = new TermRef(pre); + prefixRef = new BytesRef(pre); setInitialSeekTerm(prefixRef); } @Override - protected final AcceptStatus accept(TermRef term) { + protected final AcceptStatus accept(BytesRef term) { if (term.startsWith(prefixRef)) { return regexImpl.match(term.toString()) ? AcceptStatus.YES : AcceptStatus.NO; } else { Index: contrib/queries/src/java/org/apache/lucene/search/DuplicateFilter.java =================================================================== --- contrib/queries/src/java/org/apache/lucene/search/DuplicateFilter.java (revision 900009) +++ contrib/queries/src/java/org/apache/lucene/search/DuplicateFilter.java (working copy) @@ -16,11 +16,9 @@ * limitations under the License. */ import java.io.IOException; -import java.util.BitSet; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.index.Terms; import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.TermsEnum; @@ -90,7 +88,7 @@ if (terms != null) { TermsEnum termsEnum = terms.iterator(); while(true) { - TermRef currTerm = termsEnum.next(); + BytesRef currTerm = termsEnum.next(); if (currTerm == null) { break; } else { @@ -127,7 +125,7 @@ if (terms != null) { TermsEnum termsEnum = terms.iterator(); while(true) { - TermRef currTerm = termsEnum.next(); + BytesRef currTerm = termsEnum.next(); if (currTerm == null) { break; } else { Index: contrib/queries/src/java/org/apache/lucene/search/FuzzyLikeThisQuery.java =================================================================== --- contrib/queries/src/java/org/apache/lucene/search/FuzzyLikeThisQuery.java (revision 900009) +++ contrib/queries/src/java/org/apache/lucene/search/FuzzyLikeThisQuery.java (working copy) @@ -29,7 +29,7 @@ import org.apache.lucene.analysis.tokenattributes.TermAttribute; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.PriorityQueue; /** @@ -204,7 +204,7 @@ int df = reader.docFreq(startTerm); int numVariants=0; int totalVariantDocFreqs=0; - TermRef possibleMatch; + BytesRef possibleMatch; MultiTermQuery.BoostAttribute boostAtt = fe.attributes().addAttribute(MultiTermQuery.BoostAttribute.class); while ((possibleMatch = fe.next()) != null) { Index: backwards/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/search/TestSort.java =================================================================== --- backwards/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/search/TestSort.java (revision 899354) +++ backwards/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/search/TestSort.java (working copy) @@ -35,7 +35,7 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermRef; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.queryParser.ParseException; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.store.LockObtainFailedException; @@ -338,7 +338,7 @@ // dummy return 0; } - public final int parseInt(final TermRef term) { + public final int parseInt(final BytesRef term) { return (term.bytes[term.offset]-'A') * 123456; } }), SortField.FIELD_DOC); @@ -351,7 +351,7 @@ // dummy return 0; } - public final float parseFloat(final TermRef term) { + public final float parseFloat(final BytesRef term) { return (float) Math.sqrt( term.bytes[term.offset] ); } }), SortField.FIELD_DOC }); @@ -363,7 +363,7 @@ public final long parseLong(final String val) { return (val.charAt(0)-'A') * 1234567890L; } - public final long parseLong(final TermRef term) { + public final long parseLong(final BytesRef term) { return (term.bytes[term.offset]-'A') * 1234567890L; } }), SortField.FIELD_DOC); @@ -376,7 +376,7 @@ // dummy return 0; } - public final double parseDouble(final TermRef term) { + public final double parseDouble(final BytesRef term) { return Math.pow( term.bytes[term.offset], (term.bytes[term.offset]-'A') ); } }), SortField.FIELD_DOC }); @@ -389,7 +389,7 @@ // dummy return 0; } - public final byte parseByte(final TermRef term) { + public final byte parseByte(final BytesRef term) { return (byte) (term.bytes[term.offset]-'A'); } }), SortField.FIELD_DOC }); @@ -402,7 +402,7 @@ // dummy return 0; } - public final short parseShort(final TermRef term) { + public final short parseShort(final BytesRef term) { return (short) (term.bytes[term.offset]-'A'); } }), SortField.FIELD_DOC }); @@ -467,7 +467,7 @@ // dummy return 0; } - public final int parseInt(final TermRef term) { + public final int parseInt(final BytesRef term) { return (term.bytes[term.offset]-'A') * 123456; } });