romseygeek commented on a change in pull request #1440:
URL: https://github.com/apache/lucene-solr/pull/1440#discussion_r412829154



##########
File path: lucene/core/src/java/org/apache/lucene/index/IndexSorter.java
##########
@@ -0,0 +1,500 @@
+/*
+ * 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.index;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.lucene.search.FieldComparator;
+import org.apache.lucene.search.SortField;
+import org.apache.lucene.store.DataInput;
+import org.apache.lucene.store.DataOutput;
+import org.apache.lucene.util.LongValues;
+import org.apache.lucene.util.NumericUtils;
+import org.apache.lucene.util.packed.PackedInts;
+
+import static org.apache.lucene.search.DocIdSetIterator.NO_MORE_DOCS;
+
+/**
+ * Handles how documents should be sorted in an index, both within a segment 
and between
+ * segments.
+ *
+ * Implementers must provide the following methods:
+ * {@link #getDocComparator(LeafReader)} - an object that determines how 
documents within a segment are to be sorted
+ * {@link #getComparableProviders(List)} - an array of objects that return a 
sortable long value per document and segment
+ * {@link #serialize(DataOutput)} - how the sort should be written into the 
segment header
+ * {@link #getProviderName()} - the SPI-registered name of a {@link 
SortFieldProvider} to deserialize the sort
+ *
+ * The companion {@link SortFieldProvider} should be registered with SPI via 
{@code META-INF/services}
+ */
+public interface IndexSorter {
+
+  /** Used for sorting documents across segments */
+  public interface ComparableProvider {
+    /**
+     * Returns a long so that the natural ordering of long values matches the
+     * ordering of doc IDs for the given comparator
+     */
+    long getAsComparableLong(int docID) throws IOException;
+  }
+
+  /** A comparator of doc IDs, used for sorting documents within a segment */
+  public interface DocComparator {
+    /** Compare docID1 against docID2. The contract for the return value is the
+     *  same as {@link Comparator#compare(Object, Object)}. */
+    int compare(int docID1, int docID2);
+  }
+
+  /**
+   * Get an array of {@link ComparableProvider}, one per segment, for merge 
sorting documents in different segments
+   * @param readers the readers to be merged
+   */
+  public abstract ComparableProvider[] getComparableProviders(List<? extends 
LeafReader> readers) throws IOException;
+
+  /**
+   * Get a comparator that determines the sort order of docs within a single 
Reader.
+   *
+   * NB We cannot simply use the {@link FieldComparator} API because it 
requires docIDs to be sent
+   * in-order. The default implementations allocate array[maxDoc] to hold 
native values for comparison,
+   * but 1) they are transient (only alive while sorting this one segment) and 
2) in the typical
+   * index sorting case, they are only used to sort newly flushed segments, 
which will be smaller
+   * than merged segments
+   *
+   * @param reader the Reader to sort
+   */
+  public abstract DocComparator getDocComparator(LeafReader reader) throws 
IOException;
+
+  /**
+   * Serializes the parent SortField.  This is used to write Sort information 
into the Segment header
+   *
+   * @see SortFieldProvider#loadSortField(DataInput)
+   */
+  public abstract void serialize(DataOutput out) throws IOException;
+
+  /**
+   * The SPI-registered name of a {@link SortFieldProvider} that will 
deserialize the parent SortField
+   */
+  public abstract String getProviderName();
+
+  /**
+   * Provide a NumericDocValues instance for a LeafReader
+   */
+  public interface NumericDocValuesProvider {
+    /**
+     * Returns the NumericDocValues instance for this LeafReader
+     */
+    NumericDocValues get(LeafReader reader) throws IOException;
+  }
+
+  /**
+   * Provide a SortedDocValues instance for a LeafReader
+   */
+  public interface SortedDocValuesProvider {
+    /**
+     * Returns the SortedDocValues instance for this LeafReader
+     */
+    SortedDocValues get(LeafReader reader) throws IOException;
+  }
+
+  /**
+   * Serialize an object into a DataOutput
+   */
+  public interface Serializer {
+    /** Serializes an object into a DataOutput */
+    void serialize(DataOutput out) throws IOException;
+  }
+
+  /**
+   * Sorts documents based on integer values from a NumericDocValues instance
+   */
+  public static final class IntSorter implements IndexSorter {

Review comment:
       IndexSorter is an interface (started as an abstract class in a first 
iteration) so everything is public and static, and we don't need those 
modifiers anymore.




----------------------------------------------------------------
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