Skip to content

Commit 1084790

Browse files
committed
Suggest works
1 parent 2072cca commit 1084790

9 files changed

Lines changed: 784 additions & 557 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public final class FieldStats
162162
private volatile double[] termWeights;
163163

164164
/** The scorer used to calculate {@link #termWeights}. */
165-
private volatile TermScorer termWeightsScorer;
165+
private volatile IdfTermScorer termWeightsScorer;
166166

167167
/**
168168
* Creates an immutable statistics object from already-loaded arrays and derived scalars.
@@ -301,7 +301,7 @@ public static void build(final IndexReader reader, final Path sideDir, final Str
301301
* <p>
302302
* When {@code focusDocs} is non-null, the focus subset's token total and document
303303
* count are derived from the bitset and {@link #docTokens}, then passed to
304-
* {@link TermScorer#focus}. Each posting visit then tells the scorer whether the
304+
* {@link IdfTermScorer#focus}. Each posting visit then tells the scorer whether the
305305
* document is in focus, and the scorer accumulates into focus or rest separately.
306306
* </p>
307307
*
@@ -312,7 +312,7 @@ public static void build(final IndexReader reader, final Path sideDir, final Str
312312
* @throws IOException if term or postings iteration fails
313313
* @throws IllegalStateException if the field has no terms or no frequencies
314314
*/
315-
public double[] buildTermWeights(final IndexReader reader, final TermScorer scorer)
315+
public double[] buildTermWeights(final IndexReader reader, final IdfTermScorer scorer)
316316
throws IOException
317317
{
318318
Objects.requireNonNull(reader, "reader");
@@ -917,7 +917,7 @@ public static TermStats termStats(final IndexReader reader, final String field,
917917
*
918918
* @param termId dense term id in {@code [0, vocabSize)}
919919
* @return cached weight, or {@code 0.0} for the absent-term sentinel (id 0)
920-
* @throws IllegalStateException if {@link #termWeights(IndexReader, TermScorer)} has not been called
920+
* @throws IllegalStateException if {@link #termWeights(IndexReader, IdfTermScorer)} has not been called
921921
* @throws IllegalArgumentException if {@code termId} is out of range
922922
*/
923923
public double termWeight(final int termId)
@@ -951,7 +951,7 @@ public double[] termWeightsRef()
951951
* @return weight vector indexed by dense term id
952952
* @throws IOException if term iteration fails
953953
*/
954-
public double[] termWeights(final IndexReader reader, final TermScorer scorer) throws IOException
954+
public double[] termWeights(final IndexReader reader, final IdfTermScorer scorer) throws IOException
955955
{
956956
Objects.requireNonNull(reader, "reader");
957957
Objects.requireNonNull(scorer, "scorer");

common/src/java/com/github/oeuvres/alix/lucene/terms/TermScorer.java renamed to common/src/java/com/github/oeuvres/alix/lucene/terms/IdfTermScorer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* Stateful. One instance must not be reused concurrently.
3131
* </p>
3232
*/
33-
public abstract class TermScorer
33+
public abstract class IdfTermScorer
3434
{
3535

3636
/** Total token count of the full corpus/field. */
@@ -191,7 +191,7 @@ public int hashCode()
191191
* {@code 2 × docTermFreq × ln(docTermFreq / expected)}.
192192
* Positive when over-represented, negative when under-represented.
193193
*/
194-
public static class G extends TermScorer
194+
public static class G extends IdfTermScorer
195195
{
196196
@Override
197197
public double termDocAdd(final long docTermFreq, final long docTokens, final boolean inFocus)
@@ -214,7 +214,7 @@ public double termDocAdd(final long docTermFreq, final long docTokens, final boo
214214
/**
215215
* Count-form Jaccard: {@code docTermFreq / (docTokens + corpusTermFreq - docTermFreq)}.
216216
*/
217-
public static class Jaccard extends TermScorer
217+
public static class Jaccard extends IdfTermScorer
218218
{
219219
@Override
220220
public double termDocAdd(final long docTermFreq, final long docTokens, final boolean inFocus)
@@ -252,7 +252,7 @@ public double termDocAdd(final long docTermFreq, final long docTokens, final boo
252252
* a matter of editing {@code result()} to the alternative formula.
253253
* </p>
254254
*/
255-
public static class BM25 extends TermScorer
255+
public static class BM25 extends IdfTermScorer
256256
{
257257
/** Term frequency saturation. */
258258
protected double k1 = 1.2d;
@@ -429,7 +429,7 @@ public int hashCode()
429429
}
430430
}
431431

432-
public static class DklContrast extends TermScorer
432+
public static class DklContrast extends IdfTermScorer
433433
{
434434
/** Σ tf_i on focus side for current term. */
435435
protected long focusTermFreqAcc;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public TopTerms suggest(
160160

161161
final String foldedQuery = Char.toAscii(infix);
162162
if (foldedQuery.isEmpty()) {
163-
return source.setRanking(new int[0], null, null);
163+
return source.rank(limit);
164164
}
165165

166166
final boolean prefixOnly = foldedQuery.length() < INFIX_THRESHOLD;

0 commit comments

Comments
 (0)