You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2021/01/29 18:00:59 UTC

[GitHub] [lucene-solr] mikemccand commented on a change in pull request #2256: LUCENE-9507 Custom order for leaves in IndexReader and IndexWriter

mikemccand commented on a change in pull request #2256:
URL: https://github.com/apache/lucene-solr/pull/2256#discussion_r566993804



##########
File path: lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
##########
@@ -941,6 +969,11 @@ public IndexWriter(Directory d, IndexWriterConfig conf) throws IOException {
     // obtain the write.lock. If the user configured a timeout,
     // we wrap with a sleeper and this might take some time.
     writeLock = d.obtainLock(WRITE_LOCK_NAME);
+    if (config.getIndexSort() != null && leafSorter != null) {
+      throw new IllegalArgumentException(
+          "[IndexWriter] can't use index sort and leaf sorter at the same time!");

Review comment:
       Hmm, why is that?  I thought this change sorts whole segments, and index sorting sorts documents within one segment?  Why do they conflict?

##########
File path: lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
##########
@@ -933,6 +936,31 @@ protected final void ensureOpen() throws AlreadyClosedException {
    *     low-level IO error
    */
   public IndexWriter(Directory d, IndexWriterConfig conf) throws IOException {
+    this(d, conf, null);
+  }
+
+  /**
+   * Constructs a new IndexWriter per the settings given in <code>conf</code>. If you want to make
+   * "live" changes to this writer instance, use {@link #getConfig()}.
+   *
+   * <p><b>NOTE:</b> after ths writer is created, the given configuration instance cannot be passed
+   * to another writer.
+   *
+   * @param d the index directory. The index is either created or appended according <code>
+   *     conf.getOpenMode()</code>.
+   * @param conf the configuration settings according to which IndexWriter should be initialized.
+   * @param leafSorter a comparator for sorting leaf readers. Providing leafSorter is useful for
+   *     indices on which it is expected to run many queries with particular sort criteria (e.g. for
+   *     time-based indices this is usually a descending sort on timestamp). In this case {@code
+   *     leafSorter} should sort leaves according to this sort criteria. Providing leafSorter allows
+   *     to speed up this particular type of sort queries by early terminating while iterating
+   *     though segments and segments' documents.
+   * @throws IOException if the directory cannot be read/written to, or if it does not exist and
+   *     <code>conf.getOpenMode()</code> is <code>OpenMode.APPEND</code> or if there is any other
+   *     low-level IO error
+   */
+  public IndexWriter(Directory d, IndexWriterConfig conf, Comparator<LeafReader> leafSorter)

Review comment:
       Should `leafSorter` instead be added to `IndexWriterConfig`?




----------------------------------------------------------------
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:
users@infra.apache.org



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