jpountz commented on a change in pull request #857: LUCENE-8968: Improve 
performance of WITHIN and DISJOINT queries for Shape queries
URL: https://github.com/apache/lucene-solr/pull/857#discussion_r322441239
 
 

 ##########
 File path: lucene/sandbox/src/java/org/apache/lucene/document/ShapeQuery.java
 ##########
 @@ -373,49 +235,265 @@ protected Scorer getIntersectsScorer(ShapeQuery query, 
LeafReader reader, Weight
         // by computing the set of documents that do NOT match the query
         final FixedBitSet result = new FixedBitSet(reader.maxDoc());
         result.set(0, reader.maxDoc());
-        int[] cost = new int[]{reader.maxDoc()};
-        values.intersect(getInverseIntersectVisitor(query, result, cost));
+        final long[] cost = new long[]{reader.maxDoc()};
+        values.intersect(getInverseDenseVisitor(query, result, cost));
         final DocIdSetIterator iterator = new BitSetIterator(result, cost[0]);
         return new ConstantScoreScorer(weight, boost, scoreMode, iterator);
       }
-
-      values.intersect(visitor);
-      DocIdSetIterator iterator = docIdSetBuilder.build().iterator();
+      final DocIdSetBuilder docIdSetBuilder = new 
DocIdSetBuilder(reader.maxDoc(), values, query.getField());
+      values.intersect(getSparseVisitor(query, docIdSetBuilder));
+      final DocIdSetIterator iterator = docIdSetBuilder.build().iterator();
       return new ConstantScoreScorer(weight, boost, scoreMode, iterator);
     }
 
-    /** returns a Scorer for all other (non INTERSECT) queries */
-    protected Scorer getScorer(ShapeQuery query, Weight weight,
-                               FixedBitSet intersect, FixedBitSet disjoint, 
final float boost, ScoreMode scoreMode) throws IOException {
-      values.intersect(visitor);
-      if (disjointVisitor != null) {
-        values.intersect(disjointVisitor);
-      }
-      DocIdSetIterator iterator;
-      if (query.queryRelation == ShapeField.QueryRelation.DISJOINT) {
-        disjoint.andNot(intersect);
-        iterator = new BitSetIterator(disjoint, cost());
-      } else if (query.queryRelation == ShapeField.QueryRelation.WITHIN) {
-        intersect.andNot(disjoint);
-        iterator = new BitSetIterator(intersect, cost());
+    /** Scorer used for WITHIN and DISJOINT **/
+    private Scorer getDenseScorer(LeafReader reader, Weight weight, final 
float boost, ScoreMode scoreMode) throws IOException {
+      final FixedBitSet result = new FixedBitSet(reader.maxDoc());
+      final long[] cost;
+      if (values.getDocCount() == reader.maxDoc()) {
+        // First we check if we have any hits so we are fast in the 
adversarial case where
+        // the shape does not match any documents
+        if (hasAnyHits(query, values) == false) {
+          // no hits so we can return
+          return new ConstantScoreScorer(weight, boost, scoreMode, 
DocIdSetIterator.empty());
+        }
 
 Review comment:
   it'd be slightly better to handle this case in the scorer supplier to return 
a null scorer

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to