mirror of
https://github.com/ankitects/anki.git
synced 2025-11-13 08:07:11 -05:00
support searching for fact ids
This commit is contained in:
parent
d9d7fff820
commit
b237bcbdf0
1 changed files with 18 additions and 2 deletions
20
anki/deck.py
20
anki/deck.py
|
|
@ -49,6 +49,7 @@ REV_CARDS_RANDOM = 3
|
||||||
SEARCH_TAG = 0
|
SEARCH_TAG = 0
|
||||||
SEARCH_TYPE = 1
|
SEARCH_TYPE = 1
|
||||||
SEARCH_PHRASE = 2
|
SEARCH_PHRASE = 2
|
||||||
|
SEARCH_FID = 3
|
||||||
DECK_VERSION = 35
|
DECK_VERSION = 35
|
||||||
|
|
||||||
deckVarsTable = Table(
|
deckVarsTable = Table(
|
||||||
|
|
@ -1773,6 +1774,9 @@ where id = :id""", pending)
|
||||||
elif token.startswith("is:"):
|
elif token.startswith("is:"):
|
||||||
token = token[3:]
|
token = token[3:]
|
||||||
type = SEARCH_TYPE
|
type = SEARCH_TYPE
|
||||||
|
elif token.startswith("fid:") and len(token) > 4:
|
||||||
|
token = token[4:]
|
||||||
|
type = SEARCH_FID
|
||||||
else:
|
else:
|
||||||
type = SEARCH_PHRASE
|
type = SEARCH_PHRASE
|
||||||
res.append((token, isNeg, type))
|
res.append((token, isNeg, type))
|
||||||
|
|
@ -1783,6 +1787,7 @@ where id = :id""", pending)
|
||||||
tquery = ""
|
tquery = ""
|
||||||
fquery = ""
|
fquery = ""
|
||||||
qquery = ""
|
qquery = ""
|
||||||
|
fidquery = ""
|
||||||
args = {}
|
args = {}
|
||||||
for c, (token, isNeg, type) in enumerate(self._parseQuery(query)):
|
for c, (token, isNeg, type) in enumerate(self._parseQuery(query)):
|
||||||
if type == SEARCH_TAG:
|
if type == SEARCH_TAG:
|
||||||
|
|
@ -1828,6 +1833,15 @@ cardTags.tagId in %s""" % ids2str(ids)
|
||||||
else: # due
|
else: # due
|
||||||
qquery += ("select id from cards where "
|
qquery += ("select id from cards where "
|
||||||
"type in (0,1) and isDue = 1")
|
"type in (0,1) and isDue = 1")
|
||||||
|
elif type == SEARCH_FID:
|
||||||
|
if fidquery:
|
||||||
|
if isNeg:
|
||||||
|
fidquery += " except "
|
||||||
|
else:
|
||||||
|
fidquery += " intersect "
|
||||||
|
elif isNeg:
|
||||||
|
fidquery += "select id from cards except "
|
||||||
|
fidquery += "select id from cards where factId = %s" % token
|
||||||
else:
|
else:
|
||||||
# a field
|
# a field
|
||||||
if fquery:
|
if fquery:
|
||||||
|
|
@ -1841,10 +1855,10 @@ cardTags.tagId in %s""" % ids2str(ids)
|
||||||
args["_ff_%d" % c] = "%"+token+"%"
|
args["_ff_%d" % c] = "%"+token+"%"
|
||||||
q = "select factId from fields where value like :_ff_%d" % c
|
q = "select factId from fields where value like :_ff_%d" % c
|
||||||
fquery += q
|
fquery += q
|
||||||
return (tquery, fquery, qquery, args)
|
return (tquery, fquery, qquery, fidquery, args)
|
||||||
|
|
||||||
def findCardsWhere(self, query):
|
def findCardsWhere(self, query):
|
||||||
(tquery, fquery, qquery, args) = self._findCards(query)
|
(tquery, fquery, qquery, fidquery, args) = self._findCards(query)
|
||||||
q = ""
|
q = ""
|
||||||
x = []
|
x = []
|
||||||
if tquery:
|
if tquery:
|
||||||
|
|
@ -1853,6 +1867,8 @@ cardTags.tagId in %s""" % ids2str(ids)
|
||||||
x.append(" factId in (%s)" % fquery)
|
x.append(" factId in (%s)" % fquery)
|
||||||
if qquery:
|
if qquery:
|
||||||
x.append(" id in (%s)" % qquery)
|
x.append(" id in (%s)" % qquery)
|
||||||
|
if fidquery:
|
||||||
|
x.append(" id in (%s)" % fidquery)
|
||||||
if x:
|
if x:
|
||||||
q += " and ".join(x)
|
q += " and ".join(x)
|
||||||
return q, args
|
return q, args
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue