lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sim...@apache.org
Subject svn commit: r1143719 [9/20] - in /lucene/dev/branches/LUCENE2793: ./ dev-tools/eclipse/ dev-tools/idea/.idea/ dev-tools/idea/lucene/contrib/ dev-tools/idea/lucene/contrib/demo/ dev-tools/idea/lucene/contrib/highlighter/ dev-tools/idea/lucene/contrib/in...
Date Thu, 07 Jul 2011 09:04:29 GMT
Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java Thu Jul  7 09:03:58 2011
@@ -88,7 +88,7 @@ public class MultiPhraseQuery extends Qu
       field = terms[0].field();
 
     for (int i = 0; i < terms.length; i++) {
-      if (terms[i].field() != field) {
+      if (!terms[i].field().equals(field)) {
         throw new IllegalArgumentException(
             "All phrase terms must be in the same field (" + field + "): "
                 + terms[i]);
@@ -175,7 +175,7 @@ public class MultiPhraseQuery extends Qu
       if (termArrays.size() == 0)                  // optimize zero-term case
         return null;
       final IndexReader reader = context.reader;
-      final Bits delDocs = reader.getDeletedDocs();
+      final Bits liveDocs = reader.getLiveDocs();
       
       PhraseQuery.PostingsAndFreq[] postingsFreqs = new PhraseQuery.PostingsAndFreq[termArrays.size()];
 
@@ -196,12 +196,12 @@ public class MultiPhraseQuery extends Qu
           }
         } else {
           final Term term = terms[0];
-          postingsEnum = reader.termPositionsEnum(delDocs,
+          postingsEnum = reader.termPositionsEnum(liveDocs,
                                                   term.field(),
                                                   term.bytes());
 
           if (postingsEnum == null) {
-            if (reader.termDocsEnum(delDocs, term.field(), term.bytes()) != null) {
+            if (reader.termDocsEnum(liveDocs, term.field(), term.bytes()) != null) {
               // term does exist, but has no positions
               throw new IllegalStateException("field \"" + term.field() + "\" was indexed with Field.omitTermFreqAndPositions=true; cannot run PhraseQuery (term=" + term.text() + ")");
             } else {
@@ -497,15 +497,15 @@ class UnionDocsAndPositionsEnum extends 
 
   public UnionDocsAndPositionsEnum(IndexReader indexReader, Term[] terms) throws IOException {
     List<DocsAndPositionsEnum> docsEnums = new LinkedList<DocsAndPositionsEnum>();
-    final Bits delDocs = indexReader.getDeletedDocs();
+    final Bits liveDocs = indexReader.getLiveDocs();
     for (int i = 0; i < terms.length; i++) {
-      DocsAndPositionsEnum postings = indexReader.termPositionsEnum(delDocs,
+      DocsAndPositionsEnum postings = indexReader.termPositionsEnum(liveDocs,
                                                                     terms[i].field(),
                                                                     terms[i].bytes());
       if (postings != null) {
         docsEnums.add(postings);
       } else {
-        if (indexReader.termDocsEnum(delDocs, terms[i].field(), terms[i].bytes()) != null) {
+        if (indexReader.termDocsEnum(liveDocs, terms[i].field(), terms[i].bytes()) != null) {
           // term does exist, but has no positions
           throw new IllegalStateException("field \"" + terms[i].field() + "\" was indexed with Field.omitTermFreqAndPositions=true; cannot run PhraseQuery (term=" + terms[i].text() + ")");
         }

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/MultiTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/MultiTermQuery.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/MultiTermQuery.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/MultiTermQuery.java Thu Jul  7 09:03:58 2011
@@ -301,8 +301,13 @@ public abstract class MultiTermQuery ext
     numberOfTerms += inc;
   }
 
+  /**
+   * To rewrite to a simpler form, instead return a simpler
+   * enum from {@link #getTermsEnum(Terms, AttributeSource)}.  For example,
+   * to rewrite to a single term, return a {@link SingleTermsEnum}
+   */
   @Override
-  public Query rewrite(IndexReader reader) throws IOException {
+  public final Query rewrite(IndexReader reader) throws IOException {
     return rewriteMethod.rewrite(reader, this);
   }
 

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java Thu Jul  7 09:03:58 2011
@@ -19,14 +19,14 @@ package org.apache.lucene.search;
 
 import java.io.IOException;
 
+import org.apache.lucene.index.DocsEnum;
 import org.apache.lucene.index.Fields;
-import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
-import org.apache.lucene.index.DocsEnum;
-import org.apache.lucene.util.OpenBitSet;
 import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.OpenBitSet;
 
 /**
  * A wrapper for {@link MultiTermQuery}, that exposes its
@@ -123,15 +123,15 @@ public class MultiTermQueryWrapperFilter
     assert termsEnum != null;
     if (termsEnum.next() != null) {
       // fill into a OpenBitSet
-      final OpenBitSet bitSet = new OpenBitSet(context.reader.maxDoc());
+      final OpenBitSet bitSet = new OpenBitSet(reader.maxDoc());
       int termCount = 0;
-      final Bits delDocs = reader.getDeletedDocs();
+      final Bits liveDocs = reader.getLiveDocs();
       DocsEnum docsEnum = null;
       do {
         termCount++;
         // System.out.println("  iter termCount=" + termCount + " term=" +
         // enumerator.term().toBytesString());
-        docsEnum = termsEnum.docs(delDocs, docsEnum);
+        docsEnum = termsEnum.docs(liveDocs, docsEnum);
         final DocsEnum.BulkReadResult result = docsEnum.getBulkResult();
         while (true) {
           final int count = docsEnum.read();

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/PhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/PhraseQuery.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/PhraseQuery.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/PhraseQuery.java Thu Jul  7 09:03:58 2011
@@ -85,14 +85,15 @@ public class PhraseQuery extends Query {
    * @param position
    */
   public void add(Term term, int position) {
-      if (terms.size() == 0)
-          field = term.field();
-      else if (term.field() != field)
-          throw new IllegalArgumentException("All phrase terms must be in the same field: " + term);
-
-      terms.add(term);
-      positions.add(Integer.valueOf(position));
-      if (position > maxPosition) maxPosition = position;
+    if (terms.size() == 0) {
+      field = term.field();
+    } else if (!term.field().equals(field)) {
+      throw new IllegalArgumentException("All phrase terms must be in the same field: " + term);
+    }
+
+    terms.add(term);
+    positions.add(Integer.valueOf(position));
+    if (position > maxPosition) maxPosition = position;
   }
 
   /** Returns the set of terms in this phrase. */
@@ -211,17 +212,17 @@ public class PhraseQuery extends Query {
       if (terms.size() == 0)			  // optimize zero-term case
         return null;
       final IndexReader reader = context.reader;
+      final Bits liveDocs = reader.getLiveDocs();
       PostingsAndFreq[] postingsFreqs = new PostingsAndFreq[terms.size()];
-      final Bits delDocs = reader.getDeletedDocs();
       for (int i = 0; i < terms.size(); i++) {
         final Term t = terms.get(i);
-        DocsAndPositionsEnum postingsEnum = reader.termPositionsEnum(delDocs,
+        DocsAndPositionsEnum postingsEnum = reader.termPositionsEnum(liveDocs,
                                                                      t.field(),
                                                                      t.bytes());
         // PhraseQuery on a field that did not index
         // positions.
         if (postingsEnum == null) {
-          if (reader.termDocsEnum(delDocs, t.field(), t.bytes()) != null) {
+          if (reader.termDocsEnum(liveDocs, t.field(), t.bytes()) != null) {
             // term does exist, but has no positions
             throw new IllegalStateException("field \"" + t.field() + "\" was indexed with Field.omitTermFreqAndPositions=true; cannot run PhraseQuery (term=" + t.text() + ")");
           } else {

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/Query.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/Query.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/Query.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/Query.java Thu Jul  7 09:03:58 2011
@@ -88,7 +88,7 @@ public abstract class Query implements C
    * Only implemented by primitive queries, which re-write to themselves.
    */
   public Weight createWeight(IndexSearcher searcher) throws IOException {
-    throw new UnsupportedOperationException();
+    throw new UnsupportedOperationException("Query " + this + " does not implement createWeight");
   }
 
   /** Expert: called to re-write queries into primitive queries. For example,

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/ScoringRewrite.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/ScoringRewrite.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/ScoringRewrite.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/ScoringRewrite.java Thu Jul  7 09:03:58 2011
@@ -113,7 +113,6 @@ public abstract class ScoringRewrite<Q e
     final ParallelArraysTermCollector col = new ParallelArraysTermCollector();
     collectTerms(reader, query, col);
     
-    final Term placeholderTerm = new Term(query.field);
     final int size = col.terms.size();
     if (size > 0) {
       final int sort[] = col.terms.sort(col.termsEnum.getComparator());
@@ -121,7 +120,7 @@ public abstract class ScoringRewrite<Q e
       final PerReaderTermState[] termStates = col.array.termState;
       for (int i = 0; i < size; i++) {
         final int pos = sort[i];
-        final Term term = placeholderTerm.createTerm(col.terms.get(pos, new BytesRef()));
+        final Term term = new Term(query.getField(), col.terms.get(pos, new BytesRef()));
         assert reader.docFreq(term) == termStates[pos].docFreq();
         addClause(result, term, termStates[pos].docFreq(), query.getBoost() * boost[pos], termStates[pos]);
       }

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/SortField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/SortField.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/SortField.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/SortField.java Thu Jul  7 09:03:58 2011
@@ -21,8 +21,8 @@ import java.io.IOException;
 import java.util.Comparator;
 
 import org.apache.lucene.search.cache.*;
-import org.apache.lucene.util.StringHelper;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.StringHelper;
 
 // TODO(simonw) -- for cleaner transition, maybe we should make
 // a new SortField that subclasses this one and always uses
@@ -39,69 +39,70 @@ import org.apache.lucene.util.BytesRef;
  */
 public class SortField {
 
-  /** Sort by document score (relevance).  Sort values are Float and higher
-   * values are at the front. */
-  public static final int SCORE = 0;
-
-  /** Sort by document number (index order).  Sort values are Integer and lower
-   * values are at the front. */
-  public static final int DOC = 1;
-
-  // reserved, in Lucene 2.9, there was a constant: AUTO = 2;
-
-  /** Sort using term values as Strings.  Sort values are String and lower
-   * values are at the front. */
-  public static final int STRING = 3;
-
-  /** Sort using term values as encoded Integers.  Sort values are Integer and
-   * lower values are at the front. */
-  public static final int INT = 4;
-
-  /** Sort using term values as encoded Floats.  Sort values are Float and
-   * lower values are at the front. */
-  public static final int FLOAT = 5;
-
-  /** Sort using term values as encoded Longs.  Sort values are Long and
-   * lower values are at the front. */
-  public static final int LONG = 6;
-
-  /** Sort using term values as encoded Doubles.  Sort values are Double and
-   * lower values are at the front. */
-  public static final int DOUBLE = 7;
-
-  /** Sort using term values as encoded Shorts.  Sort values are Short and
-   * lower values are at the front. */
-  public static final int SHORT = 8;
-
-  /** Sort using a custom Comparator.  Sort values are any Comparable and
-   * sorting is done according to natural order. */
-  public static final int CUSTOM = 9;
-
-  /** Sort using term values as encoded Bytes.  Sort values are Byte and
-   * lower values are at the front. */
-  public static final int BYTE = 10;
-  
-  /** Sort using term values as Strings, but comparing by
-   * value (using String.compareTo) for all comparisons.
-   * This is typically slower than {@link #STRING}, which
-   * uses ordinals to do the sorting. */
-  public static final int STRING_VAL = 11;
-
-  /** Sort use byte[] index values. */
-  public static final int BYTES = 12;
-
-  /** Force rewriting of SortField using {@link SortField#rewrite(IndexSearcher)}
-   * before it can be used for sorting */
-  public static final int REWRITEABLE = 13;
+  public static enum Type {
+
+    /** Sort by document score (relevance).  Sort values are Float and higher
+     * values are at the front. */
+    SCORE,
+
+    /** Sort by document number (index order).  Sort values are Integer and lower
+     * values are at the front. */
+    DOC,
+
+    /** Sort using term values as Strings.  Sort values are String and lower
+     * values are at the front. */
+    STRING,
+
+    /** Sort using term values as encoded Integers.  Sort values are Integer and
+     * lower values are at the front. */
+    INT,
+
+    /** Sort using term values as encoded Floats.  Sort values are Float and
+     * lower values are at the front. */
+    FLOAT,
+
+    /** Sort using term values as encoded Longs.  Sort values are Long and
+     * lower values are at the front. */
+    LONG,
+
+    /** Sort using term values as encoded Doubles.  Sort values are Double and
+     * lower values are at the front. */
+    DOUBLE,
+
+    /** Sort using term values as encoded Shorts.  Sort values are Short and
+     * lower values are at the front. */
+    SHORT,
+
+    /** Sort using a custom Comparator.  Sort values are any Comparable and
+     * sorting is done according to natural order. */
+    CUSTOM,
+
+    /** Sort using term values as encoded Bytes.  Sort values are Byte and
+     * lower values are at the front. */
+    BYTE,
+
+    /** Sort using term values as Strings, but comparing by
+     * value (using String.compareTo) for all comparisons.
+     * This is typically slower than {@link #STRING}, which
+     * uses ordinals to do the sorting. */
+    STRING_VAL,
+
+    /** Sort use byte[] index values. */
+    BYTES,
+
+    /** Force rewriting of SortField using {@link SortField#rewrite(IndexSearcher)}
+     * before it can be used for sorting */
+    REWRITEABLE
+  }
 
   /** Represents sorting by document score (relevance). */
-  public static final SortField FIELD_SCORE = new SortField(null, SCORE);
+  public static final SortField FIELD_SCORE = new SortField(null, Type.SCORE);
 
   /** Represents sorting by document number (index order). */
-  public static final SortField FIELD_DOC = new SortField(null, DOC);
+  public static final SortField FIELD_DOC = new SortField(null, Type.DOC);
 
   private String field;
-  private int type;  // defaults to determining type dynamically
+  private Type type;  // defaults to determining type dynamically
   boolean reverse = false;  // defaults to natural order
   private CachedArrayCreator<?> creator;
   public Object missingValue = null; // used for 'sortMissingFirst/Last'
@@ -115,7 +116,7 @@ public class SortField {
    *               <code>type</code> is SCORE or DOC.
    * @param type   Type of values in the terms.
    */
-  public SortField(String field, int type) {
+  public SortField(String field, Type type) {
     initFieldType(field, type);
   }
 
@@ -126,7 +127,7 @@ public class SortField {
    * @param type   Type of values in the terms.
    * @param reverse True if natural order should be reversed.
    */
-  public SortField(String field, int type, boolean reverse) {
+  public SortField(String field, Type type, boolean reverse) {
     initFieldType(field, type);
     this.reverse = reverse;
   }
@@ -166,36 +167,31 @@ public class SortField {
     if (field == null) {
       throw new IllegalArgumentException("field can only be null when type is SCORE or DOC");
     } 
-    this.field = StringHelper.intern(field);
+    this.field = field;
     this.reverse = reverse;
     
     if (parser instanceof FieldCache.IntParser) {
-      this.type = INT;
       this.creator = new IntValuesCreator( field, (FieldCache.IntParser)parser );
     }
     else if (parser instanceof FieldCache.FloatParser) {
-      this.type = FLOAT;
       this.creator = new FloatValuesCreator( field, (FieldCache.FloatParser)parser );
     }
     else if (parser instanceof FieldCache.ShortParser) {
-      this.type = SHORT;
       this.creator = new ShortValuesCreator( field, (FieldCache.ShortParser)parser );
     }
     else if (parser instanceof FieldCache.ByteParser) {
-      this.type = BYTE;
       this.creator = new ByteValuesCreator( field, (FieldCache.ByteParser)parser );
     }
     else if (parser instanceof FieldCache.LongParser) {
-      this.type = LONG;
       this.creator = new LongValuesCreator( field, (FieldCache.LongParser)parser );
     }
     else if (parser instanceof FieldCache.DoubleParser) {
-      this.type = DOUBLE;
       this.creator = new DoubleValuesCreator( field, (FieldCache.DoubleParser)parser );
     }
     else
       throw new IllegalArgumentException("Parser instance does not subclass existing numeric parser from FieldCache (got " + parser + ")");
 
+    this.type = this.creator.getSortType();
   }
   
   /**
@@ -205,10 +201,10 @@ public class SortField {
    */
   public SortField( CachedArrayCreator<?> creator, boolean reverse ) 
   {
-    this.field = StringHelper.intern(creator.field);
+    this.field = creator.field;
     this.reverse = reverse;
     this.creator = creator;
-    this.type = creator.getSortTypeID();
+    this.type = creator.getSortType();
   }
   
   public SortField setMissingValue( Object v )
@@ -230,7 +226,7 @@ public class SortField {
    * @param comparator Returns a comparator for sorting hits.
    */
   public SortField(String field, FieldComparatorSource comparator) {
-    initFieldType(field, CUSTOM);
+    initFieldType(field, Type.CUSTOM);
     this.comparatorSource = comparator;
   }
 
@@ -240,20 +236,20 @@ public class SortField {
    * @param reverse True if natural order should be reversed.
    */
   public SortField(String field, FieldComparatorSource comparator, boolean reverse) {
-    initFieldType(field, CUSTOM);
+    initFieldType(field, Type.CUSTOM);
     this.reverse = reverse;
     this.comparatorSource = comparator;
   }
 
   // Sets field & type, and ensures field is not NULL unless
   // type is SCORE or DOC
-  private void initFieldType(String field, int type) {
+  private void initFieldType(String field, Type type) {
     this.type = type;
     if (field == null) {
-      if (type != SCORE && type != DOC)
+      if (type != Type.SCORE && type != Type.DOC)
         throw new IllegalArgumentException("field can only be null when type is SCORE or DOC");
     } else {
-      this.field = StringHelper.intern(field);
+      this.field = field;
     }
     
     if( creator != null ) {
@@ -280,7 +276,7 @@ public class SortField {
   /** Returns the type of contents in the field.
    * @return One of the constants SCORE, DOC, STRING, INT or FLOAT.
    */
-  public int getType() {
+  public Type getType() {
     return type;
   }
 
@@ -359,6 +355,10 @@ public class SortField {
       case CUSTOM:
         buffer.append("<custom:\"").append(field).append("\": ").append(comparatorSource).append('>');
         break;
+      
+      case REWRITEABLE:
+        buffer.append("<rewriteable: \"").append(field).append("\">");
+        break;
 
       default:
         buffer.append("<???: \"").append(field).append("\">");
@@ -381,7 +381,7 @@ public class SortField {
     if (!(o instanceof SortField)) return false;
     final SortField other = (SortField)o;
     return (
-      other.field == this.field // field is always interned
+      StringHelper.equals(other.field, this.field)
       && other.type == this.type
       && other.reverse == this.reverse
       && (other.comparatorSource == null ? this.comparatorSource == null : other.comparatorSource.equals(this.comparatorSource))
@@ -396,7 +396,7 @@ public class SortField {
    *  used). */
   @Override
   public int hashCode() {
-    int hash=type^0x346565dd + Boolean.valueOf(reverse).hashCode()^0xaf5998bb;
+    int hash = type.hashCode() ^ 0x346565dd + Boolean.valueOf(reverse).hashCode() ^ 0xaf5998bb;
     if (field != null) hash += field.hashCode()^0xff5685dd;
     if (comparatorSource != null) hash += comparatorSource.hashCode();
     if (creator != null) hash += creator.hashCode()^0x3aaf56ff;
@@ -438,49 +438,49 @@ public class SortField {
   public FieldComparator getComparator(final int numHits, final int sortPos) throws IOException {
 
     switch (type) {
-    case SortField.SCORE:
+    case SCORE:
       return new FieldComparator.RelevanceComparator(numHits);
 
-    case SortField.DOC:
+    case DOC:
       return new FieldComparator.DocComparator(numHits);
 
-    case SortField.INT:
+    case INT:
       if (useIndexValues) {
         return new FieldComparator.IntDocValuesComparator(numHits, field);
       } else {
         return new FieldComparator.IntComparator(numHits, (IntValuesCreator)creator, (Integer) missingValue);
       }
 
-    case SortField.FLOAT:
+    case FLOAT:
       if (useIndexValues) {
         return new FieldComparator.FloatDocValuesComparator(numHits, field);
       } else {
         return new FieldComparator.FloatComparator(numHits, (FloatValuesCreator) creator, (Float) missingValue);
       }
 
-    case SortField.LONG:
+    case LONG:
       return new FieldComparator.LongComparator(numHits, (LongValuesCreator)creator, (Long)missingValue );
 
-    case SortField.DOUBLE:
+    case DOUBLE:
       return new FieldComparator.DoubleComparator(numHits, (DoubleValuesCreator)creator, (Double)missingValue );
 
-    case SortField.BYTE:
+    case BYTE:
       return new FieldComparator.ByteComparator(numHits, (ByteValuesCreator)creator, (Byte)missingValue );
 
-    case SortField.SHORT:
+    case SHORT:
       return new FieldComparator.ShortComparator(numHits, (ShortValuesCreator)creator, (Short)missingValue );
 
-    case SortField.CUSTOM:
+    case CUSTOM:
       assert comparatorSource != null;
       return comparatorSource.newComparator(field, numHits, sortPos, reverse);
 
-    case SortField.STRING:
+    case STRING:
       return new FieldComparator.TermOrdValComparator(numHits, field, sortPos, reverse);
 
-    case SortField.STRING_VAL:
+    case STRING_VAL:
       return new FieldComparator.TermValComparator(numHits, field);
 
-    case SortField.REWRITEABLE:
+    case REWRITEABLE:
       throw new IllegalStateException("SortField needs to be rewritten through Sort.rewrite(..) and SortField.rewrite(..)");
         
     default:
@@ -491,7 +491,7 @@ public class SortField {
   /**
    * Rewrites this SortField, returning a new SortField if a change is made.
    * Subclasses should override this define their rewriting behavior when this
-   * SortField is of type {@link SortField#REWRITEABLE}
+   * SortField is of type {@link SortField.Type#REWRITEABLE}
    *
    * @param searcher IndexSearcher to use during rewriting
    * @return New rewritten SortField, or {@code this} if nothing has changed.

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/TermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/TermQuery.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/TermQuery.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/TermQuery.java Thu Jul  7 09:03:58 2011
@@ -90,13 +90,12 @@ public class TermQuery extends Query {
       final String field = term.field();
       final IndexReader reader = context.reader;
       assert termStates.topReaderContext == ReaderUtil.getTopLevelContext(context) : "The top-reader used to create Weight (" + termStates.topReaderContext + ") is not the same as the current reader's top-reader (" + ReaderUtil.getTopLevelContext(context);
-      final TermState state = termStates
-          .get(context.ord);
+      final TermState state = termStates.get(context.ord);
       if (state == null) { // term is not present in that reader
         assert termNotInReader(reader, field, term.bytes()) : "no termstate found but term exists in reader";
         return null;
       }
-      final DocsEnum docs = reader.termDocsEnum(reader.getDeletedDocs(), field, term.bytes(), state);
+      final DocsEnum docs = reader.termDocsEnum(reader.getLiveDocs(), field, term.bytes(), state);
       assert docs != null;
       return new TermScorer(this, docs, similarity, context.reader.norms(field));
     }
@@ -143,7 +142,7 @@ public class TermQuery extends Query {
 
       Explanation tfExplanation = new Explanation();
       int tf = 0;
-      DocsEnum docs = reader.termDocsEnum(reader.getDeletedDocs(), term.field(), term.bytes());
+      DocsEnum docs = reader.termDocsEnum(context.reader.getLiveDocs(), term.field(), term.bytes());
       if (docs != null) {
           int newDoc = docs.advance(doc);
           if (newDoc == doc) {

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/TopDocs.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/TopDocs.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/TopDocs.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/TopDocs.java Thu Jul  7 09:03:58 2011
@@ -212,18 +212,20 @@ public class TopDocs {
     }
 
     int totalHitCount = 0;
+    int availHitCount = 0;
     float maxScore = Float.MIN_VALUE;
     for(int shardIDX=0;shardIDX<shardHits.length;shardIDX++) {
       final TopDocs shard = shardHits[shardIDX];
       if (shard.scoreDocs != null && shard.scoreDocs.length > 0) {
         totalHitCount += shard.totalHits;
+        availHitCount += shard.scoreDocs.length;
         queue.add(new ShardRef(shardIDX));
         maxScore = Math.max(maxScore, shard.getMaxScore());
         //System.out.println("  maxScore now " + maxScore + " vs " + shard.getMaxScore());
       }
     }
 
-    final ScoreDoc[] hits = new ScoreDoc[Math.min(topN, totalHitCount)];
+    final ScoreDoc[] hits = new ScoreDoc[Math.min(topN, availHitCount)];
 
     int hitUpto = 0;
     while(hitUpto < hits.length) {

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/TopFieldCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/TopFieldCollector.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/TopFieldCollector.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/TopFieldCollector.java Thu Jul  7 09:03:58 2011
@@ -48,9 +48,9 @@ public abstract class TopFieldCollector 
 
     FieldComparator comparator;
     final int reverseMul;
-    final FieldValueHitQueue queue;
+    final FieldValueHitQueue<Entry> queue;
     
-    public OneComparatorNonScoringCollector(FieldValueHitQueue queue,
+    public OneComparatorNonScoringCollector(FieldValueHitQueue<Entry> queue,
         int numHits, boolean fillFields) throws IOException {
       super(queue, numHits, fillFields);
       this.queue = queue;
@@ -113,7 +113,7 @@ public abstract class TopFieldCollector 
   private static class OutOfOrderOneComparatorNonScoringCollector extends
       OneComparatorNonScoringCollector {
 
-    public OutOfOrderOneComparatorNonScoringCollector(FieldValueHitQueue queue,
+    public OutOfOrderOneComparatorNonScoringCollector(FieldValueHitQueue<Entry> queue,
         int numHits, boolean fillFields) throws IOException {
       super(queue, numHits, fillFields);
     }
@@ -160,7 +160,7 @@ public abstract class TopFieldCollector 
 
     Scorer scorer;
 
-    public OneComparatorScoringNoMaxScoreCollector(FieldValueHitQueue queue,
+    public OneComparatorScoringNoMaxScoreCollector(FieldValueHitQueue<Entry> queue,
         int numHits, boolean fillFields) throws IOException {
       super(queue, numHits, fillFields);
     }
@@ -221,7 +221,7 @@ public abstract class TopFieldCollector 
       OneComparatorScoringNoMaxScoreCollector {
 
     public OutOfOrderOneComparatorScoringNoMaxScoreCollector(
-        FieldValueHitQueue queue, int numHits, boolean fillFields)
+        FieldValueHitQueue<Entry> queue, int numHits, boolean fillFields)
         throws IOException {
       super(queue, numHits, fillFields);
     }
@@ -274,7 +274,7 @@ public abstract class TopFieldCollector 
 
     Scorer scorer;
     
-    public OneComparatorScoringMaxScoreCollector(FieldValueHitQueue queue,
+    public OneComparatorScoringMaxScoreCollector(FieldValueHitQueue<Entry> queue,
         int numHits, boolean fillFields) throws IOException {
       super(queue, numHits, fillFields);
       // Must set maxScore to NEG_INF, or otherwise Math.max always returns NaN.
@@ -334,7 +334,7 @@ public abstract class TopFieldCollector 
   private static class OutOfOrderOneComparatorScoringMaxScoreCollector extends
       OneComparatorScoringMaxScoreCollector {
 
-    public OutOfOrderOneComparatorScoringMaxScoreCollector(FieldValueHitQueue queue,
+    public OutOfOrderOneComparatorScoringMaxScoreCollector(FieldValueHitQueue<Entry> queue,
         int numHits, boolean fillFields) throws IOException {
       super(queue, numHits, fillFields);
     }
@@ -384,8 +384,8 @@ public abstract class TopFieldCollector 
     
     final FieldComparator[] comparators;
     final int[] reverseMul;
-    final FieldValueHitQueue queue;
-    public MultiComparatorNonScoringCollector(FieldValueHitQueue queue,
+    final FieldValueHitQueue<Entry> queue;
+    public MultiComparatorNonScoringCollector(FieldValueHitQueue<Entry> queue,
         int numHits, boolean fillFields) throws IOException {
       super(queue, numHits, fillFields);
       this.queue = queue;
@@ -471,7 +471,7 @@ public abstract class TopFieldCollector 
   private static class OutOfOrderMultiComparatorNonScoringCollector extends
       MultiComparatorNonScoringCollector {
     
-    public OutOfOrderMultiComparatorNonScoringCollector(FieldValueHitQueue queue,
+    public OutOfOrderMultiComparatorNonScoringCollector(FieldValueHitQueue<Entry> queue,
         int numHits, boolean fillFields) throws IOException {
       super(queue, numHits, fillFields);
     }
@@ -540,7 +540,7 @@ public abstract class TopFieldCollector 
     
     Scorer scorer;
     
-    public MultiComparatorScoringMaxScoreCollector(FieldValueHitQueue queue,
+    public MultiComparatorScoringMaxScoreCollector(FieldValueHitQueue<Entry> queue,
         int numHits, boolean fillFields) throws IOException {
       super(queue, numHits, fillFields);
       // Must set maxScore to NEG_INF, or otherwise Math.max always returns NaN.
@@ -619,7 +619,7 @@ public abstract class TopFieldCollector 
   private final static class OutOfOrderMultiComparatorScoringMaxScoreCollector
       extends MultiComparatorScoringMaxScoreCollector {
     
-    public OutOfOrderMultiComparatorScoringMaxScoreCollector(FieldValueHitQueue queue,
+    public OutOfOrderMultiComparatorScoringMaxScoreCollector(FieldValueHitQueue<Entry> queue,
         int numHits, boolean fillFields) throws IOException {
       super(queue, numHits, fillFields);
     }
@@ -692,7 +692,7 @@ public abstract class TopFieldCollector 
     
     Scorer scorer;
     
-    public MultiComparatorScoringNoMaxScoreCollector(FieldValueHitQueue queue,
+    public MultiComparatorScoringNoMaxScoreCollector(FieldValueHitQueue<Entry> queue,
         int numHits, boolean fillFields) throws IOException {
       super(queue, numHits, fillFields);
     }
@@ -771,7 +771,7 @@ public abstract class TopFieldCollector 
       extends MultiComparatorScoringNoMaxScoreCollector {
     
     public OutOfOrderMultiComparatorScoringNoMaxScoreCollector(
-        FieldValueHitQueue queue, int numHits, boolean fillFields)
+        FieldValueHitQueue<Entry> queue, int numHits, boolean fillFields)
         throws IOException {
       super(queue, numHits, fillFields);
     }
@@ -917,7 +917,7 @@ public abstract class TopFieldCollector 
       throw new IllegalArgumentException("numHits must be > 0; please use TotalHitCountCollector if you just need the total hit count");
     }
 
-    FieldValueHitQueue queue = FieldValueHitQueue.create(sort.fields, numHits);
+    FieldValueHitQueue<Entry> queue = FieldValueHitQueue.create(sort.fields, numHits);
     if (queue.getComparators().length == 1) {
       if (docsScoredInOrder) {
         if (trackMaxScore) {
@@ -972,7 +972,7 @@ public abstract class TopFieldCollector 
   protected void populateResults(ScoreDoc[] results, int howMany) {
     if (fillFields) {
       // avoid casting if unnecessary.
-      FieldValueHitQueue queue = (FieldValueHitQueue) pq;
+      FieldValueHitQueue<Entry> queue = (FieldValueHitQueue<Entry>) pq;
       for (int i = howMany - 1; i >= 0; i--) {
         results[i] = queue.fillFields(queue.pop());
       }
@@ -993,12 +993,11 @@ public abstract class TopFieldCollector 
     }
 
     // If this is a maxScoring tracking collector and there were no results, 
-    return new TopFieldDocs(totalHits, results, ((FieldValueHitQueue) pq).getFields(), maxScore);
+    return new TopFieldDocs(totalHits, results, ((FieldValueHitQueue<Entry>) pq).getFields(), maxScore);
   }
   
   @Override
   public boolean acceptsDocsOutOfOrder() {
     return false;
   }
-
 }

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/TopTermsRewrite.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/TopTermsRewrite.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/TopTermsRewrite.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/TopTermsRewrite.java Thu Jul  7 09:03:58 2011
@@ -131,12 +131,11 @@ public abstract class TopTermsRewrite<Q 
       }
     });
     
-    final Term placeholderTerm = new Term(query.field);
     final Q q = getTopLevelQuery();
     final ScoreTerm[] scoreTerms = stQueue.toArray(new ScoreTerm[stQueue.size()]);
     ArrayUtil.mergeSort(scoreTerms, scoreTermSortByTermComp);
     for (final ScoreTerm st : scoreTerms) {
-      final Term term = placeholderTerm.createTerm(st.bytes);
+      final Term term = new Term(query.field, st.bytes);
       assert reader.docFreq(term) == st.termState.docFreq() : "reader DF is " + reader.docFreq(term) + " vs " + st.termState.docFreq();
       addClause(q, term, st.termState.docFreq(), query.getBoost() * st.boost, st.termState); // add to query
     }

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/ByteValuesCreator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/ByteValuesCreator.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/ByteValuesCreator.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/ByteValuesCreator.java Thu Jul  7 09:03:58 2011
@@ -61,8 +61,8 @@ public class ByteValuesCreator extends C
   }
   
   @Override
-  public int getSortTypeID() {
-    return SortField.BYTE;
+  public SortField.Type getSortType() {
+    return SortField.Type.BYTE;
   }
 
   //--------------------------------------------------------------------------------
@@ -143,4 +143,4 @@ public class ByteValuesCreator extends C
       vals.valid = new Bits.MatchNoBits( maxDoc );
     }
   }
-}
\ No newline at end of file
+}

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/CachedArrayCreator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/CachedArrayCreator.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/CachedArrayCreator.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/CachedArrayCreator.java Thu Jul  7 09:03:58 2011
@@ -26,6 +26,7 @@ import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.FieldCache.Parser;
+import org.apache.lucene.search.SortField;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.OpenBitSet;
@@ -73,7 +74,7 @@ public abstract class CachedArrayCreator
   /** Return the type that the array will hold */
   public abstract Class getArrayType();
   public abstract Parser getParser();
-  public abstract int getSortTypeID();
+  public abstract SortField.Type getSortType();
 
   protected void setParserAndResetCounts(T value, Parser parser)
   {

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/DocTermsCreator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/DocTermsCreator.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/DocTermsCreator.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/DocTermsCreator.java Thu Jul  7 09:03:58 2011
@@ -29,7 +29,6 @@ import org.apache.lucene.search.FieldCac
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.PagedBytes;
-import org.apache.lucene.util.StringHelper;
 import org.apache.lucene.util.packed.GrowableWriter;
 import org.apache.lucene.util.packed.PackedInts;
 
@@ -66,7 +65,6 @@ public class DocTermsCreator extends Ent
   @Override
   public DocTerms create(IndexReader reader) throws IOException {
 
-    String field = StringHelper.intern(this.field); // TODO?? necessary?
     Terms terms = MultiFields.getTerms(reader, field);
 
     final boolean fasterButMoreRAM = hasOption( FASTER_BUT_MORE_RAM );
@@ -107,7 +105,7 @@ public class DocTermsCreator extends Ent
     if (terms != null) {
       int termCount = 0;
       final TermsEnum termsEnum = terms.iterator();
-      final Bits delDocs = MultiFields.getDeletedDocs(reader);
+      final Bits liveDocs = MultiFields.getLiveDocs(reader);
       DocsEnum docs = null;
       while(true) {
         if (termCount++ == termCountHardLimit) {
@@ -122,7 +120,7 @@ public class DocTermsCreator extends Ent
           break;
         }
         final long pointer = bytes.copyUsingLengthPrefix(term);
-        docs = termsEnum.docs(delDocs, docs);
+        docs = termsEnum.docs(liveDocs, docs);
         while (true) {
           final int docID = docs.nextDoc();
           if (docID == DocIdSetIterator.NO_MORE_DOCS) {

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/DocTermsIndexCreator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/DocTermsIndexCreator.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/DocTermsIndexCreator.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/DocTermsIndexCreator.java Thu Jul  7 09:03:58 2011
@@ -34,7 +34,6 @@ import org.apache.lucene.util.ArrayUtil;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.PagedBytes;
-import org.apache.lucene.util.StringHelper;
 import org.apache.lucene.util.packed.GrowableWriter;
 import org.apache.lucene.util.packed.PackedInts;
 
@@ -70,7 +69,6 @@ public class DocTermsIndexCreator extend
   @Override
   public DocTermsIndex create(IndexReader reader) throws IOException
   {
-    String field = StringHelper.intern(this.field); // TODO?? necessary?
     Terms terms = MultiFields.getTerms(reader, field);
 
     final boolean fasterButMoreRAM = hasOption(FASTER_BUT_MORE_RAM);
@@ -241,13 +239,13 @@ public class DocTermsIndexCreator extend
       }
 
       @Override
-      public SeekStatus seek(BytesRef text, boolean useCache) throws IOException {
+      public SeekStatus seekCeil(BytesRef text, boolean useCache /* ignored */) throws IOException {
         int low = 1;
         int high = numOrd-1;
         
         while (low <= high) {
           int mid = (low + high) >>> 1;
-          seek(mid);
+          seekExact(mid);
           int cmp = term.compareTo(text);
 
           if (cmp < 0)
@@ -261,19 +259,17 @@ public class DocTermsIndexCreator extend
         if (low == numOrd) {
           return SeekStatus.END;
         } else {
-          seek(low);
+          seekExact(low);
           return SeekStatus.NOT_FOUND;
         }
       }
 
-      @Override
-      public SeekStatus seek(long ord) throws IOException {
+      public void seekExact(long ord) throws IOException {
         assert(ord >= 0 && ord <= numOrd);
         // TODO: if gap is small, could iterate from current position?  Or let user decide that?
         currentBlockNumber = bytes.fillAndGetIndex(term, termOrdToBytesOffset.get((int)ord));
         end = blockEnds[currentBlockNumber];
         currentOrd = (int)ord;
-        return SeekStatus.FOUND;
       }
 
       @Override
@@ -326,12 +322,12 @@ public class DocTermsIndexCreator extend
       }
 
       @Override
-      public DocsEnum docs(Bits skipDocs, DocsEnum reuse) throws IOException {
+      public DocsEnum docs(Bits liveDocs, DocsEnum reuse) throws IOException {
         throw new UnsupportedOperationException();
       }
 
       @Override
-      public DocsAndPositionsEnum docsAndPositions(Bits skipDocs, DocsAndPositionsEnum reuse) throws IOException {
+      public DocsAndPositionsEnum docsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse) throws IOException {
         throw new UnsupportedOperationException();
       }
 
@@ -341,9 +337,9 @@ public class DocTermsIndexCreator extend
       }
 
       @Override
-      public void seek(BytesRef term, TermState state) throws IOException {
+      public void seekExact(BytesRef term, TermState state) throws IOException {
         assert state != null && state instanceof OrdTermState;
-        this.seek(((OrdTermState)state).ord);
+        this.seekExact(((OrdTermState)state).ord);
       }
 
       @Override

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/DoubleValuesCreator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/DoubleValuesCreator.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/DoubleValuesCreator.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/DoubleValuesCreator.java Thu Jul  7 09:03:58 2011
@@ -61,8 +61,8 @@ public class DoubleValuesCreator extends
   }
   
   @Override
-  public int getSortTypeID() {
-    return SortField.DOUBLE;
+  public SortField.Type getSortType() {
+    return SortField.Type.DOUBLE;
   }
 
   //--------------------------------------------------------------------------------
@@ -161,4 +161,4 @@ public class DoubleValuesCreator extends
       vals.valid = new Bits.MatchNoBits( maxDoc );
     }
   }
-}
\ No newline at end of file
+}

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/FloatValuesCreator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/FloatValuesCreator.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/FloatValuesCreator.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/FloatValuesCreator.java Thu Jul  7 09:03:58 2011
@@ -61,8 +61,8 @@ public class FloatValuesCreator extends 
   }
   
   @Override
-  public int getSortTypeID() {
-    return SortField.FLOAT;
+  public SortField.Type getSortType() {
+    return SortField.Type.FLOAT;
   }
 
 
@@ -162,4 +162,4 @@ public class FloatValuesCreator extends 
       vals.valid = new Bits.MatchNoBits( maxDoc );
     }
   }
-}
\ No newline at end of file
+}

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/IntValuesCreator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/IntValuesCreator.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/IntValuesCreator.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/IntValuesCreator.java Thu Jul  7 09:03:58 2011
@@ -61,8 +61,8 @@ public class IntValuesCreator extends Ca
   }
   
   @Override
-  public int getSortTypeID() {
-    return SortField.INT;
+  public SortField.Type getSortType() {
+    return SortField.Type.INT;
   }
 
 
@@ -162,4 +162,4 @@ public class IntValuesCreator extends Ca
       vals.valid = new Bits.MatchNoBits( maxDoc );
     }
   }
-}
\ No newline at end of file
+}

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/LongValuesCreator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/LongValuesCreator.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/LongValuesCreator.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/LongValuesCreator.java Thu Jul  7 09:03:58 2011
@@ -61,8 +61,8 @@ public class LongValuesCreator extends C
   }
   
   @Override
-  public int getSortTypeID() {
-    return SortField.LONG;
+  public SortField.Type getSortType() {
+    return SortField.Type.LONG;
   }
 
 
@@ -162,4 +162,4 @@ public class LongValuesCreator extends C
       vals.valid = new Bits.MatchNoBits( maxDoc );
     }
   }
-}
\ No newline at end of file
+}

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/ShortValuesCreator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/ShortValuesCreator.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/ShortValuesCreator.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/cache/ShortValuesCreator.java Thu Jul  7 09:03:58 2011
@@ -61,8 +61,8 @@ public class ShortValuesCreator extends 
   }
   
   @Override
-  public int getSortTypeID() {
-    return SortField.SHORT;
+  public SortField.Type getSortType() {
+    return SortField.Type.SHORT;
   }
 
 
@@ -144,4 +144,4 @@ public class ShortValuesCreator extends 
       vals.valid = new Bits.MatchNoBits( maxDoc );
     }
   }
-}
\ No newline at end of file
+}

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/spans/SpanTermQuery.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/spans/SpanTermQuery.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/search/spans/SpanTermQuery.java Thu Jul  7 09:03:58 2011
@@ -83,14 +83,14 @@ public class SpanTermQuery extends SpanQ
   @Override
   public Spans getSpans(final AtomicReaderContext context) throws IOException {
     final IndexReader reader = context.reader;
-    final DocsAndPositionsEnum postings = reader.termPositionsEnum(reader.getDeletedDocs(),
+    final DocsAndPositionsEnum postings = reader.termPositionsEnum(reader.getLiveDocs(),
                                                                    term.field(),
                                                                    term.bytes());
 
     if (postings != null) {
       return new TermSpans(postings, term);
     } else {
-      if (reader.termDocsEnum(reader.getDeletedDocs(), term.field(), term.bytes()) != null) {
+      if (reader.termDocsEnum(reader.getLiveDocs(), term.field(), term.bytes()) != null) {
         // term does exist, but has no positions
         throw new IllegalStateException("field \"" + term.field() + "\" was indexed with Field.omitTermFreqAndPositions=true; cannot run SpanTermQuery (term=" + term.text() + ")");
       } else {

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/ByteArrayDataInput.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/ByteArrayDataInput.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/ByteArrayDataInput.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/ByteArrayDataInput.java Thu Jul  7 09:03:58 2011
@@ -17,6 +17,8 @@ package org.apache.lucene.store;
  * limitations under the License.
  */
 
+import org.apache.lucene.util.BytesRef;
+
 /** @lucene.experimental */
 public final class ByteArrayDataInput extends DataInput {
 
@@ -25,9 +27,16 @@ public final class ByteArrayDataInput ex
   private int pos;
   private int limit;
 
-  // TODO: allow BytesRef (slice) too
   public ByteArrayDataInput(byte[] bytes) {
-    this.bytes = bytes;
+    reset(bytes);
+  }
+
+  public ByteArrayDataInput(byte[] bytes, int offset, int len) {
+    reset(bytes, offset, len);
+  }
+
+  public ByteArrayDataInput() {
+    reset(BytesRef.EMPTY_BYTES);
   }
 
   public void reset(byte[] bytes) {
@@ -41,7 +50,7 @@ public final class ByteArrayDataInput ex
   public void reset(byte[] bytes, int offset, int len) {
     this.bytes = bytes;
     pos = offset;
-    limit = len;
+    limit = offset + len;
   }
 
   public boolean eof() {
@@ -50,6 +59,7 @@ public final class ByteArrayDataInput ex
 
   public void skipBytes(int count) {
     pos += count;
+    assert pos <= limit;
   }
 
   @Override
@@ -59,12 +69,14 @@ public final class ByteArrayDataInput ex
  
   @Override
   public int readInt() {
+    assert pos+4 <= limit;
     return ((bytes[pos++] & 0xFF) << 24) | ((bytes[pos++] & 0xFF) << 16)
       | ((bytes[pos++] & 0xFF) <<  8) |  (bytes[pos++] & 0xFF);
   }
  
   @Override
   public long readLong() {
+    assert pos+8 <= limit;
     final int i1 = ((bytes[pos++] & 0xff) << 24) | ((bytes[pos++] & 0xff) << 16) |
       ((bytes[pos++] & 0xff) << 8) | (bytes[pos++] & 0xff);
     final int i2 = ((bytes[pos++] & 0xff) << 24) | ((bytes[pos++] & 0xff) << 16) |
@@ -74,9 +86,11 @@ public final class ByteArrayDataInput ex
 
   @Override
   public int readVInt() {
+    checkBounds();
     byte b = bytes[pos++];
     int i = b & 0x7F;
     for (int shift = 7; (b & 0x80) != 0; shift += 7) {
+      checkBounds();
       b = bytes[pos++];
       i |= (b & 0x7F) << shift;
     }
@@ -85,9 +99,11 @@ public final class ByteArrayDataInput ex
  
   @Override
   public long readVLong() {
+    checkBounds();
     byte b = bytes[pos++];
     long i = b & 0x7F;
     for (int shift = 7; (b & 0x80) != 0; shift += 7) {
+      checkBounds();
       b = bytes[pos++];
       i |= (b & 0x7FL) << shift;
     }
@@ -97,7 +113,7 @@ public final class ByteArrayDataInput ex
   // NOTE: AIOOBE not EOF if you read too much
   @Override
   public byte readByte() {
-    assert pos < limit;
+    checkBounds();
     return bytes[pos++];
   }
 
@@ -108,4 +124,9 @@ public final class ByteArrayDataInput ex
     System.arraycopy(bytes, pos, b, offset, len);
     pos += len;
   }
+
+  private boolean checkBounds() {
+    assert pos < limit;
+    return true;
+  }
 }

Copied: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java (from r1143677, lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java?p2=lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java&p1=lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java&r1=1143677&r2=1143719&rev=1143719&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java Thu Jul  7 09:03:58 2011
@@ -48,7 +48,7 @@ public abstract class CompoundFileDirect
   
   private final Directory directory;
   private final String fileName;
-  private final int readBufferSize;  
+  protected final int readBufferSize;  
   private Map<String,FileEntry> entries;
   private boolean openForWrite;
   private static final Map<String,FileEntry> SENTINEL = Collections.emptyMap();
@@ -59,11 +59,11 @@ public abstract class CompoundFileDirect
    * <p>
    * NOTE: subclasses must call {@link #initForRead(Map)} before the directory can be used.
    */
-  public CompoundFileDirectory(Directory directory, String fileName, int readBufferSize) throws IOException {
+  public CompoundFileDirectory(Directory directory, String fileName, IOContext context) throws IOException {
     assert !(directory instanceof CompoundFileDirectory) : "compound file inside of compound file: " + fileName;
     this.directory = directory;
     this.fileName = fileName;
-    this.readBufferSize = readBufferSize;
+    this.readBufferSize = BufferedIndexInput.bufferSize(context);
     this.isOpen = false;
   }
   
@@ -89,7 +89,7 @@ public abstract class CompoundFileDirect
       IndexInput input = null;
       try {
         input = dir.openInput(IndexFileNames.segmentFileName(IndexFileNames.stripExtension(name), "",
-            IndexFileNames.COMPOUND_FILE_ENTRIES_EXTENSION));
+            IndexFileNames.COMPOUND_FILE_ENTRIES_EXTENSION), IOContext.READONCE);
         final int readInt = input.readInt(); // unused right now
         assert readInt == CompoundFileWriter.ENTRY_FORMAT_CURRENT;
         final int numEntries = input.readVInt();
@@ -183,13 +183,7 @@ public abstract class CompoundFileDirect
   }
   
   @Override
-  public synchronized IndexInput openInput(String id) throws IOException {
-    // Default to readBufferSize passed in when we were opened
-    return openInput(id, readBufferSize);
-  }
-  
-  @Override
-  public synchronized IndexInput openInput(String id, int readBufferSize) throws IOException {
+  public synchronized IndexInput openInput(String id, IOContext context) throws IOException {
     ensureOpen();
     assert !openForWrite;
     id = IndexFileNames.stripSegmentName(id);
@@ -267,10 +261,10 @@ public abstract class CompoundFileDirect
   }
   
   @Override
-  public IndexOutput createOutput(String name) throws IOException {
+  public IndexOutput createOutput(String name, IOContext context) throws IOException {
     ensureOpen();
     initWriter();
-    return writer.createOutput(name);
+    return writer.createOutput(name, context);
   }
   
   @Override
@@ -288,7 +282,7 @@ public abstract class CompoundFileDirect
   /** Not implemented
    * @throws UnsupportedOperationException */
   @Override
-  public final CompoundFileDirectory openCompoundInput(String name, int bufferSize) throws IOException {
+  public final CompoundFileDirectory openCompoundInput(String name, IOContext context) throws IOException {
     // NOTE: final to make nested compounding impossible.
     throw new UnsupportedOperationException();
   }
@@ -296,7 +290,7 @@ public abstract class CompoundFileDirect
   /** Not implemented
   * @throws UnsupportedOperationException */
   @Override
-  public CompoundFileDirectory createCompoundOutput(String name)
+  public CompoundFileDirectory createCompoundOutput(String name, IOContext context)
       throws IOException {
     // NOTE: final to make nested compounding impossible.
     throw new UnsupportedOperationException();

Copied: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java (from r1143677, lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java?p2=lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java&p1=lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java&r1=1143677&r2=1143719&rev=1143719&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java Thu Jul  7 09:03:58 2011
@@ -147,7 +147,7 @@ final class CompoundFileWriter {
       assert dataOut != null;
       long finalLength = dataOut.getFilePointer();
       assert assertFileLength(finalLength, dataOut);
-      entryTableOut = directory.createOutput(entryTableName);
+      entryTableOut = directory.createOutput(entryTableName, IOContext.DEFAULT);
       writeEntryTable(entries.values(), entryTableOut);
     } catch (IOException e) {
       priorException = e;
@@ -176,7 +176,7 @@ final class CompoundFileWriter {
    */
   private final long copyFileEntry(IndexOutput dataOut, FileEntry fileEntry)
       throws IOException, MergeAbortedException {
-    final IndexInput is = fileEntry.dir.openInput(fileEntry.file);
+    final IndexInput is = fileEntry.dir.openInput(fileEntry.file, IOContext.READONCE);
     try {
       final long startPtr = dataOut.getFilePointer();
       final long length = fileEntry.length;
@@ -208,7 +208,7 @@ final class CompoundFileWriter {
     }
   }
 
-  IndexOutput createOutput(String name) throws IOException {
+  IndexOutput createOutput(String name, IOContext context) throws IOException {
     ensureOpen();
     boolean success = false;
     try {
@@ -221,7 +221,7 @@ final class CompoundFileWriter {
       entries.put(name, entry);
       final DirectCFSIndexOutput out;
       if (outputTaken.compareAndSet(false, true)) {
-        initDataOut();
+        initDataOut(context);
         success = true;
         out = new DirectCFSIndexOutput(dataOut, entry, false);
       } else {
@@ -229,7 +229,7 @@ final class CompoundFileWriter {
         if (directory.fileExists(name)) {
           throw new IOException("File already exists");
         }
-        out = new DirectCFSIndexOutput(directory.createOutput(name), entry,
+        out = new DirectCFSIndexOutput(directory.createOutput(name, context), entry,
             true);
       }
       success = true;
@@ -245,11 +245,11 @@ final class CompoundFileWriter {
     outputTaken.compareAndSet(true, false);
   }
 
-  private synchronized final void initDataOut() throws IOException {
+  private synchronized final void initDataOut(IOContext context) throws IOException {
     if (dataOut == null) {
       boolean success = false;
       try {
-        dataOut = directory.createOutput(dataFileName);
+        dataOut = directory.createOutput(dataFileName, context);
         dataOut.writeVInt(FORMAT_CURRENT);
         success = true;
       } finally {

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/DataOutput.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/DataOutput.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/DataOutput.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/DataOutput.java Thu Jul  7 09:03:58 2011
@@ -60,6 +60,14 @@ public abstract class DataOutput {
     writeByte((byte)(i >>  8));
     writeByte((byte) i);
   }
+  
+  /** Writes a short as two bytes.
+   * @see DataInput#readShort()
+   */
+  public void writeShort(short i) throws IOException {
+    writeByte((byte)(i >>  8));
+    writeByte((byte) i);
+  }
 
   /** Writes an int in a variable-length format.  Writes between one and
    * five bytes.  Smaller values take fewer bytes.  Negative numbers are not

Copied: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/DefaultCompoundFileDirectory.java (from r1143677, lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/DefaultCompoundFileDirectory.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/DefaultCompoundFileDirectory.java?p2=lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/DefaultCompoundFileDirectory.java&p1=lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/DefaultCompoundFileDirectory.java&r1=1143677&r2=1143719&rev=1143719&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/DefaultCompoundFileDirectory.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/DefaultCompoundFileDirectory.java Thu Jul  7 09:03:58 2011
@@ -31,11 +31,11 @@ import org.apache.lucene.util.IOUtils;
 public class DefaultCompoundFileDirectory extends CompoundFileDirectory {
   protected IndexInput stream;
   
-  public DefaultCompoundFileDirectory(Directory directory, String fileName, int readBufferSize, boolean writeable) throws IOException {
-    super(directory, fileName, readBufferSize);
+  public DefaultCompoundFileDirectory(Directory directory, String fileName, IOContext context, boolean writeable) throws IOException {
+    super(directory, fileName, context);
     if (!writeable) {
       try {
-        stream = directory.openInput(fileName, readBufferSize);
+        stream = directory.openInput(fileName, context);
         initForRead(CompoundFileDirectory.readEntries(stream, directory, fileName));
       } catch (IOException e) {
         IOUtils.closeSafely(e, stream);

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/Directory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/Directory.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/Directory.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/Directory.java Thu Jul  7 09:03:58 2011
@@ -108,9 +108,33 @@ public abstract class Directory implemen
    * implementation may ignore the buffer size.  Currently
    * the only Directory implementations that respect this
    * parameter are {@link FSDirectory} and {@link
-   * org.apache.lucene.index.CompoundFileReader}.
+   * CompoundFileDirectory}.
   */
   public abstract IndexInput openInput(String name, IOContext context) throws IOException; 
+  
+  /** 
+   * Returns a {@link CompoundFileDirectory} capable of
+   * reading the Lucene compound file format.  
+   * <p>
+   * The default implementation returns 
+   * {@link DefaultCompoundFileDirectory}.
+   * @lucene.experimental
+   */
+  public CompoundFileDirectory openCompoundInput(String name, IOContext context) throws IOException {
+    return new DefaultCompoundFileDirectory(this, name, context, false);
+  }
+  
+  /** 
+   * Returns a {@link CompoundFileDirectory} capable of
+   * writing the Lucene compound file format.  
+   * <p>
+   * The default implementation returns 
+   * {@link DefaultCompoundFileDirectory}.
+   * @lucene.experimental
+   */
+  public CompoundFileDirectory createCompoundOutput(String name, IOContext context) throws IOException {
+    return new DefaultCompoundFileDirectory(this, name, context, true);
+  }
 
   /** Construct a {@link Lock}.
    * @param name the name of the lock file
@@ -194,10 +218,12 @@ public abstract class Directory implemen
    * overwrite it if it does.
    */
   public void copy(Directory to, String src, String dest, IOContext context) throws IOException {
-    IndexOutput os = to.createOutput(dest, context);
-    IndexInput is = openInput(src, context);
+    IndexOutput os = null;
+    IndexInput is = null;
     IOException priorException = null;
     try {
+      os = to.createOutput(dest, context);
+      is = openInput(src, context);
       is.copyBytes(os, is.length());
     } catch (IOException ioe) {
       priorException = ioe;

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/FileSwitchDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/FileSwitchDirectory.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/FileSwitchDirectory.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/FileSwitchDirectory.java Thu Jul  7 09:03:58 2011
@@ -149,4 +149,14 @@ public class FileSwitchDirectory extends
   public IndexInput openInput(String name, IOContext context) throws IOException {
     return getDirectory(name).openInput(name, context);
   }
+
+  @Override
+  public CompoundFileDirectory openCompoundInput(String name, IOContext context) throws IOException {
+    return getDirectory(name).openCompoundInput(name, context);
+  }
+  
+  @Override
+  public CompoundFileDirectory createCompoundOutput(String name, IOContext context) throws IOException {
+    return getDirectory(name).createCompoundOutput(name, context);
+  }
 }

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/IndexOutput.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/IndexOutput.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/IndexOutput.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/IndexOutput.java Thu Jul  7 09:03:58 2011
@@ -58,4 +58,5 @@ public abstract class IndexOutput extend
    * @param length file length
    */
   public void setLength(long length) throws IOException {}
+
 }

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/InputStreamDataInput.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/InputStreamDataInput.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/InputStreamDataInput.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/InputStreamDataInput.java Thu Jul  7 09:03:58 2011
@@ -51,7 +51,7 @@ public class InputStreamDataInput extend
     }
   }
 
-  //@Override -- not until Java 1.6
+  @Override
   public void close() throws IOException {
     is.close();
   }

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/MMapDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/MMapDirectory.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/MMapDirectory.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/MMapDirectory.java Thu Jul  7 09:03:58 2011
@@ -32,6 +32,7 @@ import java.security.PrivilegedActionExc
 import java.lang.reflect.Method;
 
 import org.apache.lucene.util.Constants;
+import org.apache.lucene.util.IOUtils;
 
 /** File-based {@link Directory} implementation that uses
  *  mmap for reading, and {@link
@@ -213,11 +214,49 @@ public class MMapDirectory extends FSDir
     File f = new File(getDirectory(), name);
     RandomAccessFile raf = new RandomAccessFile(f, "r");
     try {
-      return new MMapIndexInput(raf, chunkSizePower);
+      return new MMapIndexInput(raf, 0, raf.length(), chunkSizePower);
     } finally {
       raf.close();
     }
   }
+  
+  @Override
+  public CompoundFileDirectory openCompoundInput(String name, IOContext context) throws IOException {
+    return new MMapCompoundFileDirectory(name, context);
+  }
+  
+  private final class MMapCompoundFileDirectory extends CompoundFileDirectory {
+    private RandomAccessFile raf = null;
+
+    public MMapCompoundFileDirectory(String fileName, IOContext context) throws IOException {
+      super(MMapDirectory.this, fileName, context);
+      IndexInput stream = null;
+      try {
+        File f = new File(MMapDirectory.this.getDirectory(), fileName);
+        raf = new RandomAccessFile(f, "r");
+        stream = new MMapIndexInput(raf, 0, raf.length(), chunkSizePower);
+        initForRead(CompoundFileDirectory.readEntries(stream, MMapDirectory.this, fileName));
+        stream.close();
+      } catch (IOException e) {
+        // throw our original exception
+        IOUtils.closeSafely(e, raf, stream);
+      }
+    }
+
+    @Override
+    public IndexInput openInputSlice(String id, long offset, long length, int readBufferSize) throws IOException {
+      return new MMapIndexInput(raf, offset, length, chunkSizePower);
+    }
+
+    @Override
+    public synchronized void close() throws IOException {
+      try {
+        raf.close();
+      } finally {
+        super.close();
+      }
+    }
+  }
 
   // Because Java's ByteBuffer uses an int to address the
   // values, it's necessary to access a file >
@@ -235,8 +274,8 @@ public class MMapDirectory extends FSDir
   
     private boolean isClone = false;
     
-    MMapIndexInput(RandomAccessFile raf, int chunkSizePower) throws IOException {
-      this.length = raf.length();
+    MMapIndexInput(RandomAccessFile raf, long offset, long length, int chunkSizePower) throws IOException {
+      this.length = length;
       this.chunkSizePower = chunkSizePower;
       this.chunkSize = 1L << chunkSizePower;
       this.chunkSizeMask = chunkSize - 1L;
@@ -261,7 +300,7 @@ public class MMapDirectory extends FSDir
           ? chunkSize
           : (length - bufferStart)
         );
-        this.buffers[bufNr] = rafc.map(MapMode.READ_ONLY, bufferStart, bufSize);
+        this.buffers[bufNr] = rafc.map(MapMode.READ_ONLY, offset + bufferStart, bufSize);
         bufferStart += bufSize;
       }
       seek(0L);

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java Thu Jul  7 09:03:58 2011
@@ -24,6 +24,9 @@ import java.nio.channels.ClosedChannelEx
 import java.nio.channels.FileChannel;
 import java.util.concurrent.Future; // javadoc
 
+import org.apache.lucene.store.SimpleFSDirectory.SimpleFSIndexInput;
+import org.apache.lucene.util.IOUtils;
+
 /**
  * An {@link FSDirectory} implementation that uses java.nio's FileChannel's
  * positional read, which allows multiple threads to read from the same file
@@ -77,6 +80,47 @@ public class NIOFSDirectory extends FSDi
     ensureOpen();
     return new NIOFSIndexInput(new File(getDirectory(), name), context, getReadChunkSize());
   }
+  
+  @Override
+  public CompoundFileDirectory openCompoundInput(String name, IOContext context) throws IOException {
+    return new NIOFSCompoundFileDirectory(name, context);
+  }
+
+  private final class NIOFSCompoundFileDirectory extends CompoundFileDirectory {
+    private SimpleFSIndexInput.Descriptor fd;
+    private FileChannel fc;
+
+    public NIOFSCompoundFileDirectory(String fileName, IOContext context) throws IOException {
+      super(NIOFSDirectory.this, fileName, context);
+      IndexInput stream = null;
+      try {
+        File f = new File(NIOFSDirectory.this.getDirectory(), fileName);
+        fd = new SimpleFSIndexInput.Descriptor(f, "r");
+        fc = fd.getChannel();
+        stream = new NIOFSIndexInput(fd, fc, 0, fd.length, readBufferSize,
+            getReadChunkSize());
+        initForRead(CompoundFileDirectory.readEntries(stream, NIOFSDirectory.this, fileName));
+        stream.close();
+      } catch (IOException e) {
+        // throw our original exception
+        IOUtils.closeSafely(e, fc, fd, stream);
+      }
+    }
+    
+    @Override
+    public IndexInput openInputSlice(String id, long offset, long length, int readBufferSize) throws IOException {
+      return new NIOFSIndexInput(fd, fc, offset, length, readBufferSize, getReadChunkSize());
+    }
+
+    @Override
+    public synchronized void close() throws IOException {
+      try {
+        IOUtils.closeSafely(false, fc, fd);
+      } finally {
+        super.close();
+      }
+    }
+  }
 
   protected static class NIOFSIndexInput extends SimpleFSDirectory.SimpleFSIndexInput {
 
@@ -91,6 +135,12 @@ public class NIOFSDirectory extends FSDi
       super(path, context, chunkSize);
       channel = file.getChannel();
     }
+    
+    public NIOFSIndexInput(Descriptor file, FileChannel fc, long off, long length, int bufferSize, int chunkSize) throws IOException {
+      super(file, off, length, bufferSize, chunkSize);
+      channel = fc;
+      isClone = true;
+    }
 
     @Override
     protected void newBuffer(byte[] newBuffer) {
@@ -145,7 +195,11 @@ public class NIOFSDirectory extends FSDi
       int readLength = bb.limit() - readOffset;
       assert readLength == len;
 
-      long pos = getFilePointer();
+      long pos = getFilePointer() + off;
+      
+      if (pos + len > end) {
+        throw new IOException("read past EOF");
+      }
 
       try {
         while (readLength > 0) {
@@ -159,9 +213,6 @@ public class NIOFSDirectory extends FSDi
           }
           bb.limit(limit);
           int i = channel.read(bb, pos);
-          if (i == -1) {
-            throw new IOException("read past EOF");
-          }
           pos += i;
           readOffset += i;
           readLength -= i;

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/OutputStreamDataOutput.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/OutputStreamDataOutput.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/OutputStreamDataOutput.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/OutputStreamDataOutput.java Thu Jul  7 09:03:58 2011
@@ -39,7 +39,7 @@ public class OutputStreamDataOutput exte
     os.write(b, offset, length);
   }
 
-  // @Override -- not until Java 1.6
+  @Override
   public void close() throws IOException {
     os.close();
   }

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java Thu Jul  7 09:03:58 2011
@@ -21,7 +21,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.RandomAccessFile;
 
-import org.apache.lucene.store.IOContext.Context;
+import org.apache.lucene.util.IOUtils;
 
 
 /** A straightforward implementation of {@link FSDirectory}
@@ -58,6 +58,45 @@ public class SimpleFSDirectory extends F
     ensureOpen();
     return new SimpleFSIndexInput(new File(directory, name), context, getReadChunkSize());
   }
+  
+  @Override
+  public CompoundFileDirectory openCompoundInput(String name, IOContext context) throws IOException {
+    return new SimpleFSCompoundFileDirectory(name, context);
+  }
+
+  private final class SimpleFSCompoundFileDirectory extends CompoundFileDirectory {
+    private SimpleFSIndexInput.Descriptor fd;
+
+    public SimpleFSCompoundFileDirectory(String fileName, IOContext context) throws IOException {
+      super(SimpleFSDirectory.this, fileName, context);
+      IndexInput stream = null;
+      try {
+        final File f = new File(SimpleFSDirectory.this.getDirectory(), fileName);
+        fd = new SimpleFSIndexInput.Descriptor(f, "r");
+        stream = new SimpleFSIndexInput(fd, 0, fd.length, readBufferSize,
+            getReadChunkSize());
+        initForRead(CompoundFileDirectory.readEntries(stream, SimpleFSDirectory.this, fileName));
+        stream.close();
+      } catch (IOException e) {
+        // throw our original exception
+        IOUtils.closeSafely(e, fd, stream);
+      }
+    }
+
+    @Override
+    public IndexInput openInputSlice(String id, long offset, long length, int readBufferSize) throws IOException {
+      return new SimpleFSIndexInput(fd, offset, length, readBufferSize, getReadChunkSize());
+    }
+
+    @Override
+    public synchronized void close() throws IOException {
+      try {
+        fd.close();
+      } finally {
+        super.close();
+      }
+    }
+  }
 
   protected static class SimpleFSIndexInput extends BufferedIndexInput {
   
@@ -87,11 +126,24 @@ public class SimpleFSDirectory extends F
     boolean isClone;
     //  LUCENE-1566 - maximum read length on a 32bit JVM to prevent incorrect OOM 
     protected final int chunkSize;
+    protected final long off;
+    protected final long end;
     
     public SimpleFSIndexInput(File path, IOContext context, int chunkSize) throws IOException {
       super(context);
-      file = new Descriptor(path, "r");
+      this.file = new Descriptor(path, "r"); 
+      this.chunkSize = chunkSize;
+      this.off = 0L;
+      this.end = file.length;
+    }
+    
+    public SimpleFSIndexInput(Descriptor file, long off, long length, int bufferSize, int chunkSize) throws IOException {
+      super(bufferSize);
+      this.file = file;
       this.chunkSize = chunkSize;
+      this.off = off;
+      this.end = off + length;
+      this.isClone = true; // well, we are sorta?
     }
   
     /** IndexInput methods */
@@ -99,13 +151,17 @@ public class SimpleFSDirectory extends F
     protected void readInternal(byte[] b, int offset, int len)
          throws IOException {
       synchronized (file) {
-        long position = getFilePointer();
+        long position = off + getFilePointer();
         if (position != file.position) {
           file.seek(position);
           file.position = position;
         }
         int total = 0;
 
+        if (position + len > end) {
+          throw new IOException("read past EOF");
+        }
+
         try {
           do {
             final int readLength;
@@ -116,9 +172,6 @@ public class SimpleFSDirectory extends F
               readLength = chunkSize;
             }
             final int i = file.read(b, offset + total, readLength);
-            if (i == -1) {
-              throw new IOException("read past EOF");
-            }
             file.position += i;
             total += i;
           } while (total < len);
@@ -147,7 +200,7 @@ public class SimpleFSDirectory extends F
   
     @Override
     public long length() {
-      return file.length;
+      return end - off;
     }
   
     @Override

Modified: lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/util/ArrayUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/util/ArrayUtil.java?rev=1143719&r1=1143718&r2=1143719&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/util/ArrayUtil.java (original)
+++ lucene/dev/branches/LUCENE2793/lucene/src/java/org/apache/lucene/util/ArrayUtil.java Thu Jul  7 09:03:58 2011
@@ -393,6 +393,56 @@ public final class ArrayUtil {
       return array;
   }
 
+  public static int[][] grow(int[][] array, int minSize) {
+    if (array.length < minSize) {
+      int[][] newArray = new int[oversize(minSize, RamUsageEstimator.NUM_BYTES_OBJECT_REF)][];
+      System.arraycopy(array, 0, newArray, 0, array.length);
+      return newArray;
+    } else {
+      return array;
+    }
+  }
+
+  public static int[][] grow(int[][] array) {
+    return grow(array, 1 + array.length);
+  }
+
+  public static int[][] shrink(int[][] array, int targetSize) {
+    final int newSize = getShrinkSize(array.length, targetSize, RamUsageEstimator.NUM_BYTES_OBJECT_REF);
+    if (newSize != array.length) {
+      int[][] newArray = new int[newSize][];
+      System.arraycopy(array, 0, newArray, 0, newSize);
+      return newArray;
+    } else {
+      return array;
+    }
+  }
+
+  public static float[][] grow(float[][] array, int minSize) {
+    if (array.length < minSize) {
+      float[][] newArray = new float[oversize(minSize, RamUsageEstimator.NUM_BYTES_OBJECT_REF)][];
+      System.arraycopy(array, 0, newArray, 0, array.length);
+      return newArray;
+    } else {
+      return array;
+    }
+  }
+
+  public static float[][] grow(float[][] array) {
+    return grow(array, 1 + array.length);
+  }
+
+  public static float[][] shrink(float[][] array, int targetSize) {
+    final int newSize = getShrinkSize(array.length, targetSize, RamUsageEstimator.NUM_BYTES_OBJECT_REF);
+    if (newSize != array.length) {
+      float[][] newArray = new float[newSize][];
+      System.arraycopy(array, 0, newArray, 0, newSize);
+      return newArray;
+    } else {
+      return array;
+    }
+  }
+
   /**
    * Returns hash of chars in range start (inclusive) to
    * end (inclusive)
@@ -617,6 +667,7 @@ public final class ArrayUtil {
    */
   public static <T> void mergeSort(T[] a, int fromIndex, int toIndex, Comparator<? super T> comp) {
     if (toIndex-fromIndex <= 1) return;
+    //System.out.println("SORT: " + (toIndex-fromIndex));
     getSorter(a, comp).mergeSort(fromIndex, toIndex-1);
   }
   



Mime
View raw message