dsmiley commented on code in PR #1184:
URL: https://github.com/apache/solr/pull/1184#discussion_r1026790611


##########
solr/core/src/java/org/apache/solr/search/MutableBitDocSet.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.search;
+
+import org.apache.lucene.util.FixedBitSet;
+
+/**
+ * A {@link BitDocSet} based implementation that mutates the underlying bits 
for andNot and
+ * intersection. This allows for computing the combinations of sets without 
duplicating the
+ * underlying array.
+ *

Review Comment:
   Lets warn that this ought not to be cached, because it might inadvertently 
be modified.



##########
solr/core/src/java/org/apache/solr/search/MutableBitDocSet.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.search;
+
+import org.apache.lucene.util.FixedBitSet;
+
+/**
+ * A {@link BitDocSet} based implementation that mutates the underlying bits 
for andNot and
+ * intersection. This allows for computing the combinations of sets without 
duplicating the
+ * underlying array.
+ *
+ * @since solr 9.2
+ */
+public class MutableBitDocSet extends BitDocSet {

Review Comment:
   Let's not make this public.



##########
solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java:
##########
@@ -1211,17 +1211,28 @@ public ProcessedFilter getProcessedFilter(DocSet 
setFilter, List<Query> queries)
     }
 
     // Are all of our normal cached filters negative?
-    if (end > 0 && answer == null) {
-      answer = getLiveDocSet();
-    }
+    if (end > 0) {
+      if (answer == null) {
+        answer = getLiveDocSet();
+      }
 
-    // do negative queries first to shrink set size
-    for (int i = 0; i < end; i++) {
-      if (neg[i]) answer = answer.andNot(sets[i]);
-    }
+      // This optimizes for the case where we have more than 2 filters and 
instead
+      // of copying the bitsets we make one mutable bitset. We only need to do 
this
+      // for BitDocSet since it clones the backing bitset for andNot and 
intersection.
+      if (end > 1 && answer instanceof BitDocSet) {

Review Comment:
   at this spot, end is guaranteed to be greater than 1 based on you putting a 
big if-else around this section (line 1214); right?



##########
solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java:
##########
@@ -1211,17 +1211,28 @@ public ProcessedFilter getProcessedFilter(DocSet 
setFilter, List<Query> queries)
     }
 
     // Are all of our normal cached filters negative?
-    if (end > 0 && answer == null) {
-      answer = getLiveDocSet();
-    }
+    if (end > 0) {
+      if (answer == null) {
+        answer = getLiveDocSet();
+      }
 
-    // do negative queries first to shrink set size
-    for (int i = 0; i < end; i++) {
-      if (neg[i]) answer = answer.andNot(sets[i]);
-    }
+      // This optimizes for the case where we have more than 2 filters and 
instead
+      // of copying the bitsets we make one mutable bitset. We only need to do 
this
+      // for BitDocSet since it clones the backing bitset for andNot and 
intersection.
+      if (end > 1 && answer instanceof BitDocSet) {
+        FixedBitSet fixedBitSet =
+            FixedBitSet.ensureCapacity(answer.getFixedBitSetClone(), maxDoc());
+        answer = new MutableBitDocSet(fixedBitSet);

Review Comment:
   I suggest adding a small static utility method on MutableBitDocSet 
`fromBitDocSet` that takes only BitDocSet and maxDoc.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to