From 48df915f8d7fea72f29d22cd1d7b726963844f4d Mon Sep 17 00:00:00 2001 From: Han Jiang Date: Sun, 16 Jun 2013 14:44:33 +0000 Subject: [PATCH] LUCENE-3069: setField now expose per-field info to term dict git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3069@1493517 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/codecs/temp/TempBlockTermsWriter.java | 14 +++++++------- .../lucene/codecs/temp/TempPostingsWriter.java | 15 ++++++--------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/codecs/temp/TempBlockTermsWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/temp/TempBlockTermsWriter.java index be724f46ce2..3c4feb42ac1 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/temp/TempBlockTermsWriter.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/temp/TempBlockTermsWriter.java @@ -496,6 +496,7 @@ public class TempBlockTermsWriter extends FieldsConsumer { class TermsWriter extends TermsConsumer { private final FieldInfo fieldInfo; + private final int longsSize; private long numTerms; long sumTotalTermFreq; long sumDocFreq; @@ -856,8 +857,7 @@ public class TempBlockTermsWriter extends FieldsConsumer { int termCount; - final int size = postingsWriter.longsSize(); - long[] lastLongs = new long[size]; + long[] lastLongs = new long[longsSize]; Arrays.fill(lastLongs, 0); if (isLeafBlock) { @@ -884,7 +884,7 @@ public class TempBlockTermsWriter extends FieldsConsumer { } // Write term meta data - for (int pos = 0; pos < size; pos++) { + for (int pos = 0; pos < longsSize; pos++) { assert term.longs[pos] >= 0; metaWriter.writeVLong(term.longs[pos] - lastLongs[pos]); } @@ -926,7 +926,7 @@ public class TempBlockTermsWriter extends FieldsConsumer { // separate anymore: // Write term meta data - for (int pos = 0; pos < size; pos++) { + for (int pos = 0; pos < longsSize; pos++) { assert term.longs[pos] >= 0; metaWriter.writeVLong(term.longs[pos] - lastLongs[pos]); } @@ -1014,7 +1014,7 @@ public class TempBlockTermsWriter extends FieldsConsumer { PackedInts.COMPACT, true, 15); - postingsWriter.setField(fieldInfo); + this.longsSize = postingsWriter.setField(fieldInfo); } @Override @@ -1046,7 +1046,7 @@ public class TempBlockTermsWriter extends FieldsConsumer { blockBuilder.add(Util.toIntsRef(text, scratchIntsRef), noOutputs.getNoOutput()); - long[] longs = new long[postingsWriter.longsSize()]; + long[] longs = new long[longsSize]; postingsWriter.finishTerm(longs, metaWriter, stats); byte[] bytes = new byte[(int)metaWriter.getFilePointer()]; metaWriter.writeTo(bytes, 0); @@ -1093,7 +1093,7 @@ public class TempBlockTermsWriter extends FieldsConsumer { sumTotalTermFreq, sumDocFreq, docCount, - postingsWriter.longsSize())); + longsSize)); } else { assert sumTotalTermFreq == 0 || fieldInfo.getIndexOptions() == IndexOptions.DOCS_ONLY && sumTotalTermFreq == -1; assert sumDocFreq == 0; diff --git a/lucene/core/src/java/org/apache/lucene/codecs/temp/TempPostingsWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/temp/TempPostingsWriter.java index 8b5ce68de71..109852a76f5 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/temp/TempPostingsWriter.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/temp/TempPostingsWriter.java @@ -198,13 +198,18 @@ public final class TempPostingsWriter extends TempPostingsWriterBase { // nocommit better name? @Override - public void setField(FieldInfo fieldInfo) { + public int setField(FieldInfo fieldInfo) { IndexOptions indexOptions = fieldInfo.getIndexOptions(); fieldHasFreqs = indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS) >= 0; fieldHasPositions = indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; fieldHasOffsets = indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; fieldHasPayloads = fieldInfo.hasPayloads(); skipWriter.setField(fieldHasPositions, fieldHasOffsets, fieldHasPayloads); + if (fieldHasPositions) { + return 3; // doc + pos + pay FP + } else { + return 1; // docFP + } } @Override @@ -350,14 +355,6 @@ public final class TempPostingsWriter extends TempPostingsWriterBase { } } - public int longsSize() { - if (fieldHasPositions) { - return 3; // doc + pos + pay FP - } else { - return 1; // docFP - } - } - // nocommit explain about the "don't care" values /** Called when we are done adding docs to this term */