lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1413182 [1/2] - in /lucene/dev/branches/lucene4547: lucene/ lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/ lucene/core/src/java/org/apache/lucene/index/ lucene/core/src/java/org/apache/lucene/search/ lucene/core/src/test/org...
Date Sat, 24 Nov 2012 13:13:54 GMT
Author: mikemccand
Date: Sat Nov 24 13:13:51 2012
New Revision: 1413182

URL: http://svn.apache.org/viewvc?rev=1413182&view=rev
Log:
merge DocTermsIndex into SortedDocValues

Modified:
    lucene/dev/branches/lucene4547/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
    lucene/dev/branches/lucene4547/lucene/common-build.xml
    lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/SortedDocValues.java
    lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCache.java
    lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java
    lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCacheRangeFilter.java
    lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCacheTermsFilter.java
    lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldComparator.java
    lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
    lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/search/FieldCacheRewriteMethod.java
    lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/search/TestElevationComparator.java
    lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/search/TestFieldCache.java
    lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java
    lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupsCollector.java
    lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermDistinctValuesCollector.java
    lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermFirstPassGroupingCollector.java
    lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java
    lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermSecondPassGroupingCollector.java
    lucene/dev/branches/lucene4547/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/DocTermsIndexDocValues.java
    lucene/dev/branches/lucene4547/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/OrdFieldSource.java
    lucene/dev/branches/lucene4547/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ReverseOrdFieldSource.java
    lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/component/FieldFacetStats.java
    lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/component/StatsComponent.java
    lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/request/PerSegmentSingleValuedFaceting.java
    lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/request/SimpleFacets.java
    lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/request/UnInvertedField.java
    lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/schema/BoolField.java
    lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/schema/DateField.java
    lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/schema/SortableDoubleField.java
    lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/schema/SortableFloatField.java
    lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/schema/SortableIntField.java
    lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/schema/SortableLongField.java
    lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/schema/StrFieldSource.java
    lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/search/MissingStringLastComparatorSource.java

Modified: lucene/dev/branches/lucene4547/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java (original)
+++ lucene/dev/branches/lucene4547/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java Sat Nov 24 13:13:51 2012
@@ -53,10 +53,10 @@ import org.apache.lucene.index.MultiFiel
 import org.apache.lucene.index.SegmentInfos;
 import org.apache.lucene.index.SerialMergeScheduler;
 import org.apache.lucene.index.SlowCompositeReaderWrapper;
+import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.search.DocIdSetIterator;
-import org.apache.lucene.search.FieldCache.DocTermsIndex;
 import org.apache.lucene.search.FieldCache;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.BytesRef;
@@ -341,12 +341,11 @@ public class TestPerfTasksLogic extends 
     Benchmark benchmark = execBenchmark(algLines);
 
     DirectoryReader r = DirectoryReader.open(benchmark.getRunData().getDirectory());
-    DocTermsIndex idx = FieldCache.DEFAULT.getTermsIndex(new SlowCompositeReaderWrapper(r), "country");
+    SortedDocValues idx = FieldCache.DEFAULT.getTermsIndex(new SlowCompositeReaderWrapper(r), "country");
     final int maxDoc = r.maxDoc();
     assertEquals(1000, maxDoc);
-    BytesRef br = new BytesRef();
     for(int i=0;i<1000;i++) {
-      assertNotNull("doc " + i + " has null country", idx.getTerm(i, br));
+      assertTrue("doc " + i + " has null country", idx.getOrd(i) != -1);
     }
     r.close();
   }

Modified: lucene/dev/branches/lucene4547/lucene/common-build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/common-build.xml?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/common-build.xml (original)
+++ lucene/dev/branches/lucene4547/lucene/common-build.xml Sat Nov 24 13:13:51 2012
@@ -438,7 +438,7 @@
           description="Compiles core classes">
     <compile
       srcdir="${src.dir}"
-      destdir="${build.dir}/classes/java">
+      DESTDIR="${build.dir}/classes/java">
       <classpath refid="classpath"/>
     </compile>
 

Modified: lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/SortedDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/SortedDocValues.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/SortedDocValues.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/SortedDocValues.java Sat Nov 24 13:13:51 2012
@@ -17,6 +17,10 @@ package org.apache.lucene.index;
  * limitations under the License.
  */
 
+import java.io.IOException;
+import java.util.Comparator;
+
+import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
 
 // nocommit need marker interface?
@@ -28,14 +32,123 @@ public abstract class SortedDocValues ex
   public abstract void lookupOrd(int ord, BytesRef result);
 
   // nocommit throws IOE or not?
+  // nocommit .getUniqueValueCount?
   public abstract int getValueCount();
 
   @Override
   public void get(int docID, BytesRef result) {
     int ord = getOrd(docID);
+    if (ord == -1) {
+      // nocommit what to do ... maybe we need to return
+      // BytesRef?
+      throw new IllegalArgumentException("doc has no value");
+    }
     lookupOrd(ord, result);
   }
 
+  public TermsEnum getTermsEnum() {
+    // nocommit who tests this base impl ...
+    // Default impl just uses the existing API; subclasses
+    // can specialize:
+    return new TermsEnum() {
+      private int currentOrd = -1;
+
+      private final BytesRef term = new BytesRef();
+
+      @Override
+      public SeekStatus seekCeil(BytesRef text, boolean useCache /* ignored */) throws IOException {
+        int low = 0;
+        int high = getValueCount()-1;
+        
+        while (low <= high) {
+          int mid = (low + high) >>> 1;
+          seekExact(mid);
+          int cmp = term.compareTo(text);
+
+          if (cmp < 0)
+            low = mid + 1;
+          else if (cmp > 0)
+            high = mid - 1;
+          else {
+            return SeekStatus.FOUND; // key found
+          }
+        }
+        
+        if (low == getValueCount()) {
+          return SeekStatus.END;
+        } else {
+          seekExact(low);
+          return SeekStatus.NOT_FOUND;
+        }
+      }
+
+      @Override
+      public void seekExact(long ord) throws IOException {
+        assert ord >= 0 && ord < getValueCount();
+        currentOrd = (int) ord;
+        lookupOrd(currentOrd, term);
+      }
+
+      @Override
+      public BytesRef next() throws IOException {
+        currentOrd++;
+        if (currentOrd >= getValueCount()) {
+          return null;
+        }
+        lookupOrd(currentOrd, term);
+        return term;
+      }
+
+      @Override
+      public BytesRef term() throws IOException {
+        return term;
+      }
+
+      @Override
+      public long ord() throws IOException {
+        return currentOrd;
+      }
+
+      @Override
+      public int docFreq() {
+        throw new UnsupportedOperationException();
+      }
+
+      @Override
+      public long totalTermFreq() {
+        return -1;
+      }
+
+      @Override
+      public DocsEnum docs(Bits liveDocs, DocsEnum reuse, int flags) throws IOException {
+        throw new UnsupportedOperationException();
+      }
+
+      @Override
+      public DocsAndPositionsEnum docsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse, int flags) throws IOException {
+        throw new UnsupportedOperationException();
+      }
+
+      @Override
+      public Comparator<BytesRef> getComparator() {
+        return BytesRef.getUTF8SortedAsUnicodeComparator();
+      }
+
+      @Override
+      public void seekExact(BytesRef term, TermState state) throws IOException {
+        assert state != null && state instanceof OrdTermState;
+        this.seekExact(((OrdTermState)state).ord);
+      }
+
+      @Override
+      public TermState termState() throws IOException {
+        OrdTermState state = new OrdTermState();
+        state.ord = currentOrd;
+        return state;
+      }
+    };
+  }
+
   @Override
   public SortedDocValues newRAMInstance() {
     // nocommit optimize this
@@ -136,4 +249,31 @@ public abstract class SortedDocValues ex
       return 0;
     }
   }
+
+  // nocommit javadocs
+  public int lookupTerm(BytesRef key, BytesRef spare) {
+    // this special case is the reason that Arrays.binarySearch() isn't useful.
+    if (key == null) {
+      throw new IllegalArgumentException("key must not be null");
+    }
+
+    int low = 0;
+    int high = getValueCount()-1;
+
+    while (low <= high) {
+      int mid = (low + high) >>> 1;
+      lookupOrd(mid, spare);
+      int cmp = spare.compareTo(key);
+
+      if (cmp < 0) {
+        low = mid + 1;
+      } else if (cmp > 0) {
+        high = mid - 1;
+      } else {
+        return mid; // key found
+      }
+    }
+
+    return -(low + 1);  // key not found.
+  }
 }

Modified: lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCache.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCache.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCache.java Sat Nov 24 13:13:51 2012
@@ -21,18 +21,17 @@ import java.io.IOException;
 import java.io.PrintStream;
 
 import org.apache.lucene.analysis.NumericTokenStream; // for javadocs
-import org.apache.lucene.document.IntField; // for javadocs
+import org.apache.lucene.document.DoubleField; // for javadocs
 import org.apache.lucene.document.FloatField; // for javadocs
+import org.apache.lucene.document.IntField; // for javadocs
 import org.apache.lucene.document.LongField; // for javadocs
-import org.apache.lucene.document.DoubleField; // for javadocs
-import org.apache.lucene.index.DocTermOrds;
 import org.apache.lucene.index.AtomicReader;
-import org.apache.lucene.index.TermsEnum;
+import org.apache.lucene.index.DocTermOrds;
+import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.NumericUtils;
 import org.apache.lucene.util.RamUsageEstimator;
-import org.apache.lucene.util.packed.PackedInts;
 
 /**
  * Expert: Maintains caches of term values.
@@ -41,6 +40,8 @@ import org.apache.lucene.util.packed.Pac
  *
  * @since   lucene 1.4
  * @see org.apache.lucene.util.FieldCacheSanityChecker
+ *
+ * @lucene.internal
  */
 // nocommit abstract class...?
 public interface FieldCache {
@@ -480,7 +481,7 @@ public interface FieldCache {
   public Doubles getDoubles(AtomicReader reader, String field, DoubleParser parser, boolean setDocsWithField) throws IOException;
 
   /** Returned by {@link #getTerms} */
-  // nocommit: can we merge this api with the BinaryDocValues api?
+  // nocommit: merge this api with the BinaryDocValues api?
   public abstract static class DocTerms {
     /** The BytesRef argument must not be null; the method
      *  returns the same BytesRef, or an empty (length=0)
@@ -515,64 +516,6 @@ public interface FieldCache {
    *  subsequent calls will share the same cache entry. */
   public DocTerms getTerms (AtomicReader reader, String field, float acceptableOverheadRatio) throws IOException;
 
-  /** Returned by {@link #getTermsIndex} */
-  // nocommit: can we merge this api with the SortedDocValues api?
-  public abstract static class DocTermsIndex {
-
-    public int binarySearchLookup(BytesRef key, BytesRef spare) {
-      // this special case is the reason that Arrays.binarySearch() isn't useful.
-      if (key == null) {
-        throw new IllegalArgumentException("key must not be null");
-      }
-
-      int low = 0;
-      int high = numOrd()-1;
-
-      while (low <= high) {
-        int mid = (low + high) >>> 1;
-        int cmp = lookup(mid, spare).compareTo(key);
-
-        if (cmp < 0)
-          low = mid + 1;
-        else if (cmp > 0)
-          high = mid - 1;
-        else
-          return mid; // key found
-      }
-      return -(low + 1);  // key not found.
-    }
-
-    /** The BytesRef argument must not be null; the method
-     *  returns the same BytesRef, or an empty (length=0)
-     *  BytesRef if this ord is the null ord (-1). */
-    public abstract BytesRef lookup(int ord, BytesRef reuse);
-
-    /** Convenience method, to lookup the Term for a doc.
-     *  If this doc is deleted or did not have this field,
-     *  this will return an empty (length=0) BytesRef. */
-    public BytesRef getTerm(int docID, BytesRef reuse) {
-      int ord = getOrd(docID);
-      if (ord == -1) {
-        return null;
-      }
-      return lookup(ord, reuse);
-    }
-
-    /** Returns sort ord for this document.  Ord -1 is
-     *  is returend for docs that are deleted or did not have
-     *  this field.  */
-    public abstract int getOrd(int docID);
-
-    /** Returns total unique ord count. */
-    public abstract int numOrd();
-
-    /** Number of documents */
-    public abstract int size();
-
-    /** Returns a TermsEnum that can iterate over the values in this index entry */
-    public abstract TermsEnum getTermsEnum();
-  }
-
   /** Checks the internal cache for an appropriate entry, and if none
    * is found, reads the term values in <code>field</code>
    * and returns a {@link DocTerms} instance, providing a
@@ -582,7 +525,7 @@ public interface FieldCache {
    * @return The values in the given field for each document.
    * @throws IOException  If any error occurs.
    */
-  public DocTermsIndex getTermsIndex (AtomicReader reader, String field) throws IOException;
+  public SortedDocValues getTermsIndex (AtomicReader reader, String field) throws IOException;
 
   /** Expert: just like {@link
    *  #getTermsIndex(AtomicReader,String)}, but you can specify
@@ -590,7 +533,7 @@ public interface FieldCache {
    *  faster lookups (default is "true").  Note that the
    *  first call for a given reader and field "wins",
    *  subsequent calls will share the same cache entry. */
-  public DocTermsIndex getTermsIndex (AtomicReader reader, String field, float acceptableOverheadRatio) throws IOException;
+  public SortedDocValues getTermsIndex (AtomicReader reader, String field, float acceptableOverheadRatio) throws IOException;
 
   /**
    * Checks the internal cache for an appropriate entry, and if none is found, reads the term values
@@ -662,7 +605,7 @@ public interface FieldCache {
      * The most recently estimated size of the value, null unless 
      * estimateSize has been called.
      */
-    public final String getEstimatedSize() {
+    public String getEstimatedSize() {
       return size;
     }
     

Modified: lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java Sat Nov 24 13:13:51 2012
@@ -47,7 +47,6 @@ import org.apache.lucene.util.FixedBitSe
 import org.apache.lucene.util.PagedBytes;
 import org.apache.lucene.util.packed.GrowableWriter;
 import org.apache.lucene.util.packed.PackedInts;
-import org.apache.lucene.util.packed.PackedInts.Reader;
 
 // nocommit rename to UninvertFieldCacheImpl or something ...
 
@@ -73,7 +72,7 @@ class FieldCacheImpl implements FieldCac
     caches.put(Long.TYPE, new LongCache(this));
     caches.put(Double.TYPE, new DoubleCache(this));
     caches.put(DocTerms.class, new DocTermsCache(this));
-    caches.put(DocTermsIndex.class, new DocTermsIndexCache(this));
+    caches.put(SortedDocValues.class, new SortedDocValuesCache(this));
     caches.put(DocTermOrds.class, new DocTermOrdsCache(this));
     caches.put(DocsWithFieldCache.class, new DocsWithFieldCache(this));
   }
@@ -574,7 +573,6 @@ class FieldCacheImpl implements FieldCac
         // nocommit should we throw exc if parser isn't
         // null?  if setDocsWithField is true?
       } else {
-        int maxDoc = reader.maxDoc();      
         final int[] values;
         final IntParser parser = (IntParser) key.custom;
         if (parser == null) {
@@ -728,7 +726,6 @@ class FieldCacheImpl implements FieldCac
         // nocommit should we throw exc if parser isn't
         // null?  if setDocsWithField is true?
       } else {
-        int maxDoc = reader.maxDoc();
         final float[] values;
         final FloatParser parser = (FloatParser) key.custom;
         if (parser == null) {
@@ -819,7 +816,6 @@ class FieldCacheImpl implements FieldCac
         // nocommit should we throw exc if parser isn't
         // null?  if setDocsWithField is true?
       } else {
-        int maxDoc = reader.maxDoc();
         final long[] values;
         final LongParser parser = (LongParser) key.custom;
         if (parser == null) {
@@ -910,7 +906,6 @@ class FieldCacheImpl implements FieldCac
         // nocommit should we throw exc if parser isn't
         // null?  if setDocsWithField is true?
       } else {
-        int maxDoc = reader.maxDoc();
         final double[] values;
         final DoubleParser parser = (DoubleParser) key.custom;
         if (parser == null) {
@@ -954,13 +949,13 @@ class FieldCacheImpl implements FieldCac
     }
   }
 
-  public static class DocTermsIndexImpl extends DocTermsIndex {
+  public static class SortedDocValuesImpl extends SortedDocValues {
     private final PagedBytes.Reader bytes;
     private final PackedInts.Reader termOrdToBytesOffset;
     private final PackedInts.Reader docToTermOrd;
     private final int numOrd;
 
-    public DocTermsIndexImpl(PagedBytes.Reader bytes, PackedInts.Reader termOrdToBytesOffset, PackedInts.Reader docToTermOrd, int numOrd) {
+    public SortedDocValuesImpl(PagedBytes.Reader bytes, PackedInts.Reader termOrdToBytesOffset, PackedInts.Reader docToTermOrd, int numOrd) {
       this.bytes = bytes;
       this.docToTermOrd = docToTermOrd;
       this.termOrdToBytesOffset = termOrdToBytesOffset;
@@ -968,7 +963,7 @@ class FieldCacheImpl implements FieldCac
     }
 
     @Override
-    public int numOrd() {
+    public int getValueCount() {
       return numOrd;
     }
 
@@ -986,19 +981,31 @@ class FieldCacheImpl implements FieldCac
     }
 
     @Override
-    public BytesRef lookup(int ord, BytesRef ret) {
+    public void lookupOrd(int ord, BytesRef ret) {
       if (ord < 0) {
         throw new IllegalArgumentException("ord must be >=0 (got ord=" + ord + ")");
       }
-      return bytes.fill(ret, termOrdToBytesOffset.get(ord));
+      bytes.fill(ret, termOrdToBytesOffset.get(ord));
+    }
+
+    @Override
+    public int maxLength() {
+      // nocommit hmm
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean isFixedLength() {
+      // nocommit hmm
+      throw new UnsupportedOperationException();
     }
 
     @Override
     public TermsEnum getTermsEnum() {
-      return this.new DocTermsIndexEnum();
+      return this.new SortedDocValuesEnum();
     }
 
-    class DocTermsIndexEnum extends TermsEnum {
+    class SortedDocValuesEnum extends TermsEnum {
       int currentOrd;
       int currentBlockNumber;
       int end;  // end position in the current block
@@ -1007,7 +1014,7 @@ class FieldCacheImpl implements FieldCac
 
       final BytesRef term = new BytesRef();
 
-      public DocTermsIndexEnum() {
+      public SortedDocValuesEnum() {
         currentOrd = -1;
         currentBlockNumber = 0;
         blocks = bytes.getBlocks();
@@ -1043,8 +1050,9 @@ class FieldCacheImpl implements FieldCac
         }
       }
 
+      @Override
       public void seekExact(long ord) throws IOException {
-        assert ord >= 0 && ord <= numOrd;
+        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];
@@ -1140,16 +1148,16 @@ class FieldCacheImpl implements FieldCac
   // nocommit woudl be nice if .getTErms would return a
   // DocTermsIndex if one already existed
 
-  public DocTermsIndex getTermsIndex(AtomicReader reader, String field) throws IOException {
+  public SortedDocValues getTermsIndex(AtomicReader reader, String field) throws IOException {
     return getTermsIndex(reader, field, PackedInts.FAST);
   }
 
-  public DocTermsIndex getTermsIndex(AtomicReader reader, String field, float acceptableOverheadRatio) throws IOException {
-    return (DocTermsIndex) caches.get(DocTermsIndex.class).get(reader, new CacheKey(field, acceptableOverheadRatio), false);
+  public SortedDocValues getTermsIndex(AtomicReader reader, String field, float acceptableOverheadRatio) throws IOException {
+    return (SortedDocValues) caches.get(SortedDocValues.class).get(reader, new CacheKey(field, acceptableOverheadRatio), false);
   }
 
-  static class DocTermsIndexCache extends Cache {
-    DocTermsIndexCache(FieldCacheImpl wrapper) {
+  static class SortedDocValuesCache extends Cache {
+    SortedDocValuesCache(FieldCacheImpl wrapper) {
       super(wrapper);
     }
 
@@ -1160,36 +1168,7 @@ class FieldCacheImpl implements FieldCac
       final int maxDoc = reader.maxDoc();
       SortedDocValues valuesIn = reader.getSortedDocValues(key.field);
       if (valuesIn != null) {
-        final SortedDocValues ramInstance = valuesIn.newRAMInstance();
-        return new DocTermsIndex() {
-
-          @Override
-          public BytesRef lookup(int ord, BytesRef reuse) {
-            ramInstance.lookupOrd(ord, reuse);
-            return reuse;
-          }
-
-          @Override
-          public int getOrd(int docID) {
-            return ramInstance.getOrd(docID);
-          }
-
-          @Override
-          public int numOrd() {
-            return ramInstance.getValueCount();
-          }
-
-          @Override
-          public int size() {
-            return ramInstance.size();
-          }
-
-          @Override
-          public TermsEnum getTermsEnum() {
-            // nocommit: to the codec api? or can that termsenum just use this thing?
-            return null;
-          }
-        };
+        return valuesIn.newRAMInstance();
       } else {
 
         Terms terms = reader.terms(key.field);
@@ -1283,7 +1262,7 @@ class FieldCacheImpl implements FieldCac
         }
 
         // maybe an int-only impl?
-        return new DocTermsIndexImpl(bytes.freeze(true), termOrdToBytesOffset.getMutable(), docToTermOrd.getMutable(), termOrd);
+        return new SortedDocValuesImpl(bytes.freeze(true), termOrdToBytesOffset.getMutable(), docToTermOrd.getMutable(), termOrd);
       }
     }
   }

Modified: lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCacheRangeFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCacheRangeFilter.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCacheRangeFilter.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCacheRangeFilter.java Sat Nov 24 13:13:51 2012
@@ -18,15 +18,16 @@ package org.apache.lucene.search;
 
 import java.io.IOException;
 
-import org.apache.lucene.index.AtomicReader; // for javadocs
-import org.apache.lucene.index.AtomicReaderContext;
-import org.apache.lucene.document.IntField; // for javadocs
+import org.apache.lucene.document.DoubleField; // for javadocs
 import org.apache.lucene.document.FloatField; // for javadocs
+import org.apache.lucene.document.IntField; // for javadocs
 import org.apache.lucene.document.LongField; // for javadocs
-import org.apache.lucene.document.DoubleField; // for javadocs
-import org.apache.lucene.util.NumericUtils;
+import org.apache.lucene.index.AtomicReader; // for javadocs
+import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.NumericUtils;
 
 /**
  * A range filter built on top of a cached single term field (in {@link FieldCache}).
@@ -89,10 +90,10 @@ public abstract class FieldCacheRangeFil
     return new FieldCacheRangeFilter<String>(field, null, lowerVal, upperVal, includeLower, includeUpper) {
       @Override
       public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {
-        final FieldCache.DocTermsIndex fcsi = FieldCache.DEFAULT.getTermsIndex(context.reader(), field);
+        final SortedDocValues fcsi = FieldCache.DEFAULT.getTermsIndex(context.reader(), field);
         final BytesRef spare = new BytesRef();
-        final int lowerPoint = lowerVal == null ? -1 : fcsi.binarySearchLookup(new BytesRef(lowerVal), spare);
-        final int upperPoint = upperVal == null ? -1 : fcsi.binarySearchLookup(new BytesRef(upperVal), spare);
+        final int lowerPoint = lowerVal == null ? -1 : fcsi.lookupTerm(new BytesRef(lowerVal), spare);
+        final int upperPoint = upperVal == null ? -1 : fcsi.lookupTerm(new BytesRef(upperVal), spare);
 
         final int inclusiveLowerPoint, inclusiveUpperPoint;
 

Modified: lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCacheTermsFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCacheTermsFilter.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCacheTermsFilter.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldCacheTermsFilter.java Sat Nov 24 13:13:51 2012
@@ -22,9 +22,10 @@ import java.io.IOException;
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.index.DocsEnum; // javadoc @link
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.util.FixedBitSet;
+import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.FixedBitSet;
 
 /**
  * A {@link Filter} that only accepts documents whose single
@@ -118,11 +119,11 @@ public class FieldCacheTermsFilter exten
 
   @Override
   public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {
-    final FieldCache.DocTermsIndex fcsi = getFieldCache().getTermsIndex(context.reader(), field);
-    final FixedBitSet bits = new FixedBitSet(fcsi.numOrd());
+    final SortedDocValues fcsi = getFieldCache().getTermsIndex(context.reader(), field);
+    final FixedBitSet bits = new FixedBitSet(fcsi.getValueCount());
     final BytesRef spare = new BytesRef();
     for (int i=0;i<terms.length;i++) {
-      int ord = fcsi.binarySearchLookup(terms[i], spare);
+      int ord = fcsi.lookupTerm(terms[i], spare);
       if (ord >= 0) {
         bits.set(ord);
       }

Modified: lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldComparator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldComparator.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldComparator.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/search/FieldComparator.java Sat Nov 24 13:13:51 2012
@@ -23,9 +23,9 @@ import java.util.Comparator;
 import org.apache.lucene.index.AtomicReader; // javadocs
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.index.DocValues;
+import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.search.FieldCache.ByteParser;
 import org.apache.lucene.search.FieldCache.DocTerms;
-import org.apache.lucene.search.FieldCache.DocTermsIndex;
 import org.apache.lucene.search.FieldCache.DoubleParser;
 import org.apache.lucene.search.FieldCache.FloatParser;
 import org.apache.lucene.search.FieldCache.IntParser;
@@ -1096,7 +1096,7 @@ public abstract class FieldComparator<T>
 
     /* Current reader's doc ord/values.
        @lucene.internal */
-    DocTermsIndex termsIndex;
+    SortedDocValues termsIndex;
 
     private final String field;
 
@@ -1159,8 +1159,8 @@ public abstract class FieldComparator<T>
 
     @Override
     public int compareDocToValue(int doc, BytesRef value) {
-      BytesRef docValue = termsIndex.getTerm(doc, tempBR);
-      if (docValue == null) {
+      int ord = termsIndex.getOrd(doc);
+      if (ord == -1) {
         if (value == null) {
           return 0;
         }
@@ -1168,12 +1168,10 @@ public abstract class FieldComparator<T>
       } else if (value == null) {
         return 1;
       }
-      return docValue.compareTo(value);
+      termsIndex.lookupOrd(ord, tempBR);
+      return tempBR.compareTo(value);
     }
 
-    // nocommit remove null from FC DocTerms/Index as an
-    // allowed value
-
     /** Base class for specialized (per bit width of the
      * ords) per-segment comparator.  NOTE: this is messy;
      * we do this only because hotspot can't reliably inline
@@ -1223,10 +1221,10 @@ public abstract class FieldComparator<T>
 
     // Used per-segment when docToOrd is null:
     private final class AnyOrdComparator extends PerSegmentComparator {
-      private final DocTermsIndex termsIndex;
+      private final SortedDocValues termsIndex;
       private final int docBase;
 
-      public AnyOrdComparator(DocTermsIndex termsIndex, int docBase) {
+      public AnyOrdComparator(SortedDocValues termsIndex, int docBase) {
         this.termsIndex = termsIndex;
         this.docBase = docBase;
       }
@@ -1259,7 +1257,7 @@ public abstract class FieldComparator<T>
           if (values[slot] == null) {
             values[slot] = new BytesRef();
           }
-          termsIndex.lookup(ord, values[slot]);
+          termsIndex.lookupOrd(ord, values[slot]);
         }
         readerGen[slot] = currentReaderGen;
       }
@@ -1294,7 +1292,7 @@ public abstract class FieldComparator<T>
           bottomSameReader = true;
           readerGen[bottomSlot] = currentReaderGen;
         } else {
-          final int index = binarySearch(tempBR, termsIndex, bottomValue);
+          final int index = termsIndex.lookupTerm(bottomValue, tempBR);
           if (index < 0) {
             bottomOrd = -index - 2;
             bottomSameReader = false;
@@ -1912,31 +1910,4 @@ public abstract class FieldComparator<T>
       return docTerms.getBytes(doc, tempBR).compareTo(value);
     }
   }
-
-  // nocommit why do we have this AND DTI.binarySearch?
-  final protected static int binarySearch(BytesRef br, DocTermsIndex a, BytesRef key) {
-    return binarySearch(br, a, key, 0, a.numOrd()-1);
-  }
-
-  final protected static int binarySearch(BytesRef br, DocTermsIndex a, BytesRef key, int low, int high) {
-
-    while (low <= high) {
-      int mid = (low + high) >>> 1;
-      BytesRef midVal = a.lookup(mid, br);
-      int cmp;
-      if (midVal != null) {
-        cmp = midVal.compareTo(key);
-      } else {
-        cmp = -1;
-      }
-
-      if (cmp < 0)
-        low = mid + 1;
-      else if (cmp > 0)
-        high = mid - 1;
-      else
-        return mid;
-    }
-    return -(low + 1);
-  }
 }

Modified: lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java Sat Nov 24 13:13:51 2012
@@ -1627,10 +1627,12 @@ public class TestIndexWriter extends Luc
     w.close();
     assertEquals(1, reader.docFreq(new Term("content", bigTerm)));
 
-    FieldCache.DocTermsIndex dti = FieldCache.DEFAULT.getTermsIndex(SlowCompositeReaderWrapper.wrap(reader), "content", random().nextFloat() * PackedInts.FAST);
-    assertEquals(4, dti.numOrd());
+    SortedDocValues dti = FieldCache.DEFAULT.getTermsIndex(SlowCompositeReaderWrapper.wrap(reader), "content", random().nextFloat() * PackedInts.FAST);
+    assertEquals(4, dti.getValueCount());
     assertEquals(4, dti.size());
-    assertEquals(bigTermBytesRef, dti.lookup(2, new BytesRef()));
+    BytesRef br = new BytesRef();
+    dti.lookupOrd(2, br);
+    assertEquals(bigTermBytesRef, br);
     reader.close();
     dir.close();
   }

Modified: lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/search/FieldCacheRewriteMethod.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/search/FieldCacheRewriteMethod.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/search/FieldCacheRewriteMethod.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/search/FieldCacheRewriteMethod.java Sat Nov 24 13:13:51 2012
@@ -22,6 +22,7 @@ import java.util.Comparator;
 
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.util.Bits;
@@ -88,9 +89,9 @@ public final class FieldCacheRewriteMeth
      */
     @Override
     public DocIdSet getDocIdSet(AtomicReaderContext context, final Bits acceptDocs) throws IOException {
-      final FieldCache.DocTermsIndex fcsi = FieldCache.DEFAULT.getTermsIndex(context.reader(), query.field);
+      final SortedDocValues fcsi = FieldCache.DEFAULT.getTermsIndex(context.reader(), query.field);
       // Cannot use FixedBitSet because we require long index (ord):
-      final OpenBitSet termSet = new OpenBitSet(fcsi.numOrd());
+      final OpenBitSet termSet = new OpenBitSet(fcsi.getValueCount());
       TermsEnum termsEnum = query.getTermsEnum(new Terms() {
         
         @Override

Modified: lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/search/TestElevationComparator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/search/TestElevationComparator.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/search/TestElevationComparator.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/search/TestElevationComparator.java Sat Nov 24 13:13:51 2012
@@ -142,7 +142,7 @@ class ElevationComparatorSource extends 
   public FieldComparator<Integer> newComparator(final String fieldname, final int numHits, int sortPos, boolean reversed) throws IOException {
    return new FieldComparator<Integer>() {
 
-     FieldCache.DocTermsIndex idIndex;
+     SortedDocValues idIndex;
      private final int[] values = new int[numHits];
      private final BytesRef tempBR = new BytesRef();
      int bottomVal;
@@ -162,8 +162,8 @@ class ElevationComparatorSource extends 
        if (ord == -1) {
          return 0;
        } else {
-         BytesRef id = idIndex.lookup(ord, tempBR);
-         Integer prio = priority.get(id);
+         idIndex.lookupOrd(ord, tempBR);
+         Integer prio = priority.get(tempBR);
          return prio == null ? 0 : prio.intValue();
        }
      }

Modified: lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/search/TestFieldCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/search/TestFieldCache.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/search/TestFieldCache.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/search/TestFieldCache.java Sat Nov 24 13:13:51 2012
@@ -188,35 +188,42 @@ public class TestFieldCache extends Luce
     }
 
     // getTermsIndex
-    FieldCache.DocTermsIndex termsIndex = cache.getTermsIndex(reader, "theRandomUnicodeString");
+    SortedDocValues termsIndex = cache.getTermsIndex(reader, "theRandomUnicodeString");
     assertSame("Second request to cache return same array", termsIndex, cache.getTermsIndex(reader, "theRandomUnicodeString"));
     assertTrue("doubles Size: " + termsIndex.size() + " is not: " + NUM_DOCS, termsIndex.size() == NUM_DOCS);
     final BytesRef br = new BytesRef();
     for (int i = 0; i < NUM_DOCS; i++) {
-      final BytesRef term = termsIndex.getTerm(i, br);
+      final BytesRef term;
+      final int ord = termsIndex.getOrd(i);
+      if (ord == -1) {
+        term = null;
+      } else {
+        termsIndex.lookupOrd(ord, br);
+        term = br;
+      }
       final String s = term == null ? null : term.utf8ToString();
       assertTrue("for doc " + i + ": " + s + " does not equal: " + unicodeStrings[i], unicodeStrings[i] == null || unicodeStrings[i].equals(s));
     }
 
-    int nTerms = termsIndex.numOrd();
+    int nTerms = termsIndex.getValueCount();
     // System.out.println("nTerms="+nTerms);
 
     TermsEnum tenum = termsIndex.getTermsEnum();
     BytesRef val = new BytesRef();
     for (int i=0; i<nTerms; i++) {
       BytesRef val1 = tenum.next();
-      BytesRef val2 = termsIndex.lookup(i,val);
+      termsIndex.lookupOrd(i, val);
       // System.out.println("i="+i);
-      assertEquals(val2, val1);
+      assertEquals(val, val1);
     }
 
     // seek the enum around (note this isn't a great test here)
     int num = atLeast(100);
     for (int i = 0; i < num; i++) {
       int k = _TestUtil.nextInt(random(), 1, nTerms-1);
-      BytesRef val1 = termsIndex.lookup(k, val);
-      assertEquals(TermsEnum.SeekStatus.FOUND, tenum.seekCeil(val1));
-      assertEquals(val1, tenum.term());
+      termsIndex.lookupOrd(k, val);
+      assertEquals(TermsEnum.SeekStatus.FOUND, tenum.seekCeil(val));
+      assertEquals(val, tenum.term());
     }
     
     // test bad field

Modified: lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java (original)
+++ lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java Sat Nov 24 13:13:51 2012
@@ -17,15 +17,16 @@ package org.apache.lucene.search.groupin
  * limitations under the License.
  */
 
+import java.io.IOException;
+import java.util.*;
+
 import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.search.*;
 import org.apache.lucene.search.grouping.AbstractAllGroupHeadsCollector;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.SentinelIntSet;
 
-import java.io.IOException;
-import java.util.*;
-
 /**
  * A base implementation of {@link org.apache.lucene.search.grouping.AbstractAllGroupHeadsCollector} for retrieving the most relevant groups when grouping
  * on a string based group field. More specifically this all concrete implementations of this base implementation
@@ -40,7 +41,7 @@ public abstract class TermAllGroupHeadsC
   final String groupField;
   final BytesRef scratchBytesRef = new BytesRef();
 
-  FieldCache.DocTermsIndex groupIndex;
+  SortedDocValues groupIndex;
   AtomicReaderContext readerContext;
 
   protected TermAllGroupHeadsCollector(String groupField, int numberOfSorts) {
@@ -124,7 +125,13 @@ public abstract class TermAllGroupHeadsC
 
     protected void retrieveGroupHeadAndAddIfNotExist(int doc) throws IOException {
       final int ord = groupIndex.getOrd(doc);
-      final BytesRef groupValue = ord == -1 ? null : groupIndex.lookup(ord, scratchBytesRef);
+      final BytesRef groupValue;
+      if (ord == -1) {
+        groupValue = null;
+      } else {
+        groupIndex.lookupOrd(ord, scratchBytesRef);
+        groupValue = scratchBytesRef;
+      }
       GroupHead groupHead = groups.get(groupValue);
       if (groupHead == null) {
         groupHead = new GroupHead(groupValue, sortWithinGroup, doc);
@@ -199,7 +206,7 @@ public abstract class TermAllGroupHeadsC
     private final List<GroupHead> collectedGroups;
     private final SortField[] fields;
 
-    private FieldCache.DocTermsIndex[] sortsIndex;
+    private SortedDocValues[] sortsIndex;
     private Scorer scorer;
     private GroupHead[] segmentGroupHeads;
 
@@ -210,7 +217,7 @@ public abstract class TermAllGroupHeadsC
 
       final SortField[] sortFields = sortWithinGroup.getSort();
       fields = new SortField[sortFields.length];
-      sortsIndex = new FieldCache.DocTermsIndex[sortFields.length];
+      sortsIndex = new SortedDocValues[sortFields.length];
       for (int i = 0; i < sortFields.length; i++) {
         reversed[i] = sortFields[i].getReverse() ? -1 : 1;
         fields[i] = sortFields[i];
@@ -230,7 +237,13 @@ public abstract class TermAllGroupHeadsC
       GroupHead groupHead;
       if (!ordSet.exists(key)) {
         ordSet.put(key);
-        BytesRef term = key == -1 ? null : groupIndex.getTerm(doc, new BytesRef());
+        BytesRef term;
+        if (key == -1) {
+          term = null;
+        } else {
+          term = new BytesRef();
+          groupIndex.lookupOrd(key, term);
+        }
         groupHead = new GroupHead(doc, term);
         collectedGroups.add(groupHead);
         segmentGroupHeads[key+1] = groupHead;
@@ -255,13 +268,13 @@ public abstract class TermAllGroupHeadsC
 
       // Clear ordSet and fill it with previous encountered groups that can occur in the current segment.
       ordSet.clear();
-      segmentGroupHeads = new GroupHead[groupIndex.numOrd()+1];
+      segmentGroupHeads = new GroupHead[groupIndex.getValueCount()+1];
       for (GroupHead collectedGroup : collectedGroups) {
         int ord;
         if (collectedGroup.groupValue == null) {
           ord = -1;
         } else {
-          ord = groupIndex.binarySearchLookup(collectedGroup.groupValue, scratchBytesRef);
+          ord = groupIndex.lookupTerm(collectedGroup.groupValue, scratchBytesRef);
         }
         if (collectedGroup.groupValue == null || ord >= 0) {
           ordSet.put(ord);
@@ -275,7 +288,7 @@ public abstract class TermAllGroupHeadsC
             if (collectedGroup.sortValues[i] == null) {
               sortOrd = -1;
             } else {
-              sortOrd = sortsIndex[i].binarySearchLookup(collectedGroup.sortValues[i], scratchBytesRef);
+              sortOrd = sortsIndex[i].lookupTerm(collectedGroup.sortValues[i], scratchBytesRef);
             }
             collectedGroup.sortOrds[i] = sortOrd;
           }
@@ -301,7 +314,7 @@ public abstract class TermAllGroupHeadsC
             sortOrds[i] = sortsIndex[i].getOrd(doc);
             sortValues[i] = new BytesRef();
             if (sortOrds[i] != -1) {
-              sortValues[i] = sortsIndex[i].getTerm(doc, sortValues[i]);
+              sortsIndex[i].get(doc, sortValues[i]);
             }
           }
         }
@@ -322,7 +335,7 @@ public abstract class TermAllGroupHeadsC
             if (sortsIndex[compIDX].getOrd(doc) == -1) {
               scratchBytesRef.length = 0;
             } else {
-              sortsIndex[compIDX].getTerm(doc, scratchBytesRef);
+              sortsIndex[compIDX].get(doc, scratchBytesRef);
             }
             return sortValues[compIDX].compareTo(scratchBytesRef);
           } else {
@@ -340,7 +353,7 @@ public abstract class TermAllGroupHeadsC
             if (sortOrds[i] == -1) {
               sortValues[i].length = 0;
             } else {
-              sortValues[i] = sortsIndex[i].getTerm(doc, sortValues[i]);
+              sortsIndex[i].get(doc, sortValues[i]);
             }
           }
         }
@@ -357,7 +370,7 @@ public abstract class TermAllGroupHeadsC
     private final List<GroupHead> collectedGroups;
     private final SortField[] fields;
 
-    private FieldCache.DocTermsIndex[] sortsIndex;
+    private SortedDocValues[] sortsIndex;
     private GroupHead[] segmentGroupHeads;
 
     OrdAllGroupHeadsCollector(String groupField, Sort sortWithinGroup, int initialSize) {
@@ -367,7 +380,7 @@ public abstract class TermAllGroupHeadsC
 
       final SortField[] sortFields = sortWithinGroup.getSort();
       fields = new SortField[sortFields.length];
-      sortsIndex = new FieldCache.DocTermsIndex[sortFields.length];
+      sortsIndex = new SortedDocValues[sortFields.length];
       for (int i = 0; i < sortFields.length; i++) {
         reversed[i] = sortFields[i].getReverse() ? -1 : 1;
         fields[i] = sortFields[i];
@@ -386,7 +399,13 @@ public abstract class TermAllGroupHeadsC
       GroupHead groupHead;
       if (!ordSet.exists(key)) {
         ordSet.put(key);
-        BytesRef term = key == -1 ? null : groupIndex.getTerm(doc, new BytesRef());
+        BytesRef term;
+        if (key == -1) {
+          term = null;
+        } else {
+          term = new BytesRef();
+          groupIndex.lookupOrd(key, term);
+        }
         groupHead = new GroupHead(doc, term);
         collectedGroups.add(groupHead);
         segmentGroupHeads[key+1] = groupHead;
@@ -407,13 +426,13 @@ public abstract class TermAllGroupHeadsC
 
       // Clear ordSet and fill it with previous encountered groups that can occur in the current segment.
       ordSet.clear();
-      segmentGroupHeads = new GroupHead[groupIndex.numOrd()+1];
+      segmentGroupHeads = new GroupHead[groupIndex.getValueCount()+1];
       for (GroupHead collectedGroup : collectedGroups) {
         int groupOrd;
         if (collectedGroup.groupValue == null) {
           groupOrd = -1;
         } else {
-          groupOrd = groupIndex.binarySearchLookup(collectedGroup.groupValue, scratchBytesRef);
+          groupOrd = groupIndex.lookupTerm(collectedGroup.groupValue, scratchBytesRef);
         }
         if (collectedGroup.groupValue == null || groupOrd >= 0) {
           ordSet.put(groupOrd);
@@ -424,7 +443,7 @@ public abstract class TermAllGroupHeadsC
             if (collectedGroup.sortOrds[i] == -1) {
               sortOrd = -1;
             } else {
-              sortOrd = sortsIndex[i].binarySearchLookup(collectedGroup.sortValues[i], scratchBytesRef);
+              sortOrd = sortsIndex[i].lookupTerm(collectedGroup.sortValues[i], scratchBytesRef);
             }
             collectedGroup.sortOrds[i] = sortOrd;
           }
@@ -445,7 +464,7 @@ public abstract class TermAllGroupHeadsC
           sortOrds[i] = sortsIndex[i].getOrd(doc);
           sortValues[i] = new BytesRef();
           if (sortOrds[i] != -1) {
-            sortsIndex[i].getTerm(doc, sortValues[i]);
+            sortsIndex[i].get(doc, sortValues[i]);
           }
         }
       }
@@ -456,7 +475,7 @@ public abstract class TermAllGroupHeadsC
           if (sortsIndex[compIDX].getOrd(doc) == -1) {
             scratchBytesRef.length = 0;
           } else {
-            sortsIndex[compIDX].getTerm(doc, scratchBytesRef);
+            sortsIndex[compIDX].get(doc, scratchBytesRef);
           }
           return sortValues[compIDX].compareTo(scratchBytesRef);
         } else {
@@ -470,7 +489,7 @@ public abstract class TermAllGroupHeadsC
           if (sortOrds[i] == -1) {
             sortValues[i].length = 0;
           } else {
-            sortValues[i] = sortsIndex[i].getTerm(doc, sortValues[i]);
+            sortsIndex[i].lookupOrd(sortOrds[i], sortValues[i]);
           }
         }
         this.doc = doc + readerContext.docBase;
@@ -517,7 +536,13 @@ public abstract class TermAllGroupHeadsC
       GroupHead groupHead;
       if (!ordSet.exists(key)) {
         ordSet.put(key);
-        BytesRef term = key == -1 ? null : groupIndex.getTerm(doc, new BytesRef());
+        BytesRef term;
+        if (key == -1) {
+          term = null;
+        } else {
+          term = new BytesRef();
+          groupIndex.lookupOrd(key, term);
+        }
         groupHead = new GroupHead(doc, term);
         collectedGroups.add(groupHead);
         segmentGroupHeads[key+1] = groupHead;
@@ -535,13 +560,13 @@ public abstract class TermAllGroupHeadsC
 
       // Clear ordSet and fill it with previous encountered groups that can occur in the current segment.
       ordSet.clear();
-      segmentGroupHeads = new GroupHead[groupIndex.numOrd()+1];
+      segmentGroupHeads = new GroupHead[groupIndex.getValueCount()+1];
       for (GroupHead collectedGroup : collectedGroups) {
         int ord;
         if (collectedGroup.groupValue == null) {
           ord = -1;
         } else {
-          ord = groupIndex.binarySearchLookup(collectedGroup.groupValue, scratchBytesRef);
+          ord = groupIndex.lookupTerm(collectedGroup.groupValue, scratchBytesRef);
         }
         if (collectedGroup.groupValue == null || ord >= 0) {
           ordSet.put(ord);

Modified: lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupsCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupsCollector.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupsCollector.java (original)
+++ lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupsCollector.java Sat Nov 24 13:13:51 2012
@@ -17,18 +17,18 @@ package org.apache.lucene.search.groupin
  * limitations under the License.
  */
 
-import org.apache.lucene.index.AtomicReaderContext;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.FieldCache;
-import org.apache.lucene.search.grouping.AbstractAllGroupsCollector;
-import org.apache.lucene.util.SentinelIntSet;
-import org.apache.lucene.util.BytesRef;
-
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.SortedDocValues;
+import org.apache.lucene.search.FieldCache;
+import org.apache.lucene.search.grouping.AbstractAllGroupsCollector;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.SentinelIntSet;
+
 /**
  * A collector that collects all groups that match the
  * query. Only the group value is collected, and the order
@@ -52,7 +52,7 @@ public class TermAllGroupsCollector exte
   private final SentinelIntSet ordSet;
   private final List<BytesRef> groups;
 
-  private FieldCache.DocTermsIndex index;
+  private SortedDocValues index;
   private final BytesRef spareBytesRef = new BytesRef();
 
   /**
@@ -87,7 +87,13 @@ public class TermAllGroupsCollector exte
     int key = index.getOrd(doc);
     if (!ordSet.exists(key)) {
       ordSet.put(key);
-      BytesRef term = key == -1 ? null : index.lookup(key, new BytesRef());
+      BytesRef term;
+      if (key == -1) {
+        term = null;
+      } else {
+        term =  new BytesRef();
+        index.lookupOrd(key, term);
+      }
       groups.add(term);
     }
   }
@@ -107,7 +113,7 @@ public class TermAllGroupsCollector exte
       if (countedGroup == null) {
         ordSet.put(-1);
       } else {
-        int ord = index.binarySearchLookup(countedGroup, spareBytesRef);
+        int ord = index.lookupTerm(countedGroup, spareBytesRef);
         if (ord >= 0) {
           ordSet.put(ord);
         }

Modified: lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermDistinctValuesCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermDistinctValuesCollector.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermDistinctValuesCollector.java (original)
+++ lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermDistinctValuesCollector.java Sat Nov 24 13:13:51 2012
@@ -17,20 +17,20 @@ package org.apache.lucene.search.groupin
  * limitations under the License.
  */
 
+import java.io.IOException;
+import java.util.*;
+
 import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.search.FieldCache;
-import org.apache.lucene.search.FieldCache.DocTermsIndex; // javadocs
 import org.apache.lucene.search.grouping.AbstractDistinctValuesCollector;
 import org.apache.lucene.search.grouping.SearchGroup;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.SentinelIntSet;
 
-import java.io.IOException;
-import java.util.*;
-
 /**
  * A term based implementation of {@link org.apache.lucene.search.grouping.AbstractDistinctValuesCollector} that relies
- * on {@link DocTermsIndex} to count the distinct values per group.
+ * on {@link SortedDocValues} to count the distinct values per group.
  *
  * @lucene.experimental
  */
@@ -43,8 +43,8 @@ public class TermDistinctValuesCollector
   private final GroupCount groupCounts[];
   private final BytesRef spare = new BytesRef();
 
-  private FieldCache.DocTermsIndex groupFieldTermIndex;
-  private FieldCache.DocTermsIndex countFieldTermIndex;
+  private SortedDocValues groupFieldTermIndex;
+  private SortedDocValues countFieldTermIndex;
 
   /**
    * Constructs {@link TermDistinctValuesCollector} instance.
@@ -69,7 +69,6 @@ public class TermDistinctValuesCollector
     if (slot < 0) {
       return;
     }
-    int groupOrd = groupFieldTermIndex.getOrd(doc);
 
     GroupCount gc = groupCounts[slot];
     int countOrd = countFieldTermIndex.getOrd(doc);
@@ -77,7 +76,9 @@ public class TermDistinctValuesCollector
       if (countOrd == -1) {
         gc.uniqueValues.add(null);
       } else {
-        gc.uniqueValues.add(countFieldTermIndex.lookup(countOrd, new BytesRef()));
+        BytesRef br = new BytesRef();
+        countFieldTermIndex.lookupOrd(countOrd, br);
+        gc.uniqueValues.add(br);
       }
 
       gc.ords = Arrays.copyOf(gc.ords, gc.ords.length + 1);
@@ -107,7 +108,7 @@ public class TermDistinctValuesCollector
     ordSet.clear();
     BytesRef scratch = new BytesRef();
     for (GroupCount group : groups) {
-      int groupOrd = group.groupValue == null ? -1 : groupFieldTermIndex.binarySearchLookup(group.groupValue, spare);
+      int groupOrd = group.groupValue == null ? -1 : groupFieldTermIndex.lookupTerm(group.groupValue, spare);
       if (group.groupValue != null && groupOrd < 0) {
         continue;
       }
@@ -117,7 +118,7 @@ public class TermDistinctValuesCollector
       Arrays.fill(group.ords, -2);
       int i = 0;
       for (BytesRef value : group.uniqueValues) {
-        int countOrd = value == null ? -1 : countFieldTermIndex.binarySearchLookup(value, scratch);
+        int countOrd = value == null ? -1 : countFieldTermIndex.lookupTerm(value, scratch);
         if (value == null || countOrd >= 0) {
           group.ords[i++] = countOrd;
         }

Modified: lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermFirstPassGroupingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermFirstPassGroupingCollector.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermFirstPassGroupingCollector.java (original)
+++ lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermFirstPassGroupingCollector.java Sat Nov 24 13:13:51 2012
@@ -17,14 +17,15 @@ package org.apache.lucene.search.groupin
  * limitations under the License.
  */
 
+import java.io.IOException;
+
 import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.search.FieldCache;
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.grouping.AbstractFirstPassGroupingCollector;
 import org.apache.lucene.util.BytesRef;
 
-import java.io.IOException;
-
 /**
  * Concrete implementation of {@link org.apache.lucene.search.grouping.AbstractFirstPassGroupingCollector} that groups based on
  * field values and more specifically uses {@link org.apache.lucene.search.FieldCache.DocTermsIndex}
@@ -35,7 +36,7 @@ import java.io.IOException;
 public class TermFirstPassGroupingCollector extends AbstractFirstPassGroupingCollector<BytesRef> {
 
   private final BytesRef scratchBytesRef = new BytesRef();
-  private FieldCache.DocTermsIndex index;
+  private SortedDocValues index;
 
   private String groupField;
 
@@ -63,7 +64,12 @@ public class TermFirstPassGroupingCollec
   @Override
   protected BytesRef getDocGroupValue(int doc) {
     final int ord = index.getOrd(doc);
-    return ord == -1 ? null : index.lookup(ord, scratchBytesRef);
+    if (ord == -1) {
+      return null;
+    } else {
+      index.lookupOrd(ord, scratchBytesRef);
+      return scratchBytesRef;
+    }
   }
 
   @Override

Modified: lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java (original)
+++ lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java Sat Nov 24 13:13:51 2012
@@ -17,17 +17,18 @@ package org.apache.lucene.search.groupin
  * limitations under the License.
  */
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.index.DocTermOrds;
+import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.search.FieldCache;
 import org.apache.lucene.search.grouping.AbstractGroupFacetCollector;
 import org.apache.lucene.util.*;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * An implementation of {@link AbstractGroupFacetCollector} that computes grouped facets based on the indexed terms
  * from the {@link FieldCache}.
@@ -40,7 +41,7 @@ public abstract class TermGroupFacetColl
   final SentinelIntSet segmentGroupedFacetHits;
   final BytesRef spare = new BytesRef();
 
-  FieldCache.DocTermsIndex groupFieldTermsIndex;
+  SortedDocValues groupFieldTermsIndex;
 
   /**
    * Factory method for creating the right implementation based on the fact whether the facet field contains
@@ -76,7 +77,7 @@ public abstract class TermGroupFacetColl
   // Implementation for single valued facet fields.
   static class SV extends TermGroupFacetCollector {
 
-    private FieldCache.DocTermsIndex facetFieldTermsIndex;
+    private SortedDocValues facetFieldTermsIndex;
 
     SV(String groupField, String facetField, BytesRef facetPrefix, int initialSize) {
       super(groupField, facetField, facetPrefix, initialSize);
@@ -89,7 +90,7 @@ public abstract class TermGroupFacetColl
       }
 
       int groupOrd = groupFieldTermsIndex.getOrd(doc);
-      int segmentGroupedFacetsIndex = groupOrd * (facetFieldTermsIndex.numOrd()+1) + facetOrd;
+      int segmentGroupedFacetsIndex = groupOrd * (facetFieldTermsIndex.getValueCount()+1) + facetOrd;
       if (segmentGroupedFacetHits.exists(segmentGroupedFacetsIndex)) {
         return;
       }
@@ -98,12 +99,24 @@ public abstract class TermGroupFacetColl
       segmentFacetCounts[facetOrd+1]++;
 
       segmentGroupedFacetHits.put(segmentGroupedFacetsIndex);
-      groupedFacetHits.add(
-          new GroupedFacetHit(
-              groupOrd == -1 ? null : groupFieldTermsIndex.lookup(groupOrd, new BytesRef()),
-              facetOrd == -1 ? null : facetFieldTermsIndex.lookup(facetOrd, new BytesRef())
-          )
-      );
+
+      BytesRef groupKey;
+      if (groupOrd == -1) {
+        groupKey = null;
+      } else {
+        groupKey = new BytesRef();
+        groupFieldTermsIndex.lookupOrd(groupOrd, groupKey);
+      }
+
+      BytesRef facetKey;
+      if (facetOrd == -1) {
+        facetKey = null;
+      } else {
+        facetKey = new BytesRef();
+        facetFieldTermsIndex.lookupOrd(facetOrd, facetKey);
+      }
+
+      groupedFacetHits.add(new GroupedFacetHit(groupKey, facetKey));
     }
 
     public void setNextReader(AtomicReaderContext context) throws IOException {
@@ -115,39 +128,39 @@ public abstract class TermGroupFacetColl
       facetFieldTermsIndex = FieldCache.DEFAULT.getTermsIndex(context.reader(), facetField);
 
       // 1+ to allow for the -1 "not set":
-      segmentFacetCounts = new int[facetFieldTermsIndex.numOrd()+1];
+      segmentFacetCounts = new int[facetFieldTermsIndex.getValueCount()+1];
       segmentTotalCount = 0;
 
       segmentGroupedFacetHits.clear();
       for (GroupedFacetHit groupedFacetHit : groupedFacetHits) {
-        int facetOrd = groupedFacetHit.facetValue == null ? -1 : facetFieldTermsIndex.binarySearchLookup(groupedFacetHit.facetValue, spare);
+        int facetOrd = groupedFacetHit.facetValue == null ? -1 : facetFieldTermsIndex.lookupTerm(groupedFacetHit.facetValue, spare);
         if (groupedFacetHit.facetValue != null && facetOrd < 0) {
           continue;
         }
 
-        int groupOrd = groupedFacetHit.groupValue == null ? -1 : groupFieldTermsIndex.binarySearchLookup(groupedFacetHit.groupValue, spare);
+        int groupOrd = groupedFacetHit.groupValue == null ? -1 : groupFieldTermsIndex.lookupTerm(groupedFacetHit.groupValue, spare);
         if (groupedFacetHit.groupValue != null && groupOrd < 0) {
           continue;
         }
 
-        int segmentGroupedFacetsIndex = groupOrd * (facetFieldTermsIndex.numOrd()+1) + facetOrd;
+        int segmentGroupedFacetsIndex = groupOrd * (facetFieldTermsIndex.getValueCount()+1) + facetOrd;
         segmentGroupedFacetHits.put(segmentGroupedFacetsIndex);
       }
 
       if (facetPrefix != null) {
-        startFacetOrd = facetFieldTermsIndex.binarySearchLookup(facetPrefix, spare);
+        startFacetOrd = facetFieldTermsIndex.lookupTerm(facetPrefix, spare);
         if (startFacetOrd < 0) {
           // Points to the ord one higher than facetPrefix
           startFacetOrd = -startFacetOrd - 1;
         }
         BytesRef facetEndPrefix = BytesRef.deepCopyOf(facetPrefix);
         facetEndPrefix.append(UnicodeUtil.BIG_TERM);
-        endFacetOrd = facetFieldTermsIndex.binarySearchLookup(facetEndPrefix, spare);
+        endFacetOrd = facetFieldTermsIndex.lookupTerm(facetEndPrefix, spare);
         assert endFacetOrd < 0;
         endFacetOrd = -endFacetOrd - 1; // Points to the ord one higher than facetEndPrefix
       } else {
         startFacetOrd = -1;
-        endFacetOrd = facetFieldTermsIndex.numOrd();
+        endFacetOrd = facetFieldTermsIndex.getValueCount();
       }
     }
 
@@ -199,9 +212,14 @@ public abstract class TermGroupFacetColl
         segmentFacetCounts[facetFieldDocTermOrds.numTerms()]++;
 
         segmentGroupedFacetHits.put(segmentGroupedFacetsIndex);
-        groupedFacetHits.add(
-            new GroupedFacetHit(groupOrd == -1 ? null : groupFieldTermsIndex.lookup(groupOrd, new BytesRef()), null)
-        );
+        BytesRef groupKey;
+        if (groupOrd == -1) {
+          groupKey = null;
+        } else {
+          groupKey = new BytesRef();
+          groupFieldTermsIndex.lookupOrd(groupOrd, groupKey);
+        }
+        groupedFacetHits.add(new GroupedFacetHit(groupKey, null));
         return;
       }
 
@@ -234,9 +252,17 @@ public abstract class TermGroupFacetColl
           segmentFacetCounts[facetOrd]++;
 
           segmentGroupedFacetHits.put(segmentGroupedFacetsIndex);
+
+          BytesRef groupKey;
+          if (groupOrd == -1) {
+            groupKey = null;
+          } else {
+            groupKey = new BytesRef();
+            groupFieldTermsIndex.lookupOrd(groupOrd, groupKey);
+          }
+
           groupedFacetHits.add(
-              new GroupedFacetHit(
-                  groupOrd == -1 ? null : groupFieldTermsIndex.lookup(groupOrd, new BytesRef()),
+              new GroupedFacetHit(groupKey,
                   facetOrd == facetFieldDocTermOrds.numTerms() ? null : BytesRef.deepCopyOf(facetFieldDocTermOrds.lookupTerm(facetOrdTermsEnum, facetOrd))
               )
           );
@@ -259,7 +285,7 @@ public abstract class TermGroupFacetColl
 
       segmentGroupedFacetHits.clear();
       for (GroupedFacetHit groupedFacetHit : groupedFacetHits) {
-        int groupOrd = groupedFacetHit.groupValue == null ? -1 : groupFieldTermsIndex.binarySearchLookup(groupedFacetHit.groupValue, spare);
+        int groupOrd = groupedFacetHit.groupValue == null ? -1 : groupFieldTermsIndex.lookupTerm(groupedFacetHit.groupValue, spare);
         if (groupedFacetHit.groupValue != null && groupOrd < 0) {
           continue;
         }

Modified: lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermSecondPassGroupingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermSecondPassGroupingCollector.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermSecondPassGroupingCollector.java (original)
+++ lucene/dev/branches/lucene4547/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermSecondPassGroupingCollector.java Sat Nov 24 13:13:51 2012
@@ -17,16 +17,17 @@ package org.apache.lucene.search.groupin
  * limitations under the License.
  */
 
+import java.io.IOException;
+import java.util.Collection;
+
 import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.search.FieldCache;
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.grouping.AbstractSecondPassGroupingCollector;
 import org.apache.lucene.search.grouping.SearchGroup;
-import org.apache.lucene.util.SentinelIntSet;
 import org.apache.lucene.util.BytesRef;
-
-import java.io.IOException;
-import java.util.Collection;
+import org.apache.lucene.util.SentinelIntSet;
 
 /**
  * Concrete implementation of {@link org.apache.lucene.search.grouping.AbstractSecondPassGroupingCollector} that groups based on
@@ -38,7 +39,7 @@ import java.util.Collection;
 public class TermSecondPassGroupingCollector extends AbstractSecondPassGroupingCollector<BytesRef> {
 
   private final SentinelIntSet ordSet;
-  private FieldCache.DocTermsIndex index;
+  private SortedDocValues index;
   private final BytesRef spareBytesRef = new BytesRef();
   private final String groupField;
 
@@ -61,7 +62,7 @@ public class TermSecondPassGroupingColle
     ordSet.clear();
     for (SearchGroupDocs<BytesRef> group : groupMap.values()) {
 //      System.out.println("  group=" + (group.groupValue == null ? "null" : group.groupValue.utf8ToString()));
-      int ord = group.groupValue == null ? -1 : index.binarySearchLookup(group.groupValue, spareBytesRef);
+      int ord = group.groupValue == null ? -1 : index.lookupTerm(group.groupValue, spareBytesRef);
       if (group.groupValue == null || ord >= 0) {
         groupDocs[ordSet.put(ord)] = group;
       }

Modified: lucene/dev/branches/lucene4547/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/DocTermsIndexDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/DocTermsIndexDocValues.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/DocTermsIndexDocValues.java (original)
+++ lucene/dev/branches/lucene4547/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/DocTermsIndexDocValues.java Sat Nov 24 13:13:51 2012
@@ -17,26 +17,27 @@
 
 package org.apache.lucene.queries.function.docvalues;
 
+import java.io.IOException;
+
+import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.ValueSourceScorer;
 import org.apache.lucene.search.FieldCache;
-import org.apache.lucene.index.AtomicReaderContext;
-import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.CharsRef;
 import org.apache.lucene.util.UnicodeUtil;
 import org.apache.lucene.util.mutable.MutableValue;
 import org.apache.lucene.util.mutable.MutableValueStr;
 
-import java.io.IOException;
-
 /**
  * Internal class, subject to change.
  * Serves as base class for FunctionValues based on DocTermsIndex.
  */
 public abstract class DocTermsIndexDocValues extends FunctionValues {
-  protected final FieldCache.DocTermsIndex termsIndex;
+  protected final SortedDocValues termsIndex;
   protected final ValueSource vs;
   protected final MutableValueStr val = new MutableValueStr();
   protected final BytesRef spare = new BytesRef();
@@ -51,7 +52,7 @@ public abstract class DocTermsIndexDocVa
     this.vs = vs;
   }
 
-  public FieldCache.DocTermsIndex getDocTermsIndex() {
+  public SortedDocValues getSortedDocValues() {
     return termsIndex;
   }
 
@@ -70,7 +71,7 @@ public abstract class DocTermsIndexDocVa
       target.length = 0;
       return false;
     }
-    termsIndex.lookup(ord, target);
+    termsIndex.lookupOrd(ord, target);
     return true;
   }
 
@@ -78,7 +79,7 @@ public abstract class DocTermsIndexDocVa
   public String strVal(int doc) {
     int ord=termsIndex.getOrd(doc);
     if (ord==-1) return null;
-    termsIndex.lookup(ord, spare);
+    termsIndex.lookupOrd(ord, spare);
     UnicodeUtil.UTF8toUTF16(spare, spareChars);
     return spareChars.toString();
   }
@@ -101,7 +102,7 @@ public abstract class DocTermsIndexDocVa
 
     int lower = Integer.MIN_VALUE;
     if (lowerVal != null) {
-      lower = termsIndex.binarySearchLookup(new BytesRef(lowerVal), spare);
+      lower = termsIndex.lookupTerm(new BytesRef(lowerVal), spare);
       if (lower < 0) {
         lower = -lower-1;
       } else if (!includeLower) {
@@ -111,7 +112,7 @@ public abstract class DocTermsIndexDocVa
 
     int upper = Integer.MAX_VALUE;
     if (upperVal != null) {
-      upper = termsIndex.binarySearchLookup(new BytesRef(upperVal), spare);
+      upper = termsIndex.lookupTerm(new BytesRef(upperVal), spare);
       if (upper < 0) {
         upper = -upper-2;
       } else if (!includeUpper) {
@@ -153,7 +154,7 @@ public abstract class DocTermsIndexDocVa
         if (!mval.exists) {
           mval.value.length = 0;
         } else {
-          mval.value = termsIndex.lookup(ord, mval.value);
+          termsIndex.lookupOrd(ord, mval.value);
         }
       }
     };

Modified: lucene/dev/branches/lucene4547/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/OrdFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/OrdFieldSource.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/OrdFieldSource.java (original)
+++ lucene/dev/branches/lucene4547/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/OrdFieldSource.java Sat Nov 24 13:13:51 2012
@@ -17,12 +17,16 @@
 
 package org.apache.lucene.queries.function.valuesource;
 
+import java.io.IOException;
+import java.util.Map;
+
 import org.apache.lucene.index.AtomicReader;
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.index.CompositeReader;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.ReaderUtil;
 import org.apache.lucene.index.SlowCompositeReaderWrapper;
+import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.IntDocValues;
@@ -30,9 +34,6 @@ import org.apache.lucene.search.FieldCac
 import org.apache.lucene.util.mutable.MutableValue;
 import org.apache.lucene.util.mutable.MutableValueInt;
 
-import java.io.IOException;
-import java.util.Map;
-
 /**
  * Obtains the ordinal of the field value from the default Lucene {@link org.apache.lucene.search.FieldCache} using getStringIndex().
  * <br>
@@ -72,7 +73,7 @@ public class OrdFieldSource extends Valu
     final AtomicReader r = topReader instanceof CompositeReader 
         ? new SlowCompositeReaderWrapper((CompositeReader)topReader) 
         : (AtomicReader) topReader;
-    final FieldCache.DocTermsIndex sindex = FieldCache.DEFAULT.getTermsIndex(r, field);
+    final SortedDocValues sindex = FieldCache.DEFAULT.getTermsIndex(r, field);
     return new IntDocValues(this) {
       protected String toTerm(String readableValue) {
         return readableValue;
@@ -87,7 +88,7 @@ public class OrdFieldSource extends Valu
       }
       @Override
       public int numOrd() {
-        return sindex.numOrd();
+        return sindex.getValueCount();
       }
 
       @Override

Modified: lucene/dev/branches/lucene4547/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ReverseOrdFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ReverseOrdFieldSource.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ReverseOrdFieldSource.java (original)
+++ lucene/dev/branches/lucene4547/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ReverseOrdFieldSource.java Sat Nov 24 13:13:51 2012
@@ -17,20 +17,21 @@
 
 package org.apache.lucene.queries.function.valuesource;
 
+import java.io.IOException;
+import java.util.Map;
+
 import org.apache.lucene.index.AtomicReader;
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.index.CompositeReader;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.ReaderUtil;
 import org.apache.lucene.index.SlowCompositeReaderWrapper;
+import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.IntDocValues;
 import org.apache.lucene.search.FieldCache;
 
-import java.io.IOException;
-import java.util.Map;
-
 /**
  * Obtains the ordinal of the field value from the default Lucene {@link org.apache.lucene.search.FieldCache} using getTermsIndex()
  * and reverses the order.
@@ -73,8 +74,8 @@ public class ReverseOrdFieldSource exten
         : (AtomicReader) topReader;
     final int off = readerContext.docBase;
 
-    final FieldCache.DocTermsIndex sindex = FieldCache.DEFAULT.getTermsIndex(r, field);
-    final int end = sindex.numOrd();
+    final SortedDocValues sindex = FieldCache.DEFAULT.getTermsIndex(r, field);
+    final int end = sindex.getValueCount();
 
     return new IntDocValues(this) {
      @Override

Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/component/FieldFacetStats.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/component/FieldFacetStats.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/component/FieldFacetStats.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/component/FieldFacetStats.java Sat Nov 24 13:13:51 2012
@@ -16,16 +16,17 @@ package org.apache.solr.handler.componen
  * limitations under the License.
  */
 
-import org.apache.lucene.search.FieldCache;
-import org.apache.lucene.util.BytesRef;
-import org.apache.solr.schema.FieldType;
-import org.apache.solr.schema.SchemaField;
-
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.lucene.index.SortedDocValues;
+import org.apache.lucene.search.FieldCache;
+import org.apache.lucene.util.BytesRef;
+import org.apache.solr.schema.FieldType;
+import org.apache.solr.schema.SchemaField;
+
 
 /**
  * FieldFacetStats is a utility to accumulate statistics on a set of values in one field,
@@ -39,7 +40,7 @@ import java.util.Map;
 
 public class FieldFacetStats {
   public final String name;
-  final FieldCache.DocTermsIndex si;
+  final SortedDocValues si;
   final SchemaField facet_sf;
   final SchemaField field_sf;
 
@@ -55,7 +56,7 @@ public class FieldFacetStats {
 
   private final BytesRef tempBR = new BytesRef();
 
-  public FieldFacetStats(String name, FieldCache.DocTermsIndex si, SchemaField field_sf, SchemaField facet_sf, int numStatsTerms) {
+  public FieldFacetStats(String name, SortedDocValues si, SchemaField field_sf, SchemaField facet_sf, int numStatsTerms) {
     this.name = name;
     this.si = si;
     this.field_sf = field_sf;
@@ -63,7 +64,7 @@ public class FieldFacetStats {
     this.numStatsTerms = numStatsTerms;
 
     startTermIndex = 0;
-    endTermIndex = si.numOrd();
+    endTermIndex = si.getValueCount();
     nTerms = endTermIndex - startTermIndex;
 
     facetStatsValues = new HashMap<String, StatsValues>();
@@ -82,7 +83,8 @@ public class FieldFacetStats {
     if (ord == -1) {
       return null;
     } else {
-      return si.lookup(ord, ret);
+      si.lookupOrd(ord, ret);
+      return ret;
     }
   }
 
@@ -90,7 +92,14 @@ public class FieldFacetStats {
     int term = si.getOrd(docID);
     int arrIdx = term - startTermIndex;
     if (arrIdx >= 0 && arrIdx < nTerms) {
-      final BytesRef br = si.lookup(term, tempBR);
+      
+      final BytesRef br;
+      if (term == -1) {
+        br = null;
+      } else {
+        br = tempBR;
+        si.lookupOrd(term, tempBR);
+      }
       String key = (br == null)?null:facet_sf.getType().indexedToReadable(br.utf8ToString());
       StatsValues stats = facetStatsValues.get(key);
       if (stats == null) {
@@ -117,7 +126,13 @@ public class FieldFacetStats {
     int term = si.getOrd(docID);
     int arrIdx = term - startTermIndex;
     if (arrIdx >= 0 && arrIdx < nTerms) {
-      final BytesRef br = si.lookup(term, tempBR);
+      final BytesRef br;
+      if (term == -1) {
+        br = null;
+      } else {
+        br = tempBR;
+        si.lookupOrd(term, tempBR);
+      }
       String key = br == null ? null : br.utf8ToString();
       HashMap<String, Integer> statsTermCounts = facetStatsTerms.get(statsTermNum);
       Integer statsTermCount = statsTermCounts.get(key);

Modified: lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/component/StatsComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/component/StatsComponent.java?rev=1413182&r1=1413181&r2=1413182&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/component/StatsComponent.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/java/org/apache/solr/handler/component/StatsComponent.java Sat Nov 24 13:13:51 2012
@@ -23,22 +23,23 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.search.FieldCache;
 import org.apache.lucene.util.BytesRef;
 import org.apache.solr.common.SolrException;
+import org.apache.solr.common.params.ShardParams;
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.params.StatsParams;
-import org.apache.solr.common.params.ShardParams;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SimpleOrderedMap;
 import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.request.UnInvertedField;
 import org.apache.solr.schema.FieldType;
 import org.apache.solr.schema.SchemaField;
 import org.apache.solr.schema.TrieField;
 import org.apache.solr.search.DocIterator;
 import org.apache.solr.search.DocSet;
 import org.apache.solr.search.SolrIndexSearcher;
-import org.apache.solr.request.UnInvertedField;
 
 /**
  * Stats component calculates simple statistics on numeric field values
@@ -240,7 +241,7 @@ class SimpleStats {
   public NamedList<?> getFieldCacheStats(String fieldName, String[] facet ) {
     SchemaField sf = searcher.getSchema().getField(fieldName);
     
-    FieldCache.DocTermsIndex si;
+    SortedDocValues si;
     try {
       si = FieldCache.DEFAULT.getTermsIndex(searcher.getAtomicReader(), fieldName);
     } 
@@ -248,12 +249,12 @@ class SimpleStats {
       throw new RuntimeException( "failed to open field cache for: "+fieldName, e );
     }
     StatsValues allstats = StatsValuesFactory.createStatsValues(sf);
-    final int nTerms = si.numOrd();
+    final int nTerms = si.getValueCount();
     if ( nTerms <= 0 || docs.size() <= 0 ) return allstats.getStatsValues();
 
     // don't worry about faceting if no documents match...
     List<FieldFacetStats> facetStats = new ArrayList<FieldFacetStats>();
-    FieldCache.DocTermsIndex facetTermsIndex;
+    SortedDocValues facetTermsIndex;
     for( String facetField : facet ) {
       SchemaField fsf = searcher.getSchema().getField(facetField);
 
@@ -283,9 +284,10 @@ class SimpleStats {
         tempBR.length = 0;
         raw = tempBR;
       } else {
-        raw = si.lookup(docOrd, tempBR);
-        if( raw.length > 0 ) {
-          allstats.accumulate(raw);
+        raw = tempBR;
+        si.lookupOrd(docOrd, tempBR);
+        if( tempBR.length > 0 ) {
+          allstats.accumulate(tempBR);
         } else {
           allstats.missing();
         }



Mime
View raw message