zihanx opened a new pull request, #16572:
URL: https://github.com/apache/lucene/pull/16572

   ### Description
   
   Adds a reusable utility for fetching "return fields" — one value per hit for 
a set of
   global doc IDs — concurrently across leaves, returning results 1:1 in the 
caller's input
   order. This is the follow-up to the `ReaderUtil.partitionByLeaf` 
scatter/gather API
   #16496; it builds the retriever the ordinal tracking was designed for.
   
   ### Motivation
   
   Fetching field values for a page of hits (in ranking order) is a common 
need, and getting
   the leaf partitioning + concurrency + input-order reassembly right is tricky 
and easy to
   get subtly wrong. Today callers hand-roll this. This packages it once.
   
   ### What's included
   
   Two classes:
   
   - **`ReturnFieldsRetriever`** — the generic engine. Owns only the reusable 
machinery:
     scatter doc IDs to leaves via `ReaderUtil.partitionByLeaf`, run each leaf 
as an
     independent task on a supplied `Executor` (via `TaskExecutor`), and gather 
per-leaf
     results back into input order. It is agnostic about *what* is produced per 
hit: the
     caller supplies a `LeafVisitorFactory<T>` that turns a document into a 
value of type `T`.
   
       ```java
       public static <T> T[] retrieve(
           IndexReader reader, int[] globalDocIds,
           LeafVisitorFactory<T> factory, IntFunction<T[]> arrayFactory, 
Executor executor)
       ```
   
   - **`DoubleValuesRetriever`** — a thin `DoubleValuesSource`-specific 
specialization built
     on the engine. Adapts each source to a `LeafVisitor<double[]>`:
   
       ```java
       public static double[][] retrieve(
           IndexReader reader, int[] globalDocIds, DoubleValuesSource[] 
sources, Executor executor)
       ```
   
   ### Design notes
   
   - **Concurrency contract:** leaves run concurrently, so `newLeafVisitor` is 
called once per
     leaf and must return a fresh, single-threaded visitor. Each leaf writes 
disjoint slots of the result array,
     so no synchronization is needed.
   - **Input order preserved:** `result[i]` is the value for `globalDocIds[i]`. 
The input
     array is not mutated.
   


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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to