@@ -470,24 +470,39 @@ def get_card_morph_map_cache(self) -> dict[int, list[Morpheme]]:
470470 return card_morph_map_cache
471471
472472 def get_am_cards_data_dict (
473- self , note_type_id : NotetypeId | None
473+ self ,
474+ note_type_id : NotetypeId | None ,
475+ include_tags : str , # whitespace separated string
476+ exclude_tags : str , # whitespace separated string
474477 ) -> dict [CardId , AnkiMorphsCardData ]:
475478 assert mw is not None
476479 assert mw .col .db is not None
477480 assert note_type_id is not None
478481
479- result = self .con .execute (
480- """
482+ query = """
481483 SELECT card_id, note_id, note_type_id, card_type, tags
482484 FROM Cards
483485 WHERE note_type_id = ?
484- """ ,
485- (note_type_id ,),
486- ).fetchall ()
486+ """
487+
488+ params : list [Any ] = [note_type_id ]
489+
490+ if len (include_tags ) > 0 :
491+ required_conditions = " AND " .join (["tags LIKE ?" ] * len (include_tags ))
492+ query += f" AND { required_conditions } "
493+ params .extend ([f"% { tag } %" for tag in include_tags ])
494+
495+ if len (exclude_tags ) > 0 :
496+ excluded_conditions = " AND " .join (["tags NOT LIKE ?" ] * len (exclude_tags ))
497+ query += f" AND { excluded_conditions } "
498+ params .extend ([f"% { tag } %" for tag in exclude_tags ])
499+
500+ result = self .con .execute (query , tuple (params )).fetchall ()
487501
488502 am_db_row_data_dict : dict [CardId , AnkiMorphsCardData ] = {}
489503 for am_data in map (AnkiMorphsCardData , result ):
490504 am_db_row_data_dict [am_data .card_id ] = am_data
505+
491506 return am_db_row_data_dict
492507
493508 # the cache needs to have a max size to maintain garbage collection
0 commit comments