use serde::{Deserialize, Serialize};
#[derive(
Clone, Copy, Debug, PartialEq, PartialOrd, Ord, Eq, Hash, Serialize, Deserialize, Default,
)]
pub enum IndexRecordOption {
#[serde(rename = "basic")]
#[default]
Basic,
#[serde(rename = "freq")]
WithFreqs,
#[serde(rename = "position")]
WithFreqsAndPositions,
}
impl IndexRecordOption {
pub fn has_freq(self) -> bool {
match self {
IndexRecordOption::Basic => false,
IndexRecordOption::WithFreqs | IndexRecordOption::WithFreqsAndPositions => true,
}
}
pub fn has_positions(self) -> bool {
match self {
IndexRecordOption::Basic | IndexRecordOption::WithFreqs => false,
IndexRecordOption::WithFreqsAndPositions => true,
}
}
pub fn downgrade(&self, other: IndexRecordOption) -> IndexRecordOption {
use IndexRecordOption::*;
match (other, self) {
(WithFreqsAndPositions, WithFreqsAndPositions) => WithFreqsAndPositions,
(WithFreqs, WithFreqs) => WithFreqs,
(WithFreqsAndPositions, WithFreqs) => WithFreqs,
(WithFreqs, WithFreqsAndPositions) => WithFreqs,
_ => Basic,
}
}
}