use serde_json::Value;
#[derive(Debug, Clone, Copy)]
pub enum Operator {
And,
Or,
}
impl Operator {
pub(crate) fn as_str(self) -> &'static str {
match self {
Operator::And => "AND",
Operator::Or => "OR",
}
}
}
#[derive(Debug, Clone, Copy)]
pub enum ScoreMode {
Multiply,
Sum,
Avg,
First,
Max,
Min,
}
impl ScoreMode {
pub(crate) fn as_str(self) -> &'static str {
match self {
ScoreMode::Multiply => "multiply",
ScoreMode::Sum => "sum",
ScoreMode::Avg => "avg",
ScoreMode::First => "first",
ScoreMode::Max => "max",
ScoreMode::Min => "min",
}
}
}
#[derive(Debug, Clone, Copy)]
pub enum NestedScoreMode {
Avg,
Sum,
Min,
Max,
None,
}
impl NestedScoreMode {
pub(crate) fn as_str(self) -> &'static str {
match self {
NestedScoreMode::Avg => "avg",
NestedScoreMode::Sum => "sum",
NestedScoreMode::Min => "min",
NestedScoreMode::Max => "max",
NestedScoreMode::None => "none",
}
}
}
#[derive(Debug, Clone, Copy)]
pub enum BoostMode {
Multiply,
Replace,
Sum,
Avg,
Max,
Min,
}
impl BoostMode {
pub(crate) fn as_str(self) -> &'static str {
match self {
BoostMode::Multiply => "multiply",
BoostMode::Replace => "replace",
BoostMode::Sum => "sum",
BoostMode::Avg => "avg",
BoostMode::Max => "max",
BoostMode::Min => "min",
}
}
}
#[derive(Debug, Clone, Copy)]
pub enum ZeroTermsQuery {
None,
All,
}
impl ZeroTermsQuery {
pub(crate) fn as_str(self) -> &'static str {
match self {
ZeroTermsQuery::None => "none",
ZeroTermsQuery::All => "all",
}
}
}
#[derive(Debug, Clone, Copy)]
pub enum RangeRelation {
Intersects,
Contains,
Within,
}
impl RangeRelation {
pub(crate) fn as_str(self) -> &'static str {
match self {
RangeRelation::Intersects => "INTERSECTS",
RangeRelation::Contains => "CONTAINS",
RangeRelation::Within => "WITHIN",
}
}
}
#[derive(Debug, Clone, Copy)]
pub enum MultiMatchType {
BestFields,
MostFields,
CrossFields,
Phrase,
PhrasePrefix,
BoolPrefix,
}
impl MultiMatchType {
pub(crate) fn as_str(self) -> &'static str {
match self {
MultiMatchType::BestFields => "best_fields",
MultiMatchType::MostFields => "most_fields",
MultiMatchType::CrossFields => "cross_fields",
MultiMatchType::Phrase => "phrase",
MultiMatchType::PhrasePrefix => "phrase_prefix",
MultiMatchType::BoolPrefix => "bool_prefix",
}
}
}
#[derive(Debug, Clone)]
pub enum MinimumShouldMatch {
Count(i32),
Percent(i32),
Raw(String),
}
impl MinimumShouldMatch {
pub fn count(n: i32) -> Self {
Self::Count(n)
}
pub fn percent(p: i32) -> Self {
Self::Percent(p)
}
pub fn raw(expr: impl Into<String>) -> Self {
Self::Raw(expr.into())
}
pub(crate) fn to_value(&self) -> Value {
match self {
MinimumShouldMatch::Count(n) => Value::from(*n),
MinimumShouldMatch::Percent(p) => Value::String(format!("{p}%")),
MinimumShouldMatch::Raw(expr) => Value::String(expr.clone()),
}
}
}
impl From<i32> for MinimumShouldMatch {
fn from(n: i32) -> Self {
MinimumShouldMatch::Count(n)
}
}
#[derive(Debug, Clone, Copy)]
pub enum DistanceType {
Arc,
Plane,
}
impl DistanceType {
pub(crate) fn as_str(self) -> &'static str {
match self {
DistanceType::Arc => "arc",
DistanceType::Plane => "plane",
}
}
}
#[derive(Debug, Clone, Copy)]
pub enum ValidationMethod {
Strict,
Coerce,
IgnoreMalformed,
}
impl ValidationMethod {
pub(crate) fn as_str(self) -> &'static str {
match self {
ValidationMethod::Strict => "STRICT",
ValidationMethod::Coerce => "COERCE",
ValidationMethod::IgnoreMalformed => "IGNORE_MALFORMED",
}
}
}
#[derive(Debug, Clone, Copy)]
pub enum NumericType {
Double,
Long,
Date,
DateNanos,
}
impl NumericType {
pub(crate) fn as_str(self) -> &'static str {
match self {
NumericType::Double => "double",
NumericType::Long => "long",
NumericType::Date => "date",
NumericType::DateNanos => "date_nanos",
}
}
}
#[derive(Debug, Clone, Copy)]
pub enum ScriptSortType {
Number,
String,
}
impl ScriptSortType {
pub(crate) fn as_str(self) -> &'static str {
match self {
ScriptSortType::Number => "number",
ScriptSortType::String => "string",
}
}
}
#[derive(Debug, Clone, Copy)]
pub enum Fuzziness {
Auto,
AutoBounds(u32, u32),
Edits(u32),
}
impl Fuzziness {
pub(crate) fn to_value(self) -> Value {
match self {
Fuzziness::Auto => Value::String("AUTO".to_string()),
Fuzziness::AutoBounds(lo, hi) => Value::String(format!("AUTO:{lo}:{hi}")),
Fuzziness::Edits(edits) => Value::from(edits),
}
}
}