diff --git a/lucene/src/java/org/apache/lucene/index/codecs/standard/SimpleStandardTermsIndexReader.java b/lucene/src/java/org/apache/lucene/index/codecs/standard/SimpleStandardTermsIndexReader.java index 4dde4f1d166..709e8d94151 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/standard/SimpleStandardTermsIndexReader.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/standard/SimpleStandardTermsIndexReader.java @@ -137,7 +137,7 @@ public class SimpleStandardTermsIndexReader extends StandardTermsIndexReader { if (success) { indexLoaded = true; } - termBytesReader = termBytes.freeze(); + termBytesReader = termBytes.freeze(true); } else { this.in = in; } @@ -413,7 +413,7 @@ public class SimpleStandardTermsIndexReader extends StandardTermsIndexReader { indexLoaded = true; in.close(); - termBytesReader = termBytes.freeze(); + termBytesReader = termBytes.freeze(true); } } diff --git a/lucene/src/java/org/apache/lucene/search/FieldCacheImpl.java b/lucene/src/java/org/apache/lucene/search/FieldCacheImpl.java index d85496e7fe5..3053c7b7960 100644 --- a/lucene/src/java/org/apache/lucene/search/FieldCacheImpl.java +++ b/lucene/src/java/org/apache/lucene/search/FieldCacheImpl.java @@ -866,7 +866,7 @@ class FieldCacheImpl implements FieldCache { } // maybe an int-only impl? - return new DocTermsIndexImpl(bytes.freeze(), termOrdToBytesOffset.getMutable(), docToTermOrd.getMutable(), termOrd); + return new DocTermsIndexImpl(bytes.freeze(true), termOrdToBytesOffset.getMutable(), docToTermOrd.getMutable(), termOrd); } } @@ -971,7 +971,7 @@ class FieldCacheImpl implements FieldCache { } // maybe an int-only impl? - return new DocTermsImpl(bytes.freeze(), docToOffset.getMutable()); + return new DocTermsImpl(bytes.freeze(true), docToOffset.getMutable()); } } private volatile PrintStream infoStream; diff --git a/lucene/src/java/org/apache/lucene/util/PagedBytes.java b/lucene/src/java/org/apache/lucene/util/PagedBytes.java index 40a40a19d32..1d830fde141 100644 --- a/lucene/src/java/org/apache/lucene/util/PagedBytes.java +++ b/lucene/src/java/org/apache/lucene/util/PagedBytes.java @@ -203,8 +203,33 @@ public final class PagedBytes { } } - /** Commits final byte[], trimming it if necessary. */ - public Reader freeze() { + /** Copy BytesRef in, setting BytesRef out to the result. + * Do not use this if you will use freeze(true). + * This only supports bytes.length <= blockSize */ + public void copy(BytesRef bytes, BytesRef out) throws IOException { + int left = blockSize - upto; + if (bytes.length > left) { + if (currentBlock != null) { + blocks.add(currentBlock); + blockEnd.add(upto); + } + currentBlock = new byte[blockSize]; + upto = 0; + left = blockSize; + assert bytes.length <= blockSize; + // TODO: we could also support variable block sizes + } + + out.bytes = currentBlock; + out.offset = upto; + out.length = bytes.length; + + System.arraycopy(bytes.bytes, bytes.offset, currentBlock, upto, bytes.length); + upto += bytes.length; + } + + /** Commits final byte[], trimming it if necessary and if trim=true */ + public Reader freeze(boolean trim) { if (upto < blockSize) { final byte[] newBlock = new byte[upto]; System.arraycopy(currentBlock, 0, newBlock, 0, upto); diff --git a/solr/src/java/org/apache/solr/request/UnInvertedField.java b/solr/src/java/org/apache/solr/request/UnInvertedField.java index 43bdf012c80..1c21eb19ac3 100755 --- a/solr/src/java/org/apache/solr/request/UnInvertedField.java +++ b/solr/src/java/org/apache/solr/request/UnInvertedField.java @@ -27,6 +27,7 @@ import org.apache.lucene.index.Terms; import org.apache.lucene.index.MultiFields; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TermRangeQuery; +import org.apache.lucene.util.PagedBytes; import org.apache.noggit.CharArr; import org.apache.solr.common.params.FacetParams; import org.apache.solr.common.util.NamedList; @@ -1097,6 +1098,7 @@ class TermIndex { NumberedTermsEnum getEnumerator(IndexReader reader) throws IOException { if (index==null) return new NumberedTermsEnum(reader,this, prefix==null?new BytesRef():prefix, 0) { ArrayList lst; + PagedBytes bytes; protected BytesRef setTerm() throws IOException { BytesRef br = super.setTerm(); @@ -1104,8 +1106,11 @@ class TermIndex { sizeOfStrings += br.length; if (lst==null) { lst = new ArrayList(); + bytes = new PagedBytes(15); } - lst.add(new BytesRef(br)); + BytesRef out = new BytesRef(); + bytes.copy(br, out); + lst.add(out); } return br; }