mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Add nonfunctional "prop:rated" as possible search query
This commit is contained in:
parent
9686cd99ec
commit
ce55dc4a75
3 changed files with 52 additions and 0 deletions
|
@ -87,6 +87,7 @@ pub enum PropertyKind {
|
||||||
Lapses(u32),
|
Lapses(u32),
|
||||||
Ease(f32),
|
Ease(f32),
|
||||||
Position(u32),
|
Position(u32),
|
||||||
|
Rated(u32, Option<u8>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
|
@ -369,6 +370,7 @@ fn parse_prop(s: &str) -> ParseResult<SearchNode> {
|
||||||
tag("lapses"),
|
tag("lapses"),
|
||||||
tag("ease"),
|
tag("ease"),
|
||||||
tag("pos"),
|
tag("pos"),
|
||||||
|
tag("rated"),
|
||||||
))(s)
|
))(s)
|
||||||
.map_err(|_| parse_failure(s, FailKind::InvalidPropProperty(s.into())))?;
|
.map_err(|_| parse_failure(s, FailKind::InvalidPropProperty(s.into())))?;
|
||||||
|
|
||||||
|
@ -400,6 +402,49 @@ fn parse_prop(s: &str) -> ParseResult<SearchNode> {
|
||||||
FailKind::InvalidPropInteger(format!("{}{}", prop, operator)),
|
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::<i32>() {
|
||||||
|
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::<i32>() {
|
||||||
|
PropertyKind::Rated(days, EaseKind::ManualReschedule)
|
||||||
|
} else {
|
||||||
|
return Err(parse_failure(
|
||||||
|
s,
|
||||||
|
FailKind::InvalidPropInteger(format!("{}{}", prop, operator)),
|
||||||
|
));
|
||||||
|
}
|
||||||
} else if let Ok(u) = num.parse::<u32>() {
|
} else if let Ok(u) = num.parse::<u32>() {
|
||||||
match prop {
|
match prop {
|
||||||
"ivl" => PropertyKind::Interval(u),
|
"ivl" => PropertyKind::Interval(u),
|
||||||
|
|
|
@ -272,6 +272,9 @@ impl SqlWriter<'_> {
|
||||||
PropertyKind::Ease(ease) => {
|
PropertyKind::Ease(ease) => {
|
||||||
write!(self.sql, "factor {} {}", op, (ease * 1000.0) as u32)
|
write!(self.sql, "factor {} {}", op, (ease * 1000.0) as u32)
|
||||||
}
|
}
|
||||||
|
PropertyKind::Rated(days, ease) => {
|
||||||
|
write!(self.sql, "")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -195,6 +195,10 @@ fn write_property(operator: &str, kind: &PropertyKind) -> String {
|
||||||
Lapses(u) => format!("\"prop:lapses{}{}\"", operator, u),
|
Lapses(u) => format!("\"prop:lapses{}{}\"", operator, u),
|
||||||
Ease(f) => format!("\"prop:ease{}{}\"", operator, f),
|
Ease(f) => format!("\"prop:ease{}{}\"", operator, f),
|
||||||
Position(u) => format!("\"prop:pos{}{}\"", operator, u),
|
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),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue