Make function names more explicit and add docs
This commit is contained in:
parent
62753290d8
commit
95b4e4cc84
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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<pb::String> {
|
||||
Ok(norm_search(&input.val)?.into())
|
||||
fn normalize_search(&self, input: pb::String) -> Result<pb::String> {
|
||||
Ok(normalize_search(&input.val)?.into())
|
||||
}
|
||||
|
||||
fn search_cards(&self, input: pb::SearchCardsIn) -> Result<pb::SearchCardsOut> {
|
||||
|
@ -5,4 +5,4 @@ mod sqlwriter;
|
||||
mod writer;
|
||||
|
||||
pub use cards::SortMode;
|
||||
pub use writer::norm_search;
|
||||
pub use writer::normalize_search;
|
||||
|
@ -8,7 +8,9 @@ use crate::{
|
||||
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)?))
|
||||
}
|
||||
|
||||
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user