lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h..@apache.org
Subject svn commit: r1493502 - in /lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs: ./ temp/
Date Sun, 16 Jun 2013 12:24:57 GMT
Author: han
Date: Sun Jun 16 12:24:57 2013
New Revision: 1493502

URL: http://svn.apache.org/r1493502
Log:
LUCENE-5029 simplify contract on generic long[]

Modified:
    lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/TempPostingsReaderBase.java
    lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/TempPostingsWriterBase.java
    lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempBlockTermsReader.java
    lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempBlockTermsWriter.java
    lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempPostingsReader.java
    lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempPostingsWriter.java

Modified: lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/TempPostingsReaderBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/TempPostingsReaderBase.java?rev=1493502&r1=1493501&r2=1493502&view=diff
==============================================================================
--- lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/TempPostingsReaderBase.java
(original)
+++ lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/TempPostingsReaderBase.java
Sun Jun 16 12:24:57 2013
@@ -58,10 +58,7 @@ public abstract class TempPostingsReader
 
   /** Actually decode metadata for next term */
   // nocommit: remove the 'fieldInfo' ? I suppose for a given postingsPBR, this should be
fixed?
-  public abstract void nextTerm(long[] longs, DataInput in, FieldInfo fieldInfo, TempTermState
state) throws IOException;
-
-  /** Return the fixed length of longs */
-  public abstract int longsSize(FieldInfo fieldInfo);
+  public abstract void decodeTerm(long[] longs, DataInput in, FieldInfo fieldInfo, TempTermState
state) throws IOException;
 
   /** Must fully consume state, since after this call that
    *  TermState may be reused. */

Modified: lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/TempPostingsWriterBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/TempPostingsWriterBase.java?rev=1493502&r1=1493501&r2=1493502&view=diff
==============================================================================
--- lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/TempPostingsWriterBase.java
(original)
+++ lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/TempPostingsWriterBase.java
Sun Jun 16 12:24:57 2013
@@ -61,7 +61,7 @@ public abstract class TempPostingsWriter
   public abstract void finishTerm(long[] longs, DataOutput out, TermStats stats) throws IOException;
 
   /** Return the fixed length of longs */
-  public abstract int longsSize(FieldInfo fieldInfo);
+  public abstract int longsSize();
 
   /** Called when the writing switches to another field. */
   public abstract void setField(FieldInfo fieldInfo);

Modified: lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempBlockTermsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempBlockTermsReader.java?rev=1493502&r1=1493501&r2=1493502&view=diff
==============================================================================
--- lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempBlockTermsReader.java
(original)
+++ lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempBlockTermsReader.java
Sun Jun 16 12:24:57 2013
@@ -166,6 +166,7 @@ public class TempBlockTermsReader extend
         final long sumTotalTermFreq = fieldInfo.getIndexOptions() == IndexOptions.DOCS_ONLY
? -1 : in.readVLong();
         final long sumDocFreq = in.readVLong();
         final int docCount = in.readVInt();
+        final int longsSize = in.readVInt();
         if (docCount < 0 || docCount > info.getDocCount()) { // #docs with field must
be <= #docs
           throw new CorruptIndexException("invalid docCount: " + docCount + " maxDoc: " +
info.getDocCount() + " (resource=" + in + ")");
         }
@@ -176,7 +177,7 @@ public class TempBlockTermsReader extend
           throw new CorruptIndexException("invalid sumTotalTermFreq: " + sumTotalTermFreq
+ " sumDocFreq: " + sumDocFreq + " (resource=" + in + ")");
         }
         final long indexStartFP = indexDivisor != -1 ? indexIn.readVLong() : 0;
-        FieldReader previous = fields.put(fieldInfo.name, new FieldReader(fieldInfo, numTerms,
rootCode, sumTotalTermFreq, sumDocFreq, docCount, indexStartFP, indexIn));
+        FieldReader previous = fields.put(fieldInfo.name, new FieldReader(fieldInfo, numTerms,
rootCode, sumTotalTermFreq, sumDocFreq, docCount, indexStartFP, longsSize, indexIn));
         if (previous != null) {
           throw new CorruptIndexException("duplicate field: " + fieldInfo.name + " (resource="
+ in + ")");
         }
@@ -458,11 +459,12 @@ public class TempBlockTermsReader extend
     final long indexStartFP;
     final long rootBlockFP;
     final BytesRef rootCode;
-    private final FST<BytesRef> index;
+    final int longsSize;
 
+    private final FST<BytesRef> index;
     //private boolean DEBUG;
 
-    FieldReader(FieldInfo fieldInfo, long numTerms, BytesRef rootCode, long sumTotalTermFreq,
long sumDocFreq, int docCount, long indexStartFP, IndexInput indexIn) throws IOException {
+    FieldReader(FieldInfo fieldInfo, long numTerms, BytesRef rootCode, long sumTotalTermFreq,
long sumDocFreq, int docCount, long indexStartFP, int longsSize, IndexInput indexIn) throws
IOException {
       assert numTerms > 0;
       this.fieldInfo = fieldInfo;
       //DEBUG = TempBlockTermsReader.DEBUG && fieldInfo.name.equals("id");
@@ -472,6 +474,7 @@ public class TempBlockTermsReader extend
       this.docCount = docCount;
       this.indexStartFP = indexStartFP;
       this.rootCode = rootCode;
+      this.longsSize = longsSize;
       // if (DEBUG) {
       //   System.out.println("BTTR: seg=" + segment + " field=" + fieldInfo.name + " rootBlockCode="
+ rootCode + " divisor=" + indexDivisor);
       // }
@@ -639,7 +642,7 @@ public class TempBlockTermsReader extend
           this.ord = ord;
           this.termState = postingsReader.newTermState();
           this.termState.totalTermFreq = -1;
-          this.longs = new long[postingsReader.longsSize(fieldInfo)];
+          this.longs = new long[longsSize];
         }
 
         void loadNextFloorBlock() throws IOException {
@@ -828,7 +831,7 @@ public class TempBlockTermsReader extend
             for (int i = 0; i < longSize; i++) {
               longs[i] += bytesReader.readVLong();
             }
-            postingsReader.nextTerm(longs, bytesReader, fieldInfo, termState);
+            postingsReader.decodeTerm(longs, bytesReader, fieldInfo, termState);
 
             metaDataUpto++;
           }
@@ -2332,7 +2335,7 @@ public class TempBlockTermsReader extend
           this.ord = ord;
           this.state = postingsReader.newTermState();
           this.state.totalTermFreq = -1;
-          this.longs = new long[postingsReader.longsSize(fieldInfo)];
+          this.longs = new long[longsSize];
         }
 
         public void setFloorData(ByteArrayDataInput in, BytesRef source) {
@@ -2652,7 +2655,7 @@ public class TempBlockTermsReader extend
             for (int i = 0; i < longSize; i++) {
               longs[i] += bytesReader.readVLong();
             }
-            postingsReader.nextTerm(longs, bytesReader, fieldInfo, state);
+            postingsReader.decodeTerm(longs, bytesReader, fieldInfo, state);
 
             metaDataUpto++;
           }

Modified: lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempBlockTermsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempBlockTermsWriter.java?rev=1493502&r1=1493501&r2=1493502&view=diff
==============================================================================
--- lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempBlockTermsWriter.java
(original)
+++ lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempBlockTermsWriter.java
Sun Jun 16 12:24:57 2013
@@ -244,8 +244,9 @@ public class TempBlockTermsWriter extend
     public final long sumTotalTermFreq;
     public final long sumDocFreq;
     public final int docCount;
+    private final int longsSize;
 
-    public FieldMetaData(FieldInfo fieldInfo, BytesRef rootCode, long numTerms, long indexStartFP,
long sumTotalTermFreq, long sumDocFreq, int docCount) {
+    public FieldMetaData(FieldInfo fieldInfo, BytesRef rootCode, long numTerms, long indexStartFP,
long sumTotalTermFreq, long sumDocFreq, int docCount, int longsSize) {
       assert numTerms > 0;
       this.fieldInfo = fieldInfo;
       assert rootCode != null: "field=" + fieldInfo.name + " numTerms=" + numTerms;
@@ -255,6 +256,7 @@ public class TempBlockTermsWriter extend
       this.sumTotalTermFreq = sumTotalTermFreq;
       this.sumDocFreq = sumDocFreq;
       this.docCount = docCount;
+      this.longsSize = longsSize;
     }
   }
 
@@ -981,18 +983,14 @@ public class TempBlockTermsWriter extend
       assert count <= start;
 
       final int limit = pendingMetaData.size() - start + count;
-      final int size = postingsWriter.longsSize(fieldInfo);
+      final int size = postingsWriter.longsSize();
 
       long[] lastLongs = new long[size];
       Arrays.fill(lastLongs, 0);
       for(int idx=limit-count; idx<limit; idx++) {
         PendingMetaData meta = pendingMetaData.get(idx);
         for (int pos = 0; pos < size; pos++) {
-          if (meta.longs[pos] < 0) {
-            // nocommit: this -1 padding is implicit (maybe we need javadocs, or better
-            // an API to tell PostingsBase that: every time you meet a 'don't care', just
put -1 on it?
-            meta.longs[pos] = lastLongs[pos];
-          }
+          assert meta.longs[pos] >= 0;
           bytesWriter3.writeVLong(meta.longs[pos] - lastLongs[pos]);
         }
         lastLongs = meta.longs;
@@ -1058,7 +1056,7 @@ public class TempBlockTermsWriter extend
 
       blockBuilder.add(Util.toIntsRef(text, scratchIntsRef), noOutputs.getNoOutput());
       PendingTerm term = new PendingTerm(BytesRef.deepCopyOf(text), stats);
-      PendingMetaData meta = new PendingMetaData(postingsWriter.longsSize(fieldInfo));
+      PendingMetaData meta = new PendingMetaData(postingsWriter.longsSize());
       pending.add(term);
       postingsWriter.finishTerm(meta.longs, meta.bytesWriter, stats);
       pendingMetaData.add(meta);
@@ -1100,7 +1098,8 @@ public class TempBlockTermsWriter extend
                                      indexStartFP,
                                      sumTotalTermFreq,
                                      sumDocFreq,
-                                     docCount));
+                                     docCount,
+                                     postingsWriter.longsSize()));
       } else {
         assert sumTotalTermFreq == 0 || fieldInfo.getIndexOptions() == IndexOptions.DOCS_ONLY
&& sumTotalTermFreq == -1;
         assert sumDocFreq == 0;
@@ -1134,6 +1133,7 @@ public class TempBlockTermsWriter extend
         }
         out.writeVLong(field.sumDocFreq);
         out.writeVInt(field.docCount);
+        out.writeVInt(field.longsSize);
         indexOut.writeVLong(field.indexStartFP);
       }
       writeTrailer(out, dirStart);

Modified: lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempPostingsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempPostingsReader.java?rev=1493502&r1=1493501&r2=1493502&view=diff
==============================================================================
--- lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempPostingsReader.java
(original)
+++ lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempPostingsReader.java
Sun Jun 16 12:24:57 2013
@@ -200,17 +200,7 @@ public final class TempPostingsReader ex
   }
 
   @Override
-  public int longsSize(FieldInfo fieldInfo) {
-    final boolean fieldHasPositions = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)
>= 0;
-    if (fieldHasPositions) {
-      return 3;
-    } else {
-      return 1;
-    }
-  }
-
-  @Override
-  public void nextTerm(long[] longs, DataInput in, FieldInfo fieldInfo, TempTermState _termState)
+  public void decodeTerm(long[] longs, DataInput in, FieldInfo fieldInfo, TempTermState _termState)
     throws IOException {
     final IntBlockTermState termState = (IntBlockTermState) _termState;
     final boolean fieldHasPositions = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)
>= 0;

Modified: lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempPostingsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempPostingsWriter.java?rev=1493502&r1=1493501&r2=1493502&view=diff
==============================================================================
--- lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempPostingsWriter.java
(original)
+++ lucene/dev/branches/lucene3069/lucene/core/src/java/org/apache/lucene/codecs/temp/TempPostingsWriter.java
Sun Jun 16 12:24:57 2013
@@ -348,7 +348,7 @@ public final class TempPostingsWriter ex
     }
   }
 
-  public int longsSize(FieldInfo info) {
+  public int longsSize() {
     if (fieldHasPositions) {
       return 3;  // doc + pos + pay FP
     } else {
@@ -494,12 +494,6 @@ public final class TempPostingsWriter ex
       // }
     }
 
-    long payStartFP;
-    if (stats.totalTermFreq >= BLOCK_SIZE) {
-      payStartFP = payTermStartFP;
-    } else {
-      payStartFP = -1;
-    }
     // if (DEBUG) {
     //   System.out.println("  payStartFP=" + payStartFP);
     // }
@@ -508,7 +502,7 @@ public final class TempPostingsWriter ex
     longs[0] = docTermStartFP;
     if (fieldHasPositions) {
       longs[1] = posTermStartFP;
-      longs[2] = payStartFP;
+      longs[2] = payTermStartFP;
     }
     if (singletonDocID != -1) {
       out.writeVInt(singletonDocID);



Mime
View raw message