Skip to content

Commit f476334

Browse files
committed
Prepare for PartRanker
1 parent e48dd66 commit f476334

4 files changed

Lines changed: 646 additions & 261 deletions

File tree

common/src/java/com/github/oeuvres/alix/lucene/FlucNum.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,11 @@ public int numBytes()
397397
*
398398
* @param start inclusive focus start value
399399
* @param end inclusive focus end value
400-
* @param policy policy for incomplete extremity parts
400+
* @param policy policy for incomplete extremity parts, default is {@link PartialExtremityPolicy#ABSORB}
401401
* @param acceptedDocs optional accepted-documents bitset; {@code null} means
402402
* all documents with a value are accepted
403403
* @return document partition aligned by global Lucene doc id
404404
* @throws IOException if dense-cache construction fails
405-
* @throws NullPointerException if {@code policy == null}
406405
* @throws IllegalArgumentException if the focus interval is invalid, outside
407406
* the field value range, creates too many
408407
* parts for byte storage, or if

common/src/java/com/github/oeuvres/alix/lucene/Partition.java

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public final class Partition
5959
private final byte[] docPart;
6060

6161
/** Number of accepted documents per part. */
62-
private final int[] docs;
62+
private final int[] partDocs;
6363

6464
/** Optional focus part, or {@link #NO_FOCUS}. */
6565
private final int focusPart;
@@ -108,7 +108,7 @@ public final class Partition
108108
this.partCount = partCount;
109109
this.focusPart = focusPart;
110110
this.docPart = new byte[maxDoc];
111-
this.docs = new int[partCount];
111+
this.partDocs = new int[partCount];
112112

113113
Arrays.fill(docPart, NO_PART);
114114
}
@@ -154,19 +154,6 @@ public byte[] docPartRef()
154154
return docPart;
155155
}
156156

157-
/**
158-
* Returns the number of accepted documents in one part.
159-
*
160-
* @param part part id
161-
* @return document count for the part
162-
* @throws IllegalArgumentException if {@code part} is out of range
163-
*/
164-
public int docs(final int part)
165-
{
166-
checkPart(part);
167-
return docs[part];
168-
}
169-
170157
/**
171158
* Returns the focus part.
172159
*
@@ -207,6 +194,34 @@ public int partCount()
207194
return partCount;
208195
}
209196

197+
/**
198+
* Returns the number of accepted documents in one part.
199+
*
200+
* @param part part id
201+
* @return document count for the part
202+
* @throws IllegalArgumentException if {@code part} is out of range
203+
*/
204+
public int partDocs(final int part)
205+
{
206+
checkPart(part);
207+
return partDocs[part];
208+
}
209+
210+
/**
211+
* Returns the internal part to document count array.
212+
*
213+
* <p>
214+
* This method is intended for hot loops. The returned array must not be
215+
* modified.
216+
* </p>
217+
*
218+
* @return internal array indexed by part id
219+
*/
220+
public int[] partDocsRef()
221+
{
222+
return partDocs;
223+
}
224+
210225
/**
211226
* Returns a compact textual summary.
212227
*
@@ -219,7 +234,7 @@ public String toString()
219234
+ "{maxDoc=" + maxDoc
220235
+ ", partCount=" + partCount
221236
+ ", focusPart=" + focusPart
222-
+ ", docs=" + Arrays.toString(docs)
237+
+ ", docs=" + Arrays.toString(partDocs)
223238
+ '}';
224239
}
225240

@@ -272,7 +287,7 @@ void reject(final int docId)
272287
final byte oldPart = docPart[docId];
273288
if (oldPart == NO_PART) return;
274289

275-
docs[oldPart]--;
290+
partDocs[oldPart]--;
276291
docPart[docId] = NO_PART;
277292
}
278293

@@ -301,10 +316,10 @@ void set(final int docId, final int part)
301316
if (oldPart == newPart) return;
302317

303318
if (oldPart != NO_PART) {
304-
docs[oldPart]--;
319+
partDocs[oldPart]--;
305320
}
306321

307322
docPart[docId] = newPart;
308-
docs[newPart]++;
323+
partDocs[newPart]++;
309324
}
310325
}

common/src/java/com/github/oeuvres/alix/lucene/terms/TopTerms.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ public TopTerms partScore(
486486

487487
initFocus();
488488
this.focusTokens = partTokens[focusPart];
489-
this.focusDocs = partition.docs(focusPart);
489+
this.focusDocs = partition.partDocs(focusPart);
490490

491491
final int vocabSize = fieldStats.vocabSize();
492492
final double[] termScores = new double[vocabSize];
@@ -523,7 +523,7 @@ public TopTerms partScore(
523523
partTokens,
524524
focusPart,
525525
focusDocsForTerm,
526-
partition.docs(focusPart)
526+
partition.partDocs(focusPart)
527527
);
528528
if (!Double.isNaN(s)) {
529529
termScores[termId] = s;

0 commit comments

Comments
 (0)