from tools.anki.client import anki_request
async def search_cards(query: str, limit: int = 10) -> list[dict]:
"""
Search for cards in Anki using Anki's search syntax.
Args:
query: Anki search query (e.g., 'deck:Default', 'tag:python', 'front:*async*')
limit: Maximum number of results to return
Returns:
List of cards with their fields and info
Common search operators:
- deck:DeckName - cards in a specific deck
- tag:tagname - cards with a specific tag
- is:due - cards that are due for review
- is:new - new cards not yet studied
- added:1 - cards added today
- front:*text* - search front field
"""
card_ids = await anki_request("findCards", query=query)
if not card_ids:
return []
# Limit results
card_ids = card_ids[:limit]
# Get card info
cards_info = await anki_request("cardsInfo", cards=card_ids)
return [
{
"cardId": card["cardId"],
"deckName": card["deckName"],
"front": card["fields"]["Front"]["value"],
"back": card["fields"]["Back"]["value"],
"tags": card.get("tags", []),
"interval": card.get("interval", 0),
"due": card.get("due", 0),
}
for card in cards_info
]