You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2013/02/13 07:19:31 UTC

svn commit: r1445478 - in /lucene/dev/branches/lucene4765/lucene: core/src/java/org/apache/lucene/index/ core/src/java/org/apache/lucene/search/ core/src/test/org/apache/lucene/search/ test-framework/src/java/org/apache/lucene/index/

Author: rmuir
Date: Wed Feb 13 06:19:31 2013
New Revision: 1445478

URL: http://svn.apache.org/r1445478
Log:
fix nocommits

Added:
    lucene/dev/branches/lucene4765/lucene/core/src/java/org/apache/lucene/index/SingletonSortedSetDocValues.java   (with props)
Modified:
    lucene/dev/branches/lucene4765/lucene/core/src/java/org/apache/lucene/index/SortedSetDocValues.java
    lucene/dev/branches/lucene4765/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java
    lucene/dev/branches/lucene4765/lucene/core/src/test/org/apache/lucene/search/TestFieldCache.java
    lucene/dev/branches/lucene4765/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java

Added: lucene/dev/branches/lucene4765/lucene/core/src/java/org/apache/lucene/index/SingletonSortedSetDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4765/lucene/core/src/java/org/apache/lucene/index/SingletonSortedSetDocValues.java?rev=1445478&view=auto
==============================================================================
--- lucene/dev/branches/lucene4765/lucene/core/src/java/org/apache/lucene/index/SingletonSortedSetDocValues.java (added)
+++ lucene/dev/branches/lucene4765/lucene/core/src/java/org/apache/lucene/index/SingletonSortedSetDocValues.java Wed Feb 13 06:19:31 2013
@@ -0,0 +1,64 @@
+package org.apache.lucene.index;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.util.BytesRef;
+
+/** 
+ * Exposes multi-valued view over a single-valued instance.
+ * <p>
+ * This can be used if you want to have one multi-valued implementation
+ * against e.g. FieldCache.getDocTermOrds that also works for single-valued 
+ * fields.
+ */
+public class SingletonSortedSetDocValues extends SortedSetDocValues {
+  private final SortedDocValues in;
+  private int docID;
+  
+  /** Creates a multi-valued view over the provided SortedDocValues */
+  public SingletonSortedSetDocValues(SortedDocValues in) {
+    this.in = in;
+    assert NO_MORE_ORDS == -1; // this allows our nextOrd() to work for missing values without a check
+  }
+
+  @Override
+  public long nextOrd() {
+    return in.getOrd(docID);
+  }
+
+  @Override
+  public void setDocument(int docID) {
+    this.docID = docID;
+  }
+
+  @Override
+  public void lookupOrd(long ord, BytesRef result) {
+    // cast is ok: single-valued cannot exceed Integer.MAX_VALUE
+    in.lookupOrd((int)ord, result);
+  }
+
+  @Override
+  public long getValueCount() {
+    return in.getValueCount();
+  }
+
+  @Override
+  public long lookupTerm(BytesRef key) {
+    return in.lookupTerm(key);
+  }
+}

Modified: lucene/dev/branches/lucene4765/lucene/core/src/java/org/apache/lucene/index/SortedSetDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4765/lucene/core/src/java/org/apache/lucene/index/SortedSetDocValues.java?rev=1445478&r1=1445477&r2=1445478&view=diff
==============================================================================
--- lucene/dev/branches/lucene4765/lucene/core/src/java/org/apache/lucene/index/SortedSetDocValues.java (original)
+++ lucene/dev/branches/lucene4765/lucene/core/src/java/org/apache/lucene/index/SortedSetDocValues.java Wed Feb 13 06:19:31 2013
@@ -33,7 +33,7 @@ public abstract class SortedSetDocValues
    * constructors, typically implicit.) */
   protected SortedSetDocValues() {}
 
-  public static final long NO_MORE_ORDS = Long.MAX_VALUE;
+  public static final long NO_MORE_ORDS = -1;
 
   /** 
    * Returns the next ordinal for the current document (previously

Modified: lucene/dev/branches/lucene4765/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4765/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java?rev=1445478&r1=1445477&r2=1445478&view=diff
==============================================================================
--- lucene/dev/branches/lucene4765/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java (original)
+++ lucene/dev/branches/lucene4765/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java Wed Feb 13 06:19:31 2013
@@ -33,6 +33,7 @@ import org.apache.lucene.index.FieldInfo
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.NumericDocValues;
 import org.apache.lucene.index.SegmentReader;
+import org.apache.lucene.index.SingletonSortedSetDocValues;
 import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.index.SortedSetDocValues;
 import org.apache.lucene.index.Terms;
@@ -1304,14 +1305,18 @@ class FieldCacheImpl implements FieldCac
     }
   }
 
+  // TODO: this if DocTermsIndex was already created, we
+  // should share it...
   public SortedSetDocValues getDocTermOrds(AtomicReader reader, String field) throws IOException {
     SortedSetDocValues dv = reader.getSortedSetDocValues(field);
     if (dv != null) {
       return dv;
     }
     
-    // nocommit: actually if they have a SortedDV (either indexed as DV or cached), we should return an impl
-    // over that: its like a specialized single-value case of this thing...
+    SortedDocValues sdv = reader.getSortedDocValues(field);
+    if (sdv != null) {
+      return new SingletonSortedSetDocValues(sdv);
+    }
     
     DocTermOrds dto = (DocTermOrds) caches.get(DocTermOrds.class).get(reader, new CacheKey(field, null), false);
     return dto.iterator(dto.getOrdTermsEnum(reader));
@@ -1325,7 +1330,6 @@ class FieldCacheImpl implements FieldCac
     @Override
     protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField /* ignored */)
         throws IOException {
-      // No DocValues impl yet (DocValues are single valued...):
       return new DocTermOrds(reader, key.field);
     }
   }

Modified: lucene/dev/branches/lucene4765/lucene/core/src/test/org/apache/lucene/search/TestFieldCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4765/lucene/core/src/test/org/apache/lucene/search/TestFieldCache.java?rev=1445478&r1=1445477&r2=1445478&view=diff
==============================================================================
--- lucene/dev/branches/lucene4765/lucene/core/src/test/org/apache/lucene/search/TestFieldCache.java (original)
+++ lucene/dev/branches/lucene4765/lucene/core/src/test/org/apache/lucene/search/TestFieldCache.java Wed Feb 13 06:19:31 2013
@@ -254,8 +254,11 @@ public class TestFieldCache extends Luce
 
     // getDocTermOrds
     SortedSetDocValues termOrds = cache.getDocTermOrds(reader, "theRandomUnicodeMultiValuedField");
-    // nocommit: test this with reflection or something, that its really from the same DTO
-    // assertSame("Second request to cache return same DocTermOrds", termOrds, cache.getDocTermOrds(reader, "theRandomUnicodeMultiValuedField"));
+    int numEntries = cache.getCacheEntries().length;
+    // ask for it again, and check that we didnt create any additional entries:
+    termOrds = cache.getDocTermOrds(reader, "theRandomUnicodeMultiValuedField");
+    assertEquals(numEntries, cache.getCacheEntries().length);
+
     for (int i = 0; i < NUM_DOCS; i++) {
       termOrds.setDocument(i);
       // This will remove identical terms. A DocTermOrds doesn't return duplicate ords for a docId
@@ -275,8 +278,8 @@ public class TestFieldCache extends Luce
     }
 
     // test bad field
-    // nocommit: what exactly does this test?
     termOrds = cache.getDocTermOrds(reader, "bogusfield");
+    assertTrue(termOrds.getValueCount() == 0);
 
     FieldCache.DEFAULT.purge(reader);
   }

Modified: lucene/dev/branches/lucene4765/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4765/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java?rev=1445478&r1=1445477&r2=1445478&view=diff
==============================================================================
--- lucene/dev/branches/lucene4765/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java (original)
+++ lucene/dev/branches/lucene4765/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java Wed Feb 13 06:19:31 2013
@@ -472,8 +472,8 @@ public class AssertingAtomicReader exten
     public long nextOrd() {
       assert lastOrd != NO_MORE_ORDS;
       long ord = in.nextOrd();
-      assert ord == NO_MORE_ORDS || ord < valueCount;
-      assert ord > lastOrd;
+      assert ord < valueCount;
+      assert ord == NO_MORE_ORDS || ord > lastOrd;
       lastOrd = ord;
       return ord;
     }
@@ -482,7 +482,7 @@ public class AssertingAtomicReader exten
     public void setDocument(int docID) {
       assert docID >= 0 && docID < maxDoc : "docid=" + docID + ",maxDoc=" + maxDoc;
       in.setDocument(docID);
-      lastOrd = -1;
+      lastOrd = -2;
     }
 
     @Override