mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Add docstrings to find_cards() and find_notes()
This commit is contained in:
parent
4130e9fc68
commit
010ebef12e
1 changed files with 25 additions and 12 deletions
|
@ -441,24 +441,27 @@ class Collection:
|
||||||
# Finding cards
|
# Finding cards
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
# if order=True, use the sort order stored in the collection config
|
|
||||||
# if order=False, do no ordering
|
|
||||||
#
|
|
||||||
# if order is a string, that text is added after 'order by' in the sql statement.
|
|
||||||
# you must add ' asc' or ' desc' to the order, as Anki will replace asc with
|
|
||||||
# desc and vice versa when reverse is set in the collection config, eg
|
|
||||||
# order="c.ivl asc, c.due desc"
|
|
||||||
#
|
|
||||||
# if order is an int enum, sort using that builtin sort, eg
|
|
||||||
# col.find_cards("", order=BuiltinSortKind.CARD_DUE)
|
|
||||||
# the reverse argument only applies when a BuiltinSortKind is provided;
|
|
||||||
# otherwise the collection config defines whether reverse is set or not
|
|
||||||
def find_cards(
|
def find_cards(
|
||||||
self,
|
self,
|
||||||
query: str,
|
query: str,
|
||||||
order: Union[bool, str, BuiltinSort.Kind.V] = False,
|
order: Union[bool, str, BuiltinSort.Kind.V] = False,
|
||||||
reverse: bool = False,
|
reverse: bool = False,
|
||||||
) -> Sequence[int]:
|
) -> Sequence[int]:
|
||||||
|
"""Return card ids matching the provided search.
|
||||||
|
|
||||||
|
if order=True, use the sort order stored in the collection config
|
||||||
|
if order=False, do no ordering
|
||||||
|
|
||||||
|
if order is a string, that text is added after 'order by' in the sql statement.
|
||||||
|
you must add ' asc' or ' desc' to the order, as Anki will replace asc with
|
||||||
|
desc and vice versa when reverse is set in the collection config, eg
|
||||||
|
order="c.ivl asc, c.due desc"
|
||||||
|
|
||||||
|
if order is an int enum, sort using that builtin sort, eg
|
||||||
|
col.find_cards("", order=BuiltinSortKind.CARD_DUE)
|
||||||
|
the reverse argument only applies when a BuiltinSortKind is provided;
|
||||||
|
otherwise the collection config defines whether reverse is set or not
|
||||||
|
"""
|
||||||
if isinstance(order, str):
|
if isinstance(order, str):
|
||||||
mode = _pb.SortOrder(custom=order)
|
mode = _pb.SortOrder(custom=order)
|
||||||
elif isinstance(order, bool):
|
elif isinstance(order, bool):
|
||||||
|
@ -473,6 +476,16 @@ class Collection:
|
||||||
return self._backend.search_cards(search=query, order=mode)
|
return self._backend.search_cards(search=query, order=mode)
|
||||||
|
|
||||||
def find_notes(self, *terms: Union[str, SearchNode]) -> Sequence[int]:
|
def find_notes(self, *terms: Union[str, SearchNode]) -> Sequence[int]:
|
||||||
|
"""Return note ids matching the provided search or searches.
|
||||||
|
|
||||||
|
If more than one search is provided, they will be ANDed together.
|
||||||
|
|
||||||
|
Eg: col.find_notes("test", "another") will search for "test AND another"
|
||||||
|
and return matching note ids.
|
||||||
|
|
||||||
|
Eg: col.find_notes(SearchNode(deck="test"), "foo") will return notes
|
||||||
|
that have a card in deck called "test", and have the text "foo".
|
||||||
|
"""
|
||||||
return self._backend.search_notes(self.build_search_string(*terms))
|
return self._backend.search_notes(self.build_search_string(*terms))
|
||||||
|
|
||||||
def find_and_replace(
|
def find_and_replace(
|
||||||
|
|
Loading…
Reference in a new issue