5
5
import java .io .IOException ;
6
6
import org .apache .lucene .index .LeafReaderContext ;
7
7
import org .apache .lucene .index .NumericDocValues ;
8
- import org .apache .lucene .search .Collector ;
9
- import org .apache .lucene .search .LeafCollector ;
10
- import org .apache .lucene .search .Scorable ;
11
8
import org .apache .lucene .search .ScoreMode ;
9
+ import org .apache .lucene .search .SimpleCollector ;
12
10
13
- public class StatsCollector implements Collector {
11
+ public class StatsCollector extends SimpleCollector {
14
12
15
13
public final Histogram histogram ;
16
14
private NumericDocValues docValues ;
@@ -22,21 +20,8 @@ public StatsCollector(Histogram histogram) {
22
20
}
23
21
24
22
@ Override
25
- public LeafCollector getLeafCollector ( LeafReaderContext context ) throws IOException {
23
+ protected void doSetNextReader ( final LeafReaderContext context ) throws IOException {
26
24
docValues = context .reader ().getNumericDocValues (SystemField .TIME_SINCE_EPOCH .fieldName );
27
-
28
- return new LeafCollector () {
29
- @ Override
30
- public void setScorer (Scorable scorer ) {}
31
-
32
- @ Override
33
- public void collect (int doc ) throws IOException {
34
- if (docValues != null && docValues .advanceExact (doc )) {
35
- long timestamp = docValues .longValue ();
36
- histogram .add (timestamp );
37
- }
38
- }
39
- };
40
25
}
41
26
42
27
public Histogram getHistogram () {
@@ -47,4 +32,12 @@ public Histogram getHistogram() {
47
32
public ScoreMode scoreMode () {
48
33
return ScoreMode .COMPLETE_NO_SCORES ;
49
34
}
35
+
36
+ @ Override
37
+ public void collect (int doc ) throws IOException {
38
+ if (docValues != null && docValues .advanceExact (doc )) {
39
+ long timestamp = docValues .longValue ();
40
+ histogram .add (timestamp );
41
+ }
42
+ }
50
43
}
0 commit comments