magibney commented on a change in pull request #592:
URL: https://github.com/apache/solr/pull/592#discussion_r799881581



##########
File path: solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
##########
@@ -866,8 +876,48 @@ public BitDocSet getLiveDocSet() throws IOException {
     // but the addition of setLiveDocs means we needed to add volatile to 
"liveDocs".
     BitDocSet docs = liveDocs;
     if (docs == null) {
-      //note: maybe should instead calc manually by segment, using 
FixedBitSet.copyOf(segLiveDocs); avoid filter cache?
-      liveDocs = docs = getDocSetBits(matchAllDocsQuery);
+      switch (leafContexts.size()) {
+        case 0:
+          assert numDocs() == 0;
+          docs = new BitDocSet(BitDocSet.empty().getFixedBitSet(), 0);
+          break;
+        case 1:
+          final Bits onlySegLiveDocs = 
leafContexts.get(0).reader().getLiveDocs();
+          final FixedBitSet fbs;
+          if (onlySegLiveDocs == null) {
+            final int onlySegMaxDoc = maxDoc();
+            fbs = new FixedBitSet(onlySegMaxDoc);
+            fbs.set(0, onlySegMaxDoc);
+          } else {
+            fbs = FixedBitSet.copyOf(onlySegLiveDocs);
+          }
+          assert fbs.cardinality() == numDocs();
+          docs = new BitDocSet(fbs, numDocs());
+          break;
+        default:
+          final FixedBitSet bs = new FixedBitSet(maxDoc());
+          for (LeafReaderContext ctx : leafContexts) {
+            final LeafReader r = ctx.reader();
+            final Bits segLiveDocs = r.getLiveDocs();
+            final int segDocBase = ctx.docBase;
+            int segOrd = r.maxDoc() - 1;
+            if (segLiveDocs == null) {
+              do {
+                bs.set(segDocBase + segOrd);
+              } while (segOrd-- > 0);
+            } else {
+              do {
+                if (segLiveDocs.get(segOrd)) {
+                  bs.set(segDocBase + segOrd);

Review comment:
       I don't think the 2-arg version works _here_ because the two-arg version 
works on ranges. In order to call it I think you'd need more complex logic, 
scanning contiguous ranges and then calling set(int, int) when you encounter 
boundaries (deleted docs) ... I'm thinking that's not worth the effort here?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to