lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cpoersc...@apache.org
Subject [07/21] lucene-solr git commit: also assert PointValues are the same from LTC.assertReaderEquals
Date Tue, 02 Feb 2016 09:53:19 GMT
also assert PointValues are the same from LTC.assertReaderEquals


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/9332b160
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/9332b160
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/9332b160

Branch: refs/heads/master-solr-8621
Commit: 9332b1602cc0f7312fc22a3d088c549299015691
Parents: 5d5b082
Author: Mike McCandless <mikemccand@apache.org>
Authored: Fri Jan 29 19:09:04 2016 -0500
Committer: Mike McCandless <mikemccand@apache.org>
Committed: Fri Jan 29 19:09:04 2016 -0500

----------------------------------------------------------------------
 .../apache/lucene/index/MultiPointValues.java   |  4 +-
 .../org/apache/lucene/util/LuceneTestCase.java  | 64 ++++++++++++++++++++
 2 files changed, 67 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/9332b160/lucene/core/src/java/org/apache/lucene/index/MultiPointValues.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/index/MultiPointValues.java b/lucene/core/src/java/org/apache/lucene/index/MultiPointValues.java
index 12282e7..5dd4fcc 100644
--- a/lucene/core/src/java/org/apache/lucene/index/MultiPointValues.java
+++ b/lucene/core/src/java/org/apache/lucene/index/MultiPointValues.java
@@ -23,7 +23,8 @@ import java.util.List;
 
 import org.apache.lucene.util.StringHelper;
 
-class MultiPointValues extends PointValues {
+/** Merges multiple {@link PointValues} into a single one. */
+public class MultiPointValues extends PointValues {
 
   private final List<PointValues> subs;
   private final List<Integer> docBases;
@@ -33,6 +34,7 @@ class MultiPointValues extends PointValues {
     this.docBases = docBases;
   }
 
+  /** Returns a {@link PointValues} merging all point values from the provided reader. */
   public static PointValues get(IndexReader r) {
     final List<LeafReaderContext> leaves = r.leaves();
     final int size = leaves.size();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/9332b160/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
----------------------------------------------------------------------
diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
index aaab030..7175837 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
@@ -1888,6 +1888,7 @@ public abstract class LuceneTestCase extends Assert {
     assertDocValuesEquals(info, leftReader, rightReader);
     assertDeletedDocsEquals(info, leftReader, rightReader);
     assertFieldInfosEquals(info, leftReader, rightReader);
+    assertPointsEquals(info, leftReader, rightReader);
   }
 
   /** 
@@ -2533,6 +2534,69 @@ public abstract class LuceneTestCase extends Assert {
     assertEquals(info, left, right);
   }
 
+  // naive silly memory heavy uninversion!!  maps docID -> packed values (a Set because
a given doc can be multi-valued)
+  private Map<Integer,Set<BytesRef>> uninvert(String fieldName, PointValues points)
throws IOException {
+    final Map<Integer,Set<BytesRef>> docValues = new HashMap<>();
+    points.intersect(fieldName, new PointValues.IntersectVisitor() {
+        @Override
+        public void visit(int docID) {
+          throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public void visit(int docID, byte[] packedValue) throws IOException {
+          if (docValues.containsKey(docID) == false) {
+            docValues.put(docID, new HashSet<BytesRef>());
+          }
+          docValues.get(docID).add(new BytesRef(packedValue.clone()));
+        }
+
+        @Override
+        public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue)
{
+          // We pretend our query shape is so hairy that it crosses every single cell:
+          return PointValues.Relation.CELL_CROSSES_QUERY;
+        }
+      });
+    return docValues;
+  }
+
+  public void assertPointsEquals(String info, IndexReader leftReader, IndexReader rightReader)
throws IOException {
+    assertPointsEquals(info,
+                       MultiFields.getMergedFieldInfos(leftReader),
+                       MultiPointValues.get(leftReader),
+                       MultiFields.getMergedFieldInfos(rightReader),
+                       MultiPointValues.get(rightReader));
+  }
+
+  public void assertPointsEquals(String info, FieldInfos fieldInfos1, PointValues points1,
FieldInfos fieldInfos2, PointValues points2) throws IOException {
+    for(FieldInfo fieldInfo1 : fieldInfos1) {
+      if (fieldInfo1.getPointDimensionCount() != 0) {
+        FieldInfo fieldInfo2 = fieldInfos2.fieldInfo(fieldInfo1.name);
+        // same dimension count?
+        assertEquals(info, fieldInfo2.getPointDimensionCount(), fieldInfo2.getPointDimensionCount());
+        // same bytes per dimension?
+        assertEquals(info, fieldInfo2.getPointNumBytes(), fieldInfo2.getPointNumBytes());
+
+        assertEquals(info + " field=" + fieldInfo1.name,
+                     uninvert(fieldInfo1.name, points1),
+                     uninvert(fieldInfo1.name, points2));
+      }
+    }
+
+    // make sure FieldInfos2 doesn't have any point fields that FieldInfo1 didn't have
+    for(FieldInfo fieldInfo2 : fieldInfos2) {
+      if (fieldInfo2.getPointDimensionCount() != 0) {
+        FieldInfo fieldInfo1 = fieldInfos1.fieldInfo(fieldInfo2.name);
+        // same dimension count?
+        assertEquals(info, fieldInfo2.getPointDimensionCount(), fieldInfo1.getPointDimensionCount());
+        // same bytes per dimension?
+        assertEquals(info, fieldInfo2.getPointNumBytes(), fieldInfo1.getPointNumBytes());
+
+        // we don't need to uninvert and compare here ... we did that in the first loop above
+      }
+    }
+  }
+
   /** Returns true if the file exists (can be opened), false
    *  if it cannot be opened, and (unlike Java's
    *  File.exists) throws IOException if there's some


Mime
View raw message