Skip to content

Commit 81e1dfa

Browse files
committed
Refactor SpanListener
1 parent 80645f0 commit 81e1dfa

4 files changed

Lines changed: 15 additions & 19 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
import org.apache.lucene.index.StoredFields;
99

1010
import com.github.oeuvres.alix.lucene.spans.OffsetsCollector;
11+
import com.github.oeuvres.alix.lucene.spans.SpanListener;
1112
import com.github.oeuvres.alix.util.Detagger;
1213
import com.github.oeuvres.alix.util.Markup;
1314

1415
import static com.github.oeuvres.alix.common.Names.*;
1516

1617
/**
17-
* A {@link ResultsListener} that writes span search results as an HTML fragment.
18+
* A {@link SpanListener} that writes span search results as an HTML fragment.
1819
*
1920
* <p>Each matching document becomes an {@code <article>} element containing an
2021
* ordered list of span concordance lines. Each line shows a left context, one or
@@ -28,7 +29,7 @@
2829
* ({@link #lastDocId} + 1). The caller is responsible for turning that into a
2930
* full URL.</p>
3031
*/
31-
public class HtmlResults extends ResultsListener
32+
public class HtmlResults extends SpanListener
3233
{
3334
private final Writer writer;
3435
private final StoredFields storedFields;

common/src/java/com/github/oeuvres/alix/lucene/ResultsListener.java renamed to common/src/java/com/github/oeuvres/alix/lucene/spans/SpanListener.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
package com.github.oeuvres.alix.lucene;
1+
package com.github.oeuvres.alix.lucene.spans;
22

33
import java.io.IOException;
44

55
import org.apache.lucene.queries.spans.SpanQuery;
66
import org.apache.lucene.search.Query;
77

8-
import com.github.oeuvres.alix.lucene.spans.OffsetsCollector;
9-
108

119
/**
1210
* Receives streamed query results from a walker.
@@ -30,7 +28,7 @@
3028
* exhausted, {@code false} if {@link #wantsMoreDocs()} cut traversal short</li>
3129
* </ol>
3230
*/
33-
public abstract class ResultsListener
31+
public abstract class SpanListener
3432
{
3533

3634

common/src/java/com/github/oeuvres/alix/lucene/spans/SpanVisitor.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
import org.apache.lucene.search.IndexSearcher;
1212
import org.apache.lucene.search.ScoreMode;
1313

14-
import com.github.oeuvres.alix.lucene.ResultsListener;
1514
import com.github.oeuvres.alix.lucene.terms.FieldStats;
1615
import com.github.oeuvres.alix.lucene.terms.TermRail;
1716
import com.github.oeuvres.alix.util.TopSlot;
1817

1918
/**
2019
* Visits individual documents for a {@link SpanQuery}, scores spans by passage
21-
* informativeness, and streams the top spans to a {@link ResultsListener}.
20+
* informativeness, and streams the top spans to a {@link SpanListener}.
2221
*
2322
* <p>The caller controls the outer loop — typically over a {@code ScoreDoc[]}
2423
* returned by {@link org.apache.lucene.search.IndexSearcher#search}:</p>
@@ -55,7 +54,7 @@ public final class SpanVisitor {
5554

5655
private final IndexSearcher searcher;
5756
private final SpanQuery spanQuery;
58-
private final ResultsListener listener;
57+
private final SpanListener listener;
5958
private final FieldStats fieldStats;
6059
private final TermRail termRail;
6160

@@ -116,7 +115,7 @@ public final class SpanVisitor {
116115
public SpanVisitor(
117116
final IndexSearcher searcher,
118117
final SpanQuery spanQuery,
119-
final ResultsListener listener,
118+
final SpanListener listener,
120119
final FieldStats fieldStats,
121120
final TermRail termRail,
122121
final int topSpans,
@@ -145,7 +144,7 @@ public SpanVisitor(
145144
/**
146145
* Returns the total number of spans found in the most recently visited document,
147146
* including those not emitted. Useful for the caller to pass to
148-
* {@link ResultsListener#endDoc(int)}.
147+
* {@link SpanListener#endDoc(int)}.
149148
*
150149
* @return total span count for the last {@link #visit} call
151150
*/
@@ -157,8 +156,8 @@ public int spanTotal() {
157156
* Visits one document: enumerates all its spans, scores them by passage
158157
* informativeness, and emits the top spans to the listener.
159158
*
160-
* <p>The caller must have already called {@link ResultsListener#startDoc}
161-
* before this method, and must call {@link ResultsListener#endDoc} after.</p>
159+
* <p>The caller must have already called {@link SpanListener#startDoc}
160+
* before this method, and must call {@link SpanListener#endDoc} after.</p>
162161
*
163162
* @param docId global Lucene doc id
164163
* @throws IOException if index access or listener output fails

common/src/java/com/github/oeuvres/alix/lucene/spans/SpanWalker.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616
import org.apache.lucene.search.Scorer;
1717
import org.apache.lucene.search.Weight;
1818

19-
import com.github.oeuvres.alix.lucene.ResultsListener;
20-
2119
/**
2220
* Walks a {@link SpanQuery} in natural/index order, optionally intersected with a
23-
* non-scoring filter query (dates, tags…), and streams results to a {@link ResultsListener}.
21+
* non-scoring filter query (dates, tags…), and streams results to a {@link SpanListener}.
2422
*
2523
* <p>Traversal is streaming: no results are retained in memory. If the index was built
2624
* with an index sort, natural order is that sort order.</p>
@@ -32,7 +30,7 @@
3230
* the last docId it wrote; the next page passes {@code lastDocId + 1} as {@code docStart}.</p>
3331
*
3432
* <p>Whether a page ended by natural exhaustion or by the listener is reported via
35-
* {@link ResultsListener#end(boolean)}: {@code true} means the index is fully exhausted and
33+
* {@link SpanListener#end(boolean)}: {@code true} means the index is fully exhausted and
3634
* no further pages exist; {@code false} means more results are available.</p>
3735
*
3836
* <h2>Exact document count</h2>
@@ -52,7 +50,7 @@ public final class SpanWalker {
5250
private final IndexSearcher searcher;
5351
private final SpanQuery spanQuery;
5452
private final Query filterQuery; // nullable
55-
private final ResultsListener listener;
53+
private final SpanListener listener;
5654

5755
/**
5856
* Creates a natural-order span walker.
@@ -67,7 +65,7 @@ public SpanWalker(
6765
final IndexSearcher searcher,
6866
final SpanQuery spanQuery,
6967
final Query filterQuery,
70-
final ResultsListener listener) throws IOException {
68+
final SpanListener listener) throws IOException {
7169
this.searcher = Objects.requireNonNull(searcher, "searcher");
7270
Objects.requireNonNull(spanQuery, "spanQuery");
7371
this.spanQuery = (SpanQuery) searcher.rewrite(spanQuery);

0 commit comments

Comments
 (0)