You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2016/03/24 16:37:34 UTC
lucene-solr:branch_6_0: simplify BKDWriter's comparator tie break for
its temp files; add test case verifying tie break by docID
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6_0 e2f0aae56 -> 0422e68c5
simplify BKDWriter's comparator tie break for its temp files; add test case verifying tie break by docID
Conflicts:
lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java
lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointReader.java
lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointWriter.java
lucene/core/src/test/org/apache/lucene/util/bkd/TestBKD.java
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/0422e68c
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/0422e68c
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/0422e68c
Branch: refs/heads/branch_6_0
Commit: 0422e68c5b366d8184c9774ec64c4760a7c1e1ad
Parents: e2f0aae
Author: Mike McCandless <mi...@apache.org>
Authored: Thu Mar 24 10:02:48 2016 -0400
Committer: Mike McCandless <mi...@apache.org>
Committed: Thu Mar 24 11:23:23 2016 -0400
----------------------------------------------------------------------
.../org/apache/lucene/util/bkd/BKDWriter.java | 19 ++++------
.../lucene/util/bkd/OfflinePointReader.java | 2 +-
.../lucene/util/bkd/OfflinePointWriter.java | 2 +-
.../org/apache/lucene/util/bkd/TestBKD.java | 38 ++++++++++++++++++++
4 files changed, 47 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0422e68c/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java b/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java
index 885f121..e03b0d7 100644
--- a/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java
@@ -682,24 +682,19 @@ public class BKDWriter implements Closeable {
@Override
public int compare(BytesRef a, BytesRef b) {
-
- // First compare the bytes on the dimension we are sorting on:
+ // First compare by the requested dimension we are sorting by:
int cmp = StringHelper.compare(bytesPerDim, a.bytes, a.offset + bytesPerDim*dim, b.bytes, b.offset + bytesPerDim*dim);
if (cmp != 0) {
return cmp;
}
- // Tie-break by docID:
- reader.reset(a.bytes, a.offset + packedBytesLength + Long.BYTES, a.length);
- final int docIDA = reader.readInt();
-
- reader.reset(b.bytes, b.offset + packedBytesLength + Long.BYTES, b.length);
- final int docIDB = reader.readInt();
-
- // No need to tie break on ord, for the case where the same doc has the same value in a given dimension indexed more than once: it
- // can't matter at search time since we don't write ords into the index:
- return Integer.compare(docIDA, docIDB);
+ // Tie-break by docID ... no need to tie break on ord, for the case where the same doc has
+ // the same value in a given dimension indexed more than once: it can't matter at search
+ // time since we don't write ords into the index:
+ return StringHelper.compare(Integer.BYTES,
+ a.bytes, a.offset + packedBytesLength,
+ b.bytes, b.offset + packedBytesLength);
}
};
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0422e68c/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointReader.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointReader.java b/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointReader.java
index e340be8..baa03e2 100644
--- a/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointReader.java
+++ b/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointReader.java
@@ -74,8 +74,8 @@ final class OfflinePointReader implements PointReader {
assert countLeft == -1;
return false;
}
- ord = in.readLong();
docID = in.readInt();
+ ord = in.readLong();
return true;
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0422e68c/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointWriter.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointWriter.java b/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointWriter.java
index f10020c..887ee74 100644
--- a/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/util/bkd/OfflinePointWriter.java
@@ -52,8 +52,8 @@ final class OfflinePointWriter implements PointWriter {
public void append(byte[] packedValue, long ord, int docID) throws IOException {
assert packedValue.length == packedBytesLength;
out.writeBytes(packedValue, 0, packedValue.length);
- out.writeLong(ord);
out.writeInt(docID);
+ out.writeLong(ord);
count++;
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0422e68c/lucene/core/src/test/org/apache/lucene/util/bkd/TestBKD.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/bkd/TestBKD.java b/lucene/core/src/test/org/apache/lucene/util/bkd/TestBKD.java
index 7eb0391..6dc062b 100644
--- a/lucene/core/src/test/org/apache/lucene/util/bkd/TestBKD.java
+++ b/lucene/core/src/test/org/apache/lucene/util/bkd/TestBKD.java
@@ -889,4 +889,42 @@ public class TestBKD extends LuceneTestCase {
}
fail("did not see a supporessed CorruptIndexException");
}
+
+ public void testTieBreakOrder() throws Exception {
+ try (Directory dir = newDirectory()) {
+ int numDocs = 10000;
+ BKDWriter w = new BKDWriter(numDocs+1, dir, "tmp", 1, 4, 2, 0.01f);
+ for(int i=0;i<numDocs;i++) {
+ w.add(new byte[Integer.BYTES], i);
+ }
+
+ IndexOutput out = dir.createOutput("bkd", IOContext.DEFAULT);
+ long fp = w.finish(out);
+ out.close();
+
+ IndexInput in = dir.openInput("bkd", IOContext.DEFAULT);
+ in.seek(fp);
+ BKDReader r = new BKDReader(in);
+ r.intersect(new IntersectVisitor() {
+ int lastDocID = -1;
+
+ @Override
+ public void visit(int docID) {
+ assertTrue("lastDocID=" + lastDocID + " docID=" + docID, docID > lastDocID);
+ lastDocID = docID;
+ }
+
+ @Override
+ public void visit(int docID, byte[] packedValue) {
+ visit(docID);
+ }
+
+ @Override
+ public Relation compare(byte[] minPacked, byte[] maxPacked) {
+ return Relation.CELL_CROSSES_QUERY;
+ }
+ });
+ in.close();
+ }
+ }
}