kite/collectors/
total_count.rs1use collectors::{Collector, DocumentMatch};
2
3
4pub struct TotalCountCollector {
5 total_count: u64,
6}
7
8
9impl TotalCountCollector {
10 pub fn new() -> TotalCountCollector {
11 TotalCountCollector {
12 total_count: 0,
13 }
14 }
15
16 pub fn get_total_count(&self) -> u64 {
17 self.total_count
18 }
19}
20
21
22impl Collector for TotalCountCollector {
23 fn needs_score(&self) -> bool {
24 false
25 }
26
27 fn collect(&mut self, _doc: DocumentMatch) {
28 self.total_count += 1;
29 }
30}
31
32
33#[cfg(test)]
34mod tests {
35 use collectors::{Collector, DocumentMatch};
36 use super::TotalCountCollector;
37
38
39 #[test]
40 fn test_total_count_collector_inital_state() {
41 let collector = TotalCountCollector::new();
42
43 assert_eq!(collector.get_total_count(), 0);
44 }
45
46 #[test]
47 fn test_total_count_collector_needs_score() {
48 let collector = TotalCountCollector::new();
49
50 assert_eq!(collector.needs_score(), false);
51 }
52
53 #[test]
54 fn test_total_count_collector_collect() {
55 let mut collector = TotalCountCollector::new();
56
57 collector.collect(DocumentMatch::new_unscored(0));
58 collector.collect(DocumentMatch::new_unscored(1));
59 collector.collect(DocumentMatch::new_unscored(2));
60
61 assert_eq!(collector.get_total_count(), 3);
62 }
63}