Make function names more explicit and add docs

This commit is contained in:
RumovZ 2020-12-29 11:18:49 +01:00
parent 62753290d8
commit 95b4e4cc84
5 changed files with 13 additions and 11 deletions

View File

@ -188,7 +188,7 @@ class DataModel(QAbstractTableModel):
ctx = SearchContext(search=txt, browser=self.browser) ctx = SearchContext(search=txt, browser=self.browser)
gui_hooks.browser_will_search(ctx) gui_hooks.browser_will_search(ctx)
if ctx.card_ids is None: if ctx.card_ids is None:
ctx.search = self.browser.norm_search(ctx.search) ctx.search = self.browser.normalize_search(ctx.search)
ctx.card_ids = self.col.find_cards(ctx.search, order=ctx.order) ctx.card_ids = self.col.find_cards(ctx.search, order=ctx.order)
gui_hooks.browser_did_search(ctx) gui_hooks.browser_did_search(ctx)
self.cards = ctx.card_ids self.cards = ctx.card_ids
@ -819,8 +819,8 @@ class Browser(QMainWindow):
# no row change will fire # no row change will fire
self._onRowChanged(None, None) self._onRowChanged(None, None)
def norm_search(self, search: str) -> str: def normalize_search(self, search: str) -> str:
normed = self.col.backend.norm_search(search) normed = self.col.backend.normalize_search(search)
self._lastSearchTxt = normed self._lastSearchTxt = normed
self.form.searchEdit.lineEdit().setText(normed) self.form.searchEdit.lineEdit().setText(normed)
return normed return normed

View File

@ -84,7 +84,7 @@ service BackendService {
// searching // searching
rpc NormSearch (String) returns (String); rpc NormalizeSearch (String) returns (String);
rpc SearchCards (SearchCardsIn) returns (SearchCardsOut); rpc SearchCards (SearchCardsIn) returns (SearchCardsOut);
rpc SearchNotes (SearchNotesIn) returns (SearchNotesOut); rpc SearchNotes (SearchNotesIn) returns (SearchNotesOut);
rpc FindAndReplace (FindAndReplaceIn) returns (UInt32); rpc FindAndReplace (FindAndReplaceIn) returns (UInt32);

View File

@ -32,7 +32,7 @@ use crate::{
}, },
sched::cutoff::local_minutes_west_for_stamp, sched::cutoff::local_minutes_west_for_stamp,
sched::timespan::{answer_button_time, time_span}, sched::timespan::{answer_button_time, time_span},
search::{norm_search, SortMode}, search::{normalize_search, SortMode},
stats::studied_today, stats::studied_today,
sync::{ sync::{
get_remote_sync_meta, sync_abort, sync_login, FullSyncProgress, NormalSyncProgress, get_remote_sync_meta, sync_abort, sync_login, FullSyncProgress, NormalSyncProgress,
@ -393,8 +393,8 @@ impl BackendService for Backend {
// searching // searching
//----------------------------------------------- //-----------------------------------------------
fn norm_search(&self, input: pb::String) -> Result<pb::String> { fn normalize_search(&self, input: pb::String) -> Result<pb::String> {
Ok(norm_search(&input.val)?.into()) Ok(normalize_search(&input.val)?.into())
} }
fn search_cards(&self, input: pb::SearchCardsIn) -> Result<pb::SearchCardsOut> { fn search_cards(&self, input: pb::SearchCardsIn) -> Result<pb::SearchCardsOut> {

View File

@ -5,4 +5,4 @@ mod sqlwriter;
mod writer; mod writer;
pub use cards::SortMode; pub use cards::SortMode;
pub use writer::norm_search; pub use writer::normalize_search;

View File

@ -8,7 +8,9 @@ use crate::{
search::parser::{parse, Node, PropertyKind, SearchNode, StateKind, TemplateKind}, search::parser::{parse, Node, PropertyKind, SearchNode, StateKind, TemplateKind},
}; };
pub fn norm_search(input: &str) -> Result<String> { /// Take an Anki-style search string and convert it into an equivalent
/// search string with normalized syntax.
pub fn normalize_search(input: &str) -> Result<String> {
Ok(write_nodes(&parse(input)?)) Ok(write_nodes(&parse(input)?))
} }
@ -48,7 +50,7 @@ fn write_search_node(node: &SearchNode) -> String {
Flag(u) => format!("\"flag:{}\"", u), Flag(u) => format!("\"flag:{}\"", u),
NoteIDs(s) => format!("\"nid:{}\"", s), NoteIDs(s) => format!("\"nid:{}\"", s),
CardIDs(s) => format!("\"cid:{}\"", s), CardIDs(s) => format!("\"cid:{}\"", s),
Property { operator, kind } => write_prop(operator, kind), Property { operator, kind } => write_property(operator, kind),
WholeCollection => "".to_string(), WholeCollection => "".to_string(),
Regex(s) => quote(&format!("re:{}", s)), Regex(s) => quote(&format!("re:{}", s)),
NoCombining(s) => quote(&format!("nc:{}", s)), NoCombining(s) => quote(&format!("nc:{}", s)),
@ -97,7 +99,7 @@ fn write_state(kind: &StateKind) -> String {
) )
} }
fn write_prop(operator: &str, kind: &PropertyKind) -> String { fn write_property(operator: &str, kind: &PropertyKind) -> String {
use PropertyKind::*; use PropertyKind::*;
match kind { match kind {
Due(i) => format!("\"prop:due{}{}\"", operator, i), Due(i) => format!("\"prop:due{}{}\"", operator, i),