diff --git a/rslib/src/backend/mod.rs b/rslib/src/backend/mod.rs index f67bb77b8..d253519ee 100644 --- a/rslib/src/backend/mod.rs +++ b/rslib/src/backend/mod.rs @@ -37,7 +37,7 @@ use crate::{ sched::timespan::{answer_button_time, time_span}, search::{ concatenate_searches, negate_search, normalize_search, replace_search_term, write_nodes, - BoolSeparator, Node, SearchNode, SortMode, StateKind, TemplateKind, + BoolSeparator, EaseKind, Node, SearchNode, SortMode, StateKind, TemplateKind, }, stats::studied_today, sync::{ @@ -292,11 +292,11 @@ impl From for Node<'_> { NamedFilter::AddedToday => Node::Search(SearchNode::AddedInDays(1)), NamedFilter::StudiedToday => Node::Search(SearchNode::Rated { days: 1, - ease: None, + ease: EaseKind::Reviewed, }), NamedFilter::AgainToday => Node::Search(SearchNode::Rated { days: 1, - ease: Some(1), + ease: EaseKind::Rated(1), }), NamedFilter::New => Node::Search(SearchNode::State(StateKind::New)), NamedFilter::Learn => Node::Search(SearchNode::State(StateKind::Learning)), diff --git a/rslib/src/search/mod.rs b/rslib/src/search/mod.rs index 5eef7e86e..ef107a94a 100644 --- a/rslib/src/search/mod.rs +++ b/rslib/src/search/mod.rs @@ -5,7 +5,7 @@ mod sqlwriter; mod writer; pub use cards::SortMode; -pub use parser::{Node, PropertyKind, SearchNode, StateKind, TemplateKind}; +pub use parser::{EaseKind, Node, PropertyKind, SearchNode, StateKind, TemplateKind}; pub use writer::{ concatenate_searches, negate_search, normalize_search, replace_search_term, write_nodes, BoolSeparator, diff --git a/rslib/src/search/parser.rs b/rslib/src/search/parser.rs index 6dd147140..c58e90b90 100644 --- a/rslib/src/search/parser.rs +++ b/rslib/src/search/parser.rs @@ -119,24 +119,12 @@ pub enum TemplateKind<'a> { } #[derive(Debug, PartialEq, Clone)] -pub(super) enum EaseKind { +pub enum EaseKind { Rated(u8), Reviewed, Manually, } -impl std::fmt::Display for EaseKind { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - use EaseKind::*; - - match self { - Rated(u) => write!(f, " and ease = {}", u), - Reviewed => write!(f, " and ease in (1, 2, 3, 4)"), - Manually => write!(f, " and ease = 0"), - } - } -} - /// Parse the input string into a list of nodes. pub(super) fn parse(input: &str) -> Result> { let input = input.trim(); @@ -383,7 +371,7 @@ fn parse_rated(val: &str) -> ParseResult> { if (1..5).contains(&u) { EaseKind::Rated(u) } else { - return Err(ParseError {}) + return Err(ParseError {}); } } None => EaseKind::Reviewed, diff --git a/rslib/src/search/sqlwriter.rs b/rslib/src/search/sqlwriter.rs index 3f447dea3..2b5facf70 100644 --- a/rslib/src/search/sqlwriter.rs +++ b/rslib/src/search/sqlwriter.rs @@ -1,7 +1,7 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use super::parser::{Node, PropertyKind, SearchNode, StateKind, TemplateKind, EaseKind}; +use super::parser::{EaseKind, Node, PropertyKind, SearchNode, StateKind, TemplateKind}; use crate::{ card::{CardQueue, CardType}, collection::Collection, @@ -219,12 +219,18 @@ impl SqlWriter<'_> { let target_cutoff_ms = (today_cutoff - 86_400 * i64::from(days)) * 1_000; write!( self.sql, - "c.id in (select cid from revlog where id>{}{})", + "c.id in (select cid from revlog where id>{}", target_cutoff_ms, - ease, ) .unwrap(); + match ease { + EaseKind::Rated(u) => write!(self.sql, " and ease = {})", u), + EaseKind::Reviewed => write!(self.sql, " and ease in (1, 2, 3, 4))"), + EaseKind::Manually => write!(self.sql, " and ease = 0)"), + } + .unwrap(); + Ok(()) } diff --git a/rslib/src/search/writer.rs b/rslib/src/search/writer.rs index 536fe39bd..f58143df0 100644 --- a/rslib/src/search/writer.rs +++ b/rslib/src/search/writer.rs @@ -5,7 +5,7 @@ use crate::{ decks::DeckID as DeckIDType, err::Result, notetype::NoteTypeID as NoteTypeIDType, - search::parser::{parse, Node, PropertyKind, SearchNode, StateKind, TemplateKind, EaseKind}, + search::parser::{parse, EaseKind, Node, PropertyKind, SearchNode, StateKind, TemplateKind}, }; use itertools::Itertools; use std::mem;