diff --git a/pylib/anki/find.py b/pylib/anki/find.py index 33c3ca838..c7bf14cdb 100644 --- a/pylib/anki/find.py +++ b/pylib/anki/find.py @@ -3,7 +3,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional, Set +from typing import TYPE_CHECKING, Optional, Set, Tuple from anki.hooks import * from anki.utils import ids2str, splitFields, stripHTMLMedia @@ -71,9 +71,7 @@ def findDupes( col: Collection, fieldName: str, search: str = "" ) -> List[Tuple[Any, List]]: # limit search to notes with applicable field name - if search: - search = "(" + search + ") " - search += '"%s:*"' % fieldName.replace('"', '"') + search = col.search_string(searches=[search], field_name=fieldName) # go through notes vals: Dict[str, List[int]] = {} dupes = [] diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 603c47d31..01b9dcbcf 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -1688,7 +1688,12 @@ where id in %s""" def duplicatesReport(self, web, fname, search, frm, web_context): self.mw.progress.start() - res = self.mw.col.findDupes(fname, search) + try: + res = self.mw.col.findDupes(fname, search) + except InvalidInput as e: + self.mw.progress.finish() + show_invalid_search_error(e) + return if not self._dupesButton: self._dupesButton = b = frm.buttonBox.addButton( tr(TR.BROWSING_TAG_DUPLICATES), QDialogButtonBox.ActionRole