diff --git a/rslib/src/search/parser.rs b/rslib/src/search/parser.rs index ff7f1ab84..d5ed46266 100644 --- a/rslib/src/search/parser.rs +++ b/rslib/src/search/parser.rs @@ -87,6 +87,7 @@ pub enum PropertyKind { Lapses(u32), Ease(f32), Position(u32), + Rated(u32, Option), } #[derive(Debug, PartialEq, Clone)] @@ -369,6 +370,7 @@ fn parse_prop(s: &str) -> ParseResult { tag("lapses"), tag("ease"), tag("pos"), + tag("rated"), ))(s) .map_err(|_| parse_failure(s, FailKind::InvalidPropProperty(s.into())))?; @@ -400,6 +402,49 @@ fn parse_prop(s: &str) -> ParseResult { FailKind::InvalidPropInteger(format!("{}{}", prop, operator)), )); } + } else if key == "rated" { + let mut it = num.splitn(2, ':'); + + let days: i32 = if let Ok(i) = it.next().unwrap().parse::() { + i + } else { + return Err(parse_failure( + s, + FailKind::InvalidPropInteger(format!("{}{}", prop, operator)), + )); + } + + let ease = match it.next() { + Some(v) => { + let n: u8 = if let Ok(i) = v.parse() { + if (1..5).contains(i) { + EaseKind::AnswerButton(i) + } else { + return Err(parse_failure( + s, + FailKind::InvalidPropInteger(format!("{}{}", prop, operator)), + )); + } + } else { + return Err(parse_failure( + s, + FailKind::InvalidPropInteger(format!("{}{}", prop, operator)), + )); + } + } + None => EaseKind::AnyAnswerButton, + } + + PropertyKind::Rated(days, ease) + } else if key == "resched" { + if let Ok(days) = num.parse::() { + PropertyKind::Rated(days, EaseKind::ManualReschedule) + } else { + return Err(parse_failure( + s, + FailKind::InvalidPropInteger(format!("{}{}", prop, operator)), + )); + } } else if let Ok(u) = num.parse::() { match prop { "ivl" => PropertyKind::Interval(u), diff --git a/rslib/src/search/sqlwriter.rs b/rslib/src/search/sqlwriter.rs index 4e2faf076..dc61f9b79 100644 --- a/rslib/src/search/sqlwriter.rs +++ b/rslib/src/search/sqlwriter.rs @@ -272,6 +272,9 @@ impl SqlWriter<'_> { PropertyKind::Ease(ease) => { write!(self.sql, "factor {} {}", op, (ease * 1000.0) as u32) } + PropertyKind::Rated(days, ease) => { + write!(self.sql, "") + } } .unwrap(); Ok(()) diff --git a/rslib/src/search/writer.rs b/rslib/src/search/writer.rs index 94215697e..bc7ba5584 100644 --- a/rslib/src/search/writer.rs +++ b/rslib/src/search/writer.rs @@ -195,6 +195,10 @@ fn write_property(operator: &str, kind: &PropertyKind) -> String { Lapses(u) => format!("\"prop:lapses{}{}\"", operator, u), Ease(f) => format!("\"prop:ease{}{}\"", operator, f), Position(u) => format!("\"prop:pos{}{}\"", operator, u), + Rated(u, ease) => match ease { + Some(val) => format!("\"prop:rated{}{}:{}\"", operator, u, val), + None => format!("\"prop:rated{}{}\"", operator, u), + } } }