Apache Solr open-source search software
SOLR-1260: support all DocSet operations in DocSlice
Yonik Seeleycdb2cbfeaa4f
diff --git a/src/java/org/apache/solr/search/DocSlice.java b/src/java/org/apache/solr/search/DocSlice.javaindex a21db1596cd..0f8887c7943 100644--- a/src/java/org/apache/solr/search/DocSlice.java+++ b/src/java/org/apache/solr/search/DocSlice.java@@ -85,8 +85,9 @@ public class DocSlice extends DocSetBase implements DocList {public boolean exists(int doc) {- for (int i: docs) {- if (i==doc) return true;+ int end = offset+len;+ for (int i=offset; i<end; i++) {+ if (docs[i]==doc) return true;}return false;}@@ -121,4 +122,23 @@ public class DocSlice extends DocSetBase implements DocList {}};}+++ @Override+ public DocSet intersection(DocSet other) {+ if (other instanceof SortedIntDocSet || other instanceof HashDocSet) {+ return other.intersection(this);+ }+ HashDocSet h = new HashDocSet(docs,offset,len);+ return h.intersection(other);+ }++ @Override+ public int intersectionSize(DocSet other) {+ if (other instanceof SortedIntDocSet || other instanceof HashDocSet) {+ return other.intersectionSize(this);+ }+ HashDocSet h = new HashDocSet(docs,offset,len);+ return h.intersectionSize(other);+ }}diff --git a/src/java/org/apache/solr/search/HashDocSet.java b/src/java/org/apache/solr/search/HashDocSet.javaindex 95070203f49..1c610841b5d 100644--- a/src/java/org/apache/solr/search/HashDocSet.java+++ b/src/java/org/apache/solr/search/HashDocSet.java@@ -67,7 +67,8 @@ public final class HashDocSet extends DocSetBase {// https://issues.apache.org/jira/browse/SOLR-390for (int i=tsize-1; i>=0; i--) table[i]=EMPTY;- for (int i=offset; i<len; i++) {+ int end = offset + len;+ for (int i=offset; i<end; i++) {put(docs[i]);}diff --git a/src/test/org/apache/solr/search/TestDocSet.java b/src/test/org/apache/solr/search/TestDocSet.javaindex 1607373ab9d..c545080406e 100644--- a/src/test/org/apache/solr/search/TestDocSet.java+++ b/src/test/org/apache/solr/search/TestDocSet.java@@ -71,11 +71,38 @@ public class TestDocSet extends TestCase {return new BitDocSet(bs);}+ public DocSet getDocSlice(OpenBitSet bs) {+ int len = (int)bs.cardinality();+ int[] arr = new int[len+5];+ arr[0]=10; arr[1]=20; arr[2]=30; arr[arr.length-1]=1; arr[arr.length-2]=2;+ int offset = 3;+ int end = offset + len;++ OpenBitSetIterator iter = new OpenBitSetIterator(bs);+ // put in opposite order... DocLists are not ordered.+ for (int i=end-1; i>=offset; i--) {+ arr[i] = iter.nextDoc();+ }++ return new DocSlice(offset, len, arr, null, len*2, 100.0f);+ }++public DocSet getDocSet(OpenBitSet bs) {- switch(rand.nextInt(3)) {- case 0: return getIntDocSet(bs);- case 1: return getHashDocSet(bs);- case 2: return getBitDocSet(bs);+ switch(rand.nextInt(10)) {+ case 0: return getHashDocSet(bs);++ case 1: return getBitDocSet(bs);+ case 2: return getBitDocSet(bs);+ case 3: return getBitDocSet(bs);++ case 4: return getIntDocSet(bs);+ case 5: return getIntDocSet(bs);+ case 6: return getIntDocSet(bs);+ case 7: return getIntDocSet(bs);+ case 8: return getIntDocSet(bs);++ case 9: return getDocSlice(bs);}return null;}@@ -88,8 +115,8 @@ public class TestDocSet extends TestCase {}public void iter(DocSet d1, DocSet d2) {- // HashDocSet doesn't iterate in order.- if (d1 instanceof HashDocSet || d2 instanceof HashDocSet) return;+ // HashDocSet and DocList doesn't iterate in order.+ if (d1 instanceof HashDocSet || d2 instanceof HashDocSet || d1 instanceof DocList || d2 instanceof DocList) return;DocIterator i1 = d1.iterator();DocIterator i2 = d2.iterator();@@ -149,7 +176,7 @@ public class TestDocSet extends TestCase {// 64 bits for the bit doc set. Smaller sets can hit more boundary conditions though.doMany(130, 10000);- //doMany(130, 1000000);+ // doMany(130, 1000000);}public DocSet getRandomDocSet(int n, int maxDoc) {@@ -419,6 +446,4 @@ public class TestDocSet extends TestCase {doFilterTest(sir);}}--}