mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
wildcard deck searches
This commit is contained in:
parent
bc220e6f35
commit
28b5a108f6
2 changed files with 27 additions and 2 deletions
19
anki/find.py
19
anki/find.py
|
@ -192,6 +192,7 @@ and c.nid=n.id %s""" % (q, order)
|
|||
self.lims['preds'].append("mid %s in %s" % (extra, ids2str(ids)))
|
||||
|
||||
def _findDeck(self, val, isNeg):
|
||||
ids = []
|
||||
if val.lower() == "current":
|
||||
id = self.col.decks.current()['id']
|
||||
elif val.lower() == "none":
|
||||
|
@ -202,9 +203,23 @@ and c.nid=n.id %s""" % (q, order)
|
|||
self.lims['preds'].append(
|
||||
"c.did %s in %s" % (extra, ids2str(self.col.decks.allIds())))
|
||||
return
|
||||
else:
|
||||
elif "*" not in val:
|
||||
# single deck
|
||||
id = self.col.decks.id(val, create=False) or 0
|
||||
ids = [id] + [a[1] for a in self.col.decks.children(id)]
|
||||
else:
|
||||
# wildcard
|
||||
val = val.replace("*", ".*")
|
||||
for d in self.col.decks.all():
|
||||
if re.match("(?i)"+val, d['name']):
|
||||
id = d['id']
|
||||
ids.extend([id] + [
|
||||
a[1] for a in self.col.decks.children(id)])
|
||||
if not ids:
|
||||
# invalid search
|
||||
self.lims['valid'] = False
|
||||
return
|
||||
if not ids:
|
||||
ids = [id] + [a[1] for a in self.col.decks.children(id)]
|
||||
sids = ids2str(ids)
|
||||
if not isNeg:
|
||||
# normal search
|
||||
|
|
|
@ -108,6 +108,9 @@ def test_findCards():
|
|||
assert len(deck.findCards("deck:default")) == 5
|
||||
assert len(deck.findCards("-deck:default")) == 0
|
||||
assert len(deck.findCards("-deck:foo")) == 5
|
||||
assert len(deck.findCards("deck:def*")) == 5
|
||||
assert len(deck.findCards("deck:*EFAULT")) == 5
|
||||
assert len(deck.findCards("deck:*cefault")) == 0
|
||||
# full search
|
||||
f = deck.newNote()
|
||||
f['Front'] = u'hello<b>world</b>'
|
||||
|
@ -125,6 +128,13 @@ def test_findCards():
|
|||
assert len(deck.findCards("back:helloworld", full=True)) == 2
|
||||
# searching for an invalid special tag should not error
|
||||
assert len(deck.findCards("is:invalid")) == 0
|
||||
# should be able to limit to parent deck, no children
|
||||
id = deck.db.scalar("select id from cards limit 1")
|
||||
deck.db.execute("update cards set did = ? where id = ?",
|
||||
deck.decks.id("Default::Child"), id)
|
||||
assert len(deck.findCards("deck:default")) == 7
|
||||
assert len(deck.findCards("deck:default::child")) == 1
|
||||
assert len(deck.findCards("deck:default -deck:default::*")) == 6
|
||||
|
||||
def test_findReplace():
|
||||
deck = getEmptyDeck()
|
||||
|
|
Loading…
Reference in a new issue