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
/// Control how the total number of hits should be tracked.
///
/// When set to `Track` with a value `true`, the response will always track the number of hits that
/// match the query accurately.
///
/// When set to `Count` with an integer value `n`, the response accurately tracks the total
/// hit count that match the query up to `n` documents.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum TrackTotalHits {
/// Whether to accurately track the number of hits that match the query accurately
Track(bool),
/// Accurately track the number of hits up to the specified value
Count(i64),
}
impl From<bool> for TrackTotalHits {
fn from(value: bool) -> Self {
TrackTotalHits::Track(value)
}
}
impl From<i64> for TrackTotalHits {
fn from(value: i64) -> Self {
TrackTotalHits::Count(value)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::util::*;
#[test]
fn serialization() {
assert_serialize(
[
TrackTotalHits::Track(false),
TrackTotalHits::Track(true),
TrackTotalHits::Count(10),
],
json!([false, true, 10,]),
)
}
}