Example #1
0
    def find_cards(
        self,
        query: str,
        order: Union[bool, str, BuiltinSort.Kind.V] = False,
        reverse: bool = False,
    ) -> Sequence[int]:
        """Return card ids matching the provided search.

        To programmatically construct a search string, see .build_search_string().

        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 a BuiltinSort.Kind value, sort using that builtin sort, eg
        col.find_cards("", order=BuiltinSort.Kind.CARD_DUE)

        The reverse argument only applies when a BuiltinSort.Kind is provided;
        otherwise the collection config defines whether reverse is set or not.
        """
        if isinstance(order, str):
            mode = _pb.SortOrder(custom=order)
        elif isinstance(order, bool):
            if order is True:
                mode = _pb.SortOrder(from_config=_pb.Empty())
            else:
                mode = _pb.SortOrder(none=_pb.Empty())
        else:
            mode = _pb.SortOrder(
                builtin=_pb.SortOrder.Builtin(kind=order, reverse=reverse))
        return self._backend.search_cards(search=query, order=mode)
Example #2
0
 def find_cards(
     self,
     query: str,
     order: Union[bool, str, BuiltinSort.Kind.V] = False,
     reverse: bool = False,
 ) -> Sequence[int]:
     if isinstance(order, str):
         mode = _pb.SortOrder(custom=order)
     elif isinstance(order, bool):
         if order is True:
             mode = _pb.SortOrder(from_config=_pb.Empty())
         else:
             mode = _pb.SortOrder(none=_pb.Empty())
     else:
         mode = _pb.SortOrder(
             builtin=_pb.SortOrder.Builtin(kind=order, reverse=reverse))
     return self._backend.search_cards(search=query, order=mode)