mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 17:26:36 -04:00
users can pass a number for template ordinal; makes show:one obsolete
This commit is contained in:
parent
94d4e319ae
commit
57938927e7
2 changed files with 14 additions and 25 deletions
36
anki/find.py
36
anki/find.py
|
@ -10,8 +10,7 @@ SEARCH_TYPE = 1
|
||||||
SEARCH_PHRASE = 2
|
SEARCH_PHRASE = 2
|
||||||
SEARCH_FID = 3
|
SEARCH_FID = 3
|
||||||
SEARCH_TEMPLATE = 4
|
SEARCH_TEMPLATE = 4
|
||||||
SEARCH_DISTINCT = 5
|
SEARCH_FIELD = 5
|
||||||
SEARCH_FIELD = 6
|
|
||||||
SEARCH_FIELD_EXISTS = 7
|
SEARCH_FIELD_EXISTS = 7
|
||||||
|
|
||||||
# Find
|
# Find
|
||||||
|
@ -29,26 +28,12 @@ class Finder(object):
|
||||||
query = "select id from cards"
|
query = "select id from cards"
|
||||||
if q:
|
if q:
|
||||||
query += " where " + q
|
query += " where " + q
|
||||||
# if cmquery['pos'] or cmquery['neg']:
|
|
||||||
# if hasWhere is False:
|
|
||||||
# query += " where "
|
|
||||||
# hasWhere = True
|
|
||||||
# else: query += " and "
|
|
||||||
# if cmquery['pos']:
|
|
||||||
# query += (" fid in(select distinct fid from cards "+
|
|
||||||
# "where id in (" + cmquery['pos'] + ")) ")
|
|
||||||
# query += " and id in(" + cmquery['pos'] + ") "
|
|
||||||
# if cmquery['neg']:
|
|
||||||
# query += (" fid not in(select distinct fid from "+
|
|
||||||
# "cards where id in (" + cmquery['neg'] + ")) ")
|
|
||||||
# if fidList is not None:
|
# if fidList is not None:
|
||||||
# if hasWhere is False:
|
# if hasWhere is False:
|
||||||
# query += " where "
|
# query += " where "
|
||||||
# hasWhere = True
|
# hasWhere = True
|
||||||
# else: query += " and "
|
# else: query += " and "
|
||||||
# query += " fid IN %s" % ids2str(fidList)
|
# query += " fid IN %s" % ids2str(fidList)
|
||||||
# if showdistinct:
|
|
||||||
# query += " group by fid"
|
|
||||||
print query, args
|
print query, args
|
||||||
return self.deck.db.list(query, **args)
|
return self.deck.db.list(query, **args)
|
||||||
|
|
||||||
|
@ -100,11 +85,6 @@ class Finder(object):
|
||||||
sfquery += """
|
sfquery += """
|
||||||
select fid from fdata where fmid in %s and
|
select fid from fdata where fmid in %s and
|
||||||
value like :_ff_%d escape '\\'""" % (ids2str(ids), c)
|
value like :_ff_%d escape '\\'""" % (ids2str(ids), c)
|
||||||
elif type == SEARCH_DISTINCT:
|
|
||||||
if isNeg is False:
|
|
||||||
showdistinct = True if token == "one" else False
|
|
||||||
else:
|
|
||||||
showdistinct = False if token == "one" else True
|
|
||||||
else:
|
else:
|
||||||
self._findText(token, isNeg, c)
|
self._findText(token, isNeg, c)
|
||||||
|
|
||||||
|
@ -151,9 +131,18 @@ class Finder(object):
|
||||||
lims = []
|
lims = []
|
||||||
comp = "!=" if isNeg else "="
|
comp = "!=" if isNeg else "="
|
||||||
found = False
|
found = False
|
||||||
|
try:
|
||||||
|
num = int(val) - 1
|
||||||
|
except:
|
||||||
|
num = None
|
||||||
for m in self.deck.models().values():
|
for m in self.deck.models().values():
|
||||||
for t in m.templates:
|
for t in m.templates:
|
||||||
if t['name'].lower() == val.lower():
|
# ordinal number?
|
||||||
|
if num is not None and t['ord'] == num:
|
||||||
|
self.lims['card'].append("ord %s %d" % (comp, num))
|
||||||
|
found = True
|
||||||
|
# template name?
|
||||||
|
elif t['name'].lower() == val.lower():
|
||||||
self.lims['card'].append((
|
self.lims['card'].append((
|
||||||
"(fid in (select id from facts where mid = %d) "
|
"(fid in (select id from facts where mid = %d) "
|
||||||
"and ord %s %d)") % (m.id, comp, t['ord']))
|
"and ord %s %d)") % (m.id, comp, t['ord']))
|
||||||
|
@ -273,9 +262,6 @@ class Finder(object):
|
||||||
elif token['value'].startswith("card:"):
|
elif token['value'].startswith("card:"):
|
||||||
token['value'] = token['value'][5:]
|
token['value'] = token['value'][5:]
|
||||||
type = SEARCH_TEMPLATE
|
type = SEARCH_TEMPLATE
|
||||||
elif token['value'].startswith("show:"):
|
|
||||||
token['value'] = token['value'][5:].lower()
|
|
||||||
type = SEARCH_DISTINCT
|
|
||||||
elif token['value'].startswith("field:"):
|
elif token['value'].startswith("field:"):
|
||||||
type = SEARCH_FIELD_EXISTS
|
type = SEARCH_FIELD_EXISTS
|
||||||
parts = token['value'][6:].split(':', 1)
|
parts = token['value'][6:].split(':', 1)
|
||||||
|
|
|
@ -65,3 +65,6 @@ def test_findCards():
|
||||||
# templates
|
# templates
|
||||||
assert len(deck.findCards("card:foo")) == 0
|
assert len(deck.findCards("card:foo")) == 0
|
||||||
assert len(deck.findCards("card:forward")) == 4
|
assert len(deck.findCards("card:forward")) == 4
|
||||||
|
assert len(deck.findCards("card:reverse")) == 1
|
||||||
|
assert len(deck.findCards("card:1")) == 4
|
||||||
|
assert len(deck.findCards("card:2")) == 1
|
||||||
|
|
Loading…
Reference in a new issue