lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r790938 - in /lucene/solr/trunk/src: java/org/apache/solr/search/DocSlice.java java/org/apache/solr/search/HashDocSet.java test/org/apache/solr/search/TestDocSet.java
Date Fri, 03 Jul 2009 15:09:22 GMT
Author: yonik
Date: Fri Jul  3 15:09:21 2009
New Revision: 790938

URL: http://svn.apache.org/viewvc?rev=790938&view=rev
Log:
SOLR-1260: support all DocSet operations in DocSlice

Modified:
    lucene/solr/trunk/src/java/org/apache/solr/search/DocSlice.java
    lucene/solr/trunk/src/java/org/apache/solr/search/HashDocSet.java
    lucene/solr/trunk/src/test/org/apache/solr/search/TestDocSet.java

Modified: lucene/solr/trunk/src/java/org/apache/solr/search/DocSlice.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/DocSlice.java?rev=790938&r1=790937&r2=790938&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/DocSlice.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/DocSlice.java Fri Jul  3 15:09:21 2009
@@ -85,8 +85,9 @@
 
 
   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 @@
       }
     };
   }
+
+
+  @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);  
+  }
 }

Modified: lucene/solr/trunk/src/java/org/apache/solr/search/HashDocSet.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/HashDocSet.java?rev=790938&r1=790937&r2=790938&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/HashDocSet.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/HashDocSet.java Fri Jul  3 15:09:21
2009
@@ -67,7 +67,8 @@
     // https://issues.apache.org/jira/browse/SOLR-390
     for (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]);
     }
 

Modified: lucene/solr/trunk/src/test/org/apache/solr/search/TestDocSet.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/search/TestDocSet.java?rev=790938&r1=790937&r2=790938&view=diff
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/search/TestDocSet.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/search/TestDocSet.java Fri Jul  3 15:09:21
2009
@@ -71,11 +71,38 @@
     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 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 @@
     // 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 @@
       doFilterTest(sir);
     }
   }
-
-
 }



Mime
View raw message