lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sar...@apache.org
Subject [32/48] lucene-solr:jira/lucene-2562: LUCENE-8487: add IndexSearcher.getSlices
Date Tue, 17 Jul 2018 21:13:07 GMT
LUCENE-8487: add IndexSearcher.getSlices


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/224b7852
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/224b7852
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/224b7852

Branch: refs/heads/jira/lucene-2562
Commit: 224b78523390527200bba17e046ca3f683537496
Parents: 47a3a17
Author: Mike McCandless <mikemccand@apache.org>
Authored: Mon Jul 16 12:26:58 2018 -0400
Committer: Steve Rowe <sarowe@apache.org>
Committed: Tue Jul 17 12:22:31 2018 -0400

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  4 ++++
 .../org/apache/lucene/search/IndexSearcher.java | 16 +++++++++++--
 .../apache/lucene/search/TestIndexSearcher.java | 24 +++++++++++++++++++-
 3 files changed, 41 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/224b7852/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index f6958fd..d09f82e 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -140,6 +140,10 @@ API Changes:
 
 * LUCENE-8397: Add DirectoryTaxonomyWriter.getCache (Mike McCandless)
 
+* LUCENE-8387: Add experimental IndexSearcher.getSlices API to see which slices
+  IndexSearcher is searching concurrently when it's created with an ExecutorService
+  (Mike McCandless)
+
 Bug Fixes:
 
 * LUCENE-8380: UTF8TaxonomyWriterCache inconsistency. (Ruslan Torobaev, Dawid Weiss)

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/224b7852/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java
index 5a3c890..85a0006 100644
--- a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java
+++ b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java
@@ -90,7 +90,7 @@ public class IndexSearcher {
   protected final IndexReaderContext readerContext;
   protected final List<LeafReaderContext> leafContexts;
   /** used with executor - each slice holds a set of leafs executed within one thread */
-  protected final LeafSlice[] leafSlices;
+  private final LeafSlice[] leafSlices;
 
   // These are only used for multi-threaded search
   private final ExecutorService executor;
@@ -352,6 +352,14 @@ public class IndexSearcher {
     return search(query, collectorManager);
   }
 
+  /** Returns the leaf slices used for concurrent searching, or null if no {@code ExecutorService}
was
+   *  passed to the constructor.
+   *
+   * @lucene.experimental */
+  public LeafSlice[] getSlices() {
+      return leafSlices;
+  }
+  
   /** Finds the top <code>n</code>
    * hits for <code>query</code> where all results are after a previous 
    * result (<code>after</code>).
@@ -709,7 +717,11 @@ public class IndexSearcher {
    * @lucene.experimental
    */
   public static class LeafSlice {
-    final LeafReaderContext[] leaves;
+
+    /** The leaves that make up this slice.
+     *
+     *  @lucene.experimental */
+    public final LeafReaderContext[] leaves;
     
     public LeafSlice(LeafReaderContext... leaves) {
       this.leaves = leaves;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/224b7852/lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java b/lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java
index 8748a1a..206ee86 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java
@@ -25,8 +25,8 @@ import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
 import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.document.Field;
 import org.apache.lucene.document.SortedDocValuesField;
 import org.apache.lucene.document.StringField;
 import org.apache.lucene.index.IndexReader;
@@ -219,4 +219,26 @@ public class TestIndexSearcher extends LuceneTestCase {
     searcher = new IndexSearcher(new MultiReader());
     assertEquals(dummyPolicy, searcher.getQueryCachingPolicy());
   }
+
+  public void testGetSlices() throws Exception {
+    assertNull(new IndexSearcher(new MultiReader()).getSlices());
+
+    Directory dir = newDirectory();
+    RandomIndexWriter w = new RandomIndexWriter(random(), dir);
+    w.addDocument(new Document());
+    IndexReader r = w.getReader();
+    w.close();
+
+    ExecutorService service = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS,
+                                   new LinkedBlockingQueue<Runnable>(),
+                                   new NamedThreadFactory("TestIndexSearcher"));
+    IndexSearcher s = new IndexSearcher(r, service);
+    IndexSearcher.LeafSlice[] slices = s.getSlices();
+    assertNotNull(slices);
+    assertEquals(1, slices.length);
+    assertEquals(1, slices[0].leaves.length);
+    assertTrue(slices[0].leaves[0] == r.leaves().get(0));
+    service.shutdown();
+    IOUtils.close(r, dir);
+  }
 }


Mime
View raw message