You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: common/src/java/com/github/oeuvres/alix/lucene/spans/SpanWalker.java
+49-28Lines changed: 49 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -17,48 +17,57 @@
17
17
importorg.apache.lucene.search.Weight;
18
18
19
19
/**
20
-
* Streams the matches of a {@link SpanQuery}, optionally intersected with a non-scoring filter, to a {@link SpanListener}, in natural index order.
20
+
* Streams the matches of a {@link SpanQuery}, optionally intersected with a non-scoring filter, to
21
+
* a {@link SpanListener}, in natural index order.
21
22
*
22
23
* <p>
23
-
* No matches are retained in memory; per-match state is owned by the listener. If the index is sorted, natural order is the index sort order.
24
+
* No matches are retained in memory; per-match state is owned by the listener. If the index is
25
+
* sorted, natural order is the index sort order.
24
26
* </p>
25
27
*
26
28
* <h2>Pagination</h2>
27
29
*
28
30
* <p>
29
-
* {@link #walk(int)} accepts a global docId cursor (inclusive). The first call passes {@code 0}; subsequent calls pass the value returned by the previous call, which is the first unprocessed docId, or {@code -1} when the walk has completed.
31
+
* {@link #walk(int)} accepts a global docId cursor (inclusive). The first call passes {@code 0};
32
+
* subsequent calls pass the value returned by the previous call, which is the first unprocessed
33
+
* docId, or {@code -1} when the walk has completed.
30
34
* </p>
31
35
*
32
36
* <h2>Filter query</h2>
33
37
*
34
38
* <p>
35
-
* Filter constraints (dates, tags…) belong in {@code filterQuery}. The walker leapfrogs the span and filter iterators per leaf, advancing whichever lags. With an {@link IndexSearcher} backed by an {@code LRUQueryCache}, filter results are cached across requests.
39
+
* Filter constraints (dates, tags…) belong in {@code filterQuery}. The walker leapfrogs the span
40
+
* and filter iterators per leaf, advancing whichever lags. With an {@link IndexSearcher} backed by
41
+
* an {@code LRUQueryCache}, filter results are cached across requests.
36
42
* </p>
37
43
*
38
44
* <h2>Document count</h2>
39
45
*
40
46
* <p>
41
-
* {@link #hits()} performs a separate full-count scan and is independent of {@link #walk(int)}. Call it on demand only.
47
+
* {@link #hits()} performs a separate full-count scan and is independent of {@link #walk(int)}.
48
+
* Call it on demand only.
42
49
* </p>
43
50
*/
44
51
publicfinalclassSpanWalker
45
52
{
46
53
privatestaticfinalintINITIAL_LEAF_CAPACITY = 8;
47
-
54
+
48
55
privatefinalIndexSearchersearcher;
49
56
privatefinalSpanQueryspanQuery;
50
57
privatefinalQueryfilterQuery;
51
58
privatefinalSpanListenerlistener;
52
-
59
+
53
60
/**
54
-
* Creates a walker bound to a query, an optional filter, and a listener. Both queries are rewritten once, here.
61
+
* Creates a walker bound to a query, an optional filter, and a listener. Both queries are
62
+
* rewritten once, here.
55
63
*
56
64
* @param searcher used for query rewrite and leaf access
57
65
* @param spanQuery span query to enumerate
58
66
* @param filterQuery non-scoring filter, or {@code null}
59
67
* @param listener consumer of streamed matches
60
68
* @throws IOException on rewrite failure
61
-
* @throws NullPointerException if {@code searcher}, {@code spanQuery}, or {@code listener} is {@code null}
69
+
* @throws NullPointerException if {@code searcher}, {@code spanQuery}, or {@code listener} is
* Counts the documents matched by the span query intersected with the optional filter. Performs a full scan; does not interact with {@link #walk(int)}.
86
+
* Counts the documents matched by the span query intersected with the optional filter. Performs
87
+
* a full scan; does not interact with {@link #walk(int)}.
78
88
*
79
89
* @return matching document count
80
90
* @throws IOException on I/O failure
@@ -89,16 +99,22 @@ public int hits() throws IOException
89
99
.build();
90
100
returnsearcher.count(countQuery);
91
101
}
92
-
102
+
93
103
/**
94
104
* Streams matches to the listener starting at the given global docId (inclusive).
95
105
*
96
106
* <p>
97
-
* Each matching document is visited once, in natural order; for each document the matches are delivered in ascending start-position order. The listener may stop the walk at any document boundary by returning {@code false} from {@link SpanListener#wantsMoreDocs()}.
107
+
* Each matching document is visited once, in natural order; for each document the matches are
108
+
* delivered in ascending start-position order. The listener may stop the walk at any document
109
+
* boundary by returning {@code false} from {@link SpanListener#wantsMoreDocs()}.
98
110
* </p>
99
111
*
100
112
* <p>
101
-
* Per match the walker performs the canonical {@link SpanMatch} lifecycle: {@link SpanMatch#reset()}, {@link SpanMatch#range(int, int)} from {@link Spans#startPosition()} / {@link Spans#endPosition()}, {@link SpanMatch#ord(int)}, then {@link Spans#collect(org.apache.lucene.queries.spans.SpanCollector)} and {@link SpanMatch#sort()}.
113
+
* Per match the walker performs the canonical {@link SpanMatch} lifecycle:
114
+
* {@link SpanMatch#reset()}, {@link SpanMatch#range(int, int)} from
115
+
* {@link Spans#startPosition()} / {@link Spans#endPosition()}, {@link SpanMatch#ord(int)}, then
116
+
* {@link Spans#collect(org.apache.lucene.queries.spans.SpanCollector)} and
117
+
* {@link SpanMatch#sort()}.
102
118
* </p>
103
119
*
104
120
* @param docStart first global docId to visit, inclusive; pass {@code 0} on the first call
@@ -112,46 +128,51 @@ public int walk(final int docStart) throws IOException
0 commit comments