mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32:23 -04:00
support searches for particular ratings
This commit is contained in:
parent
3755a8f82d
commit
ef4ff86f8c
2 changed files with 36 additions and 0 deletions
23
anki/find.py
23
anki/find.py
|
@ -15,6 +15,7 @@ SEARCH_FIELD = 5
|
||||||
SEARCH_MODEL = 6
|
SEARCH_MODEL = 6
|
||||||
SEARCH_DECK = 7
|
SEARCH_DECK = 7
|
||||||
SEARCH_PROP = 8
|
SEARCH_PROP = 8
|
||||||
|
SEARCH_RATED = 9
|
||||||
|
|
||||||
# Tools
|
# Tools
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -122,6 +123,8 @@ and c.nid=n.id %s""" % (q, order)
|
||||||
self._findDeck(token, isNeg)
|
self._findDeck(token, isNeg)
|
||||||
elif type == SEARCH_PROP:
|
elif type == SEARCH_PROP:
|
||||||
self._findProp(token, isNeg)
|
self._findProp(token, isNeg)
|
||||||
|
elif type == SEARCH_RATED:
|
||||||
|
self._findRated(token, isNeg)
|
||||||
else:
|
else:
|
||||||
self._findText(token, isNeg, c)
|
self._findText(token, isNeg, c)
|
||||||
|
|
||||||
|
@ -164,6 +167,23 @@ and c.nid=n.id %s""" % (q, order)
|
||||||
else:
|
else:
|
||||||
self.lims['valid'] = False
|
self.lims['valid'] = False
|
||||||
|
|
||||||
|
def _findRated(self, val, neg):
|
||||||
|
r = val.split(":")
|
||||||
|
if len(r) != 2 or r[0] not in ("1", "2", "3", "4"):
|
||||||
|
self.lims['valid'] = False
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
days = int(r[1])
|
||||||
|
except ValueError:
|
||||||
|
self.lims['valid'] = False
|
||||||
|
return
|
||||||
|
# bound the search
|
||||||
|
days = min(days, 31)
|
||||||
|
lim = self.col.sched.dayCutoff - 86400*days
|
||||||
|
self.lims['preds'].append(
|
||||||
|
"c.id in (select cid from revlog where ease=%s and id>%d)" %
|
||||||
|
(r[0], (lim*1000)))
|
||||||
|
|
||||||
def _findProp(self, val, neg):
|
def _findProp(self, val, neg):
|
||||||
# extract
|
# extract
|
||||||
m = re.match("(^.+?)(<=|>=|=|<|>)(.+?$)", val)
|
m = re.match("(^.+?)(<=|>=|=|<|>)(.+?$)", val)
|
||||||
|
@ -418,6 +438,9 @@ n.mid in %s and n.id %s in %s""" % (
|
||||||
elif token['value'].startswith("prop:"):
|
elif token['value'].startswith("prop:"):
|
||||||
token['value'] = token['value'][5:].lower()
|
token['value'] = token['value'][5:].lower()
|
||||||
type = SEARCH_PROP
|
type = SEARCH_PROP
|
||||||
|
elif token['value'].startswith("rated:"):
|
||||||
|
token['value'] = token['value'][6:].lower()
|
||||||
|
type = SEARCH_RATED
|
||||||
elif token['value'].startswith("nid:") and len(token['value']) > 4:
|
elif token['value'].startswith("nid:") and len(token['value']) > 4:
|
||||||
dec = token['value'][4:]
|
dec = token['value'][4:]
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -160,6 +160,19 @@ def test_findCards():
|
||||||
assert len(deck.findCards("prop:ease=2.2")) == 1
|
assert len(deck.findCards("prop:ease=2.2")) == 1
|
||||||
assert len(deck.findCards("prop:ease>2")) == 1
|
assert len(deck.findCards("prop:ease>2")) == 1
|
||||||
assert len(deck.findCards("-prop:ease>2")) > 1
|
assert len(deck.findCards("-prop:ease>2")) > 1
|
||||||
|
# recently failed
|
||||||
|
assert len(deck.findCards("rated:1:1")) == 0
|
||||||
|
assert len(deck.findCards("rated:2:1")) == 0
|
||||||
|
c = deck.sched.getCard()
|
||||||
|
deck.sched.answerCard(c, 2)
|
||||||
|
assert len(deck.findCards("rated:1:1")) == 0
|
||||||
|
assert len(deck.findCards("rated:2:1")) == 1
|
||||||
|
c = deck.sched.getCard()
|
||||||
|
deck.sched.answerCard(c, 1)
|
||||||
|
assert len(deck.findCards("rated:1:1")) == 1
|
||||||
|
assert len(deck.findCards("rated:2:1")) == 1
|
||||||
|
assert len(deck.findCards("rated:2:0")) == 0
|
||||||
|
assert len(deck.findCards("rated:2:2")) == 1
|
||||||
|
|
||||||
def test_findReplace():
|
def test_findReplace():
|
||||||
deck = getEmptyDeck()
|
deck = getEmptyDeck()
|
||||||
|
|
Loading…
Reference in a new issue