find comparisons needs to be normalized

this data should probably be normalized when it's originally
added to the collection

https://anki.tenderapp.com/discussions/ankidesktop/31409-cant-search-by-deck-when-searching-decks-containing-arabic-text
This commit is contained in:
Damien Elmes 2018-12-13 20:36:04 +10:00
parent 54d5a321b6
commit 30f19c07be
2 changed files with 8 additions and 5 deletions

View file

@ -3,6 +3,8 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import copy, operator import copy, operator
import unicodedata
from anki.utils import intTime, ids2str, json from anki.utils import intTime, ids2str, json
from anki.hooks import runHook from anki.hooks import runHook
from anki.consts import * from anki.consts import *
@ -130,7 +132,7 @@ class DeckManager:
"Add a deck with NAME. Reuse deck if already exists. Return id as int." "Add a deck with NAME. Reuse deck if already exists. Return id as int."
name = name.replace('"', '') name = name.replace('"', '')
for id, g in list(self.decks.items()): for id, g in list(self.decks.items()):
if g['name'].lower() == name.lower(): if unicodedata.normalize("NFC", g['name'].lower()) == name.lower():
return int(id) return int(id)
if not create: if not create:
return None return None

View file

@ -4,6 +4,7 @@
import re import re
import sre_constants import sre_constants
import unicodedata
from anki.utils import ids2str, splitFields, joinFields, intTime, fieldChecksum, stripHTMLMedia from anki.utils import ids2str, splitFields, joinFields, intTime, fieldChecksum, stripHTMLMedia
from anki.consts import * from anki.consts import *
@ -368,7 +369,7 @@ select distinct(n.id) from cards c, notes n where c.nid=n.id and """+preds
ids = [] ids = []
val = val.lower() val = val.lower()
for m in self.col.models.all(): for m in self.col.models.all():
if m['name'].lower() == val: if unicodedata.normalize("NFC", m['name'].lower()) == val:
ids.append(m['id']) ids.append(m['id'])
return "n.mid in %s" % ids2str(ids) return "n.mid in %s" % ids2str(ids)
@ -396,7 +397,7 @@ select distinct(n.id) from cards c, notes n where c.nid=n.id and """+preds
ids = set() ids = set()
val = re.escape(val).replace(r"\*", ".*") val = re.escape(val).replace(r"\*", ".*")
for d in self.col.decks.all(): for d in self.col.decks.all():
if re.match("(?i)"+val, d['name']): if re.match("(?i)"+val, unicodedata.normalize("NFC", d['name'])):
ids.update(dids(d['id'])) ids.update(dids(d['id']))
if not ids: if not ids:
return return
@ -416,7 +417,7 @@ select distinct(n.id) from cards c, notes n where c.nid=n.id and """+preds
lims = [] lims = []
for m in self.col.models.all(): for m in self.col.models.all():
for t in m['tmpls']: for t in m['tmpls']:
if t['name'].lower() == val.lower(): if unicodedata.normalize("NFC", t['name'].lower()) == val.lower():
if m['type'] == MODEL_CLOZE: if m['type'] == MODEL_CLOZE:
# if the user has asked for a cloze card, we want # if the user has asked for a cloze card, we want
# to give all ordinals, so we just limit to the # to give all ordinals, so we just limit to the
@ -434,7 +435,7 @@ select distinct(n.id) from cards c, notes n where c.nid=n.id and """+preds
mods = {} mods = {}
for m in self.col.models.all(): for m in self.col.models.all():
for f in m['flds']: for f in m['flds']:
if f['name'].lower() == field: if unicodedata.normalize("NFC", f['name'].lower()) == field:
mods[str(m['id'])] = (m, f['ord']) mods[str(m['id'])] = (m, f['ord'])
if not mods: if not mods:
# nothing has that field # nothing has that field