Merge pull request #881 from abdnh/prop-order

Support prop:order to search for new cards by order
This commit is contained in:
Damien Elmes 2021-01-02 21:27:29 +10:00 committed by GitHub
commit 105d8e59f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View file

@ -97,6 +97,7 @@ pub(super) enum PropertyKind {
Reps(u32), Reps(u32),
Lapses(u32), Lapses(u32),
Ease(f32), Ease(f32),
Position(u32),
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
@ -373,6 +374,7 @@ fn parse_prop(val: &str) -> ParseResult<SearchNode<'static>> {
tag("reps"), tag("reps"),
tag("lapses"), tag("lapses"),
tag("ease"), tag("ease"),
tag("pos"),
))(val)?; ))(val)?;
let (val, operator) = alt(( let (val, operator) = alt((
@ -396,6 +398,7 @@ fn parse_prop(val: &str) -> ParseResult<SearchNode<'static>> {
"ivl" => PropertyKind::Interval(num), "ivl" => PropertyKind::Interval(num),
"reps" => PropertyKind::Reps(num), "reps" => PropertyKind::Reps(num),
"lapses" => PropertyKind::Lapses(num), "lapses" => PropertyKind::Lapses(num),
"pos" => PropertyKind::Position(num),
_ => unreachable!(), _ => unreachable!(),
} }
}; };

View file

@ -247,6 +247,15 @@ impl SqlWriter<'_> {
day = day day = day
) )
} }
PropertyKind::Position(pos) => {
write!(
self.sql,
"(c.type = {t} and due {op} {pos})",
t = CardType::New as u8,
op = op,
pos = pos
)
}
PropertyKind::Interval(ivl) => write!(self.sql, "ivl {} {}", op, ivl), PropertyKind::Interval(ivl) => write!(self.sql, "ivl {} {}", op, ivl),
PropertyKind::Reps(reps) => write!(self.sql, "reps {} {}", op, reps), PropertyKind::Reps(reps) => write!(self.sql, "reps {} {}", op, reps),
PropertyKind::Lapses(days) => write!(self.sql, "lapses {} {}", op, days), PropertyKind::Lapses(days) => write!(self.sql, "lapses {} {}", op, days),