jimczi commented on a change in pull request #1725:
URL: https://github.com/apache/lucene-solr/pull/1725#discussion_r468774381



##########
File path: lucene/core/src/java/org/apache/lucene/search/FieldValueHitQueue.java
##########
@@ -160,18 +160,20 @@ private FieldValueHitQueue(SortField[] fields, int size, 
boolean filterNonCompet
    *          The number of hits to retain. Must be greater than zero.
    * @param filterNonCompetitiveDocs
    *    {@code true} If comparators should be allowed to filter 
non-competitive documents, {@code false} otherwise
+   * @param hasAfter
+   *    {@code true} If this sort has "after" FieldDoc
    */
   public static <T extends FieldValueHitQueue.Entry> FieldValueHitQueue<T> 
create(SortField[] fields, int size,
-      boolean filterNonCompetitiveDocs) {
+      boolean filterNonCompetitiveDocs, boolean hasAfter) {

Review comment:
       Can we avoid adding `hasAfter` here ? See my comment below.

##########
File path: 
lucene/core/src/java/org/apache/lucene/search/FilteringDocLeafComparator.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.lucene.search;
+
+import org.apache.lucene.index.LeafReaderContext;
+
+import java.io.IOException;
+
+/**
+ * This comparator is used when there is sort by _doc asc together with 
"after" FieldDoc.
+ * The comparator provides an iterator that can quickly skip to the desired 
"after" document.
+ */
+public class FilteringDocLeafComparator implements 
FilteringLeafFieldComparator {
+    private final FieldComparator.DocComparator in;
+    private DocIdSetIterator topValueIterator; // iterator that starts from 
topValue if possible
+    private final int minDoc;
+    private final int maxDoc;
+    private final int docBase;
+    private boolean iteratorUpdated = false;
+
+    public FilteringDocLeafComparator(LeafFieldComparator in, 
LeafReaderContext context) {

Review comment:
       Can we force the `in` to be a `FieldComparator.DocComparator` ? 

##########
File path: 
lucene/core/src/java/org/apache/lucene/search/FilteringFieldComparator.java
##########
@@ -68,10 +68,12 @@ public int compareValues(T first, T second) {
    * @param comparator – comparator to wrap
    * @param reverse – if this sort is reverse
    * @param singleSort – true if this sort is based on a single field and 
there are no other sort fields for tie breaking
+   * @param hasAfter – true if this sort has after FieldDoc
    * @return comparator wrapped as a filtering comparator or the original 
comparator if the filtering functionality
    * is not implemented for it
    */
-  public static FieldComparator<?> 
wrapToFilteringComparator(FieldComparator<?> comparator, boolean reverse, 
boolean singleSort) {
+  public static FieldComparator<?> 
wrapToFilteringComparator(FieldComparator<?> comparator, boolean reverse, 
boolean singleSort,
+      boolean hasAfter) {

Review comment:
       Do we really need to add the `hasAfter` ? Can we check the if the 
`topValue` in the DocComparator is greater than 0 instead ?

##########
File path: lucene/core/src/java/org/apache/lucene/search/FieldValueHitQueue.java
##########
@@ -121,7 +121,7 @@ protected boolean lessThan(final Entry hitA, final Entry 
hitB) {
   }
   
   // prevent instantiation and extension.
-  private FieldValueHitQueue(SortField[] fields, int size, boolean 
filterNonCompetitiveDocs) {
+  private FieldValueHitQueue(SortField[] fields, int size, boolean 
filterNonCompetitiveDocs, boolean hasAfter) {

Review comment:
       Not sure that `hasAfter` is really needed here.

##########
File path: 
lucene/core/src/java/org/apache/lucene/search/FilteringDocLeafComparator.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.lucene.search;
+
+import org.apache.lucene.index.LeafReaderContext;
+
+import java.io.IOException;
+
+/**
+ * This comparator is used when there is sort by _doc asc together with 
"after" FieldDoc.
+ * The comparator provides an iterator that can quickly skip to the desired 
"after" document.
+ */
+public class FilteringDocLeafComparator implements 
FilteringLeafFieldComparator {

Review comment:
       Maybe rename to `AfterDocLeafComparator` ?

##########
File path: lucene/core/src/java/org/apache/lucene/search/FieldValueHitQueue.java
##########
@@ -95,8 +95,8 @@ protected boolean lessThan(final Entry hitA, final Entry 
hitB) {
    */
   private static final class MultiComparatorsFieldValueHitQueue<T extends 
FieldValueHitQueue.Entry> extends FieldValueHitQueue<T> {
 
-    public MultiComparatorsFieldValueHitQueue(SortField[] fields, int size, 
boolean filterNonCompetitiveDocs) {
-      super(fields, size, filterNonCompetitiveDocs);
+    public MultiComparatorsFieldValueHitQueue(SortField[] fields, int size, 
boolean filterNonCompetitiveDocs, boolean hasAfter) {

Review comment:
       Not sure that `hasAfter` is really needed 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.

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



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

Reply via email to