From 95b4e4cc84e42ba915c492c3d873d9ce4bc5fa78 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Tue, 29 Dec 2020 11:18:49 +0100 Subject: [PATCH] Make function names more explicit and add docs --- qt/aqt/browser.py | 6 +++--- rslib/backend.proto | 2 +- rslib/src/backend/mod.rs | 6 +++--- rslib/src/search/mod.rs | 2 +- rslib/src/search/writer.rs | 8 +++++--- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index e3ff7d7f2..003388a88 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -188,7 +188,7 @@ class DataModel(QAbstractTableModel): ctx = SearchContext(search=txt, browser=self.browser) gui_hooks.browser_will_search(ctx) 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) gui_hooks.browser_did_search(ctx) self.cards = ctx.card_ids @@ -819,8 +819,8 @@ class Browser(QMainWindow): # no row change will fire self._onRowChanged(None, None) - def norm_search(self, search: str) -> str: - normed = self.col.backend.norm_search(search) + def normalize_search(self, search: str) -> str: + normed = self.col.backend.normalize_search(search) self._lastSearchTxt = normed self.form.searchEdit.lineEdit().setText(normed) return normed diff --git a/rslib/backend.proto b/rslib/backend.proto index 821336385..396ec4485 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -84,7 +84,7 @@ service BackendService { // searching - rpc NormSearch (String) returns (String); + rpc NormalizeSearch (String) returns (String); rpc SearchCards (SearchCardsIn) returns (SearchCardsOut); rpc SearchNotes (SearchNotesIn) returns (SearchNotesOut); rpc FindAndReplace (FindAndReplaceIn) returns (UInt32); diff --git a/rslib/src/backend/mod.rs b/rslib/src/backend/mod.rs index 2cd25a486..0efee24f1 100644 --- a/rslib/src/backend/mod.rs +++ b/rslib/src/backend/mod.rs @@ -32,7 +32,7 @@ use crate::{ }, sched::cutoff::local_minutes_west_for_stamp, sched::timespan::{answer_button_time, time_span}, - search::{norm_search, SortMode}, + search::{normalize_search, SortMode}, stats::studied_today, sync::{ get_remote_sync_meta, sync_abort, sync_login, FullSyncProgress, NormalSyncProgress, @@ -393,8 +393,8 @@ impl BackendService for Backend { // searching //----------------------------------------------- - fn norm_search(&self, input: pb::String) -> Result { - Ok(norm_search(&input.val)?.into()) + fn normalize_search(&self, input: pb::String) -> Result { + Ok(normalize_search(&input.val)?.into()) } fn search_cards(&self, input: pb::SearchCardsIn) -> Result { diff --git a/rslib/src/search/mod.rs b/rslib/src/search/mod.rs index 4d1ff02e2..d409c05eb 100644 --- a/rslib/src/search/mod.rs +++ b/rslib/src/search/mod.rs @@ -5,4 +5,4 @@ mod sqlwriter; mod writer; pub use cards::SortMode; -pub use writer::norm_search; +pub use writer::normalize_search; diff --git a/rslib/src/search/writer.rs b/rslib/src/search/writer.rs index dab60aee0..8944a00a5 100644 --- a/rslib/src/search/writer.rs +++ b/rslib/src/search/writer.rs @@ -8,7 +8,9 @@ use crate::{ search::parser::{parse, Node, PropertyKind, SearchNode, StateKind, TemplateKind}, }; -pub fn norm_search(input: &str) -> Result { +/// Take an Anki-style search string and convert it into an equivalent +/// search string with normalized syntax. +pub fn normalize_search(input: &str) -> Result { Ok(write_nodes(&parse(input)?)) } @@ -48,7 +50,7 @@ fn write_search_node(node: &SearchNode) -> String { Flag(u) => format!("\"flag:{}\"", u), NoteIDs(s) => format!("\"nid:{}\"", s), CardIDs(s) => format!("\"cid:{}\"", s), - Property { operator, kind } => write_prop(operator, kind), + Property { operator, kind } => write_property(operator, kind), WholeCollection => "".to_string(), Regex(s) => quote(&format!("re:{}", 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::*; match kind { Due(i) => format!("\"prop:due{}{}\"", operator, i),