1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::core::index::impact::Impact;
use crate::core::util::error::lucene_error::Result;
/// Information about upcoming impacts, i.e., (freq, norm) pairs.
pub trait Impacts {
/// Return the number of levels on which we have impacts.
///
/// The returned value is always greater than 0 and may not always be the
/// same, even on a single postings list, depending on the current doc
/// ID.
fn num_levels(&self) -> usize;
/// Return the maximum inclusive doc ID until which the list of impacts
/// returned by `get_impacts(level)` is valid.
///
/// This is a non-decreasing function of `level`.
fn get_doc_id_upto(&self, level: usize) -> i32;
/// Return impacts on the given level.
///
/// These impacts are sorted by increasing frequency and increasing unsigned
/// norm, and only valid until the doc ID returned by
/// `get_doc_id_upto(level)` (inclusive).
///
/// The returned list is never empty and supports efficient random access when it contains more
/// than one element.
///
/// NOTE: There is no guarantee that these impacts actually appear in
/// postings, only that they trigger scores that are greater than or
/// equal to the impacts that actually appear in postings.
fn get_impacts(&self, level: usize) -> Result<Vec<Impact>>;
}
macro_rules! define_impacts_enum {
(
$enum_name:ident,
[$($V:ident),+ $(,)?]
) => {
pub enum $enum_name<$($V),+> {
$($V($V)),+
}
impl<$($V),+> Impacts for $enum_name<$($V),+>
where
$($V: Impacts,)+
{
fn num_levels(&self) -> usize {
match self {
$(Self::$V(t) => t.num_levels(),)+
}
}
fn get_doc_id_upto(&self, level: usize) -> i32 {
match self {
$(Self::$V(t) => t.get_doc_id_upto(level),)+
}
}
fn get_impacts(&self, level: usize) -> Result<Vec<Impact>> {
match self {
$(Self::$V(t) => t.get_impacts(level),)+
}
}
}
};
}
define_impacts_enum!(ImpactsEnum2, [A, B]);