diff --git a/anki/find.py b/anki/find.py index 0202488b4..be2dab02f 100644 --- a/anki/find.py +++ b/anki/find.py @@ -159,8 +159,9 @@ and c.nid=n.id %s""" % (q, order) extra = "not" if neg else "" if not self.full: self.lims['args']["_text_%d"%c] = "%"+val+"%" - self.lims['preds'].append("flds %s like :_text_%d escape '\\'" % ( - extra, c)) + self.lims['preds'].append("""\ +(sfld %s like :_text_%d escape '\\' or +flds %s like :_text_%d escape '\\')""" % (extra, c, extra, c)) else: # in the future we may want to apply this at the end to speed up # the case where there are other limits diff --git a/tests/test_find.py b/tests/test_find.py index 98710c08f..161666499 100644 --- a/tests/test_find.py +++ b/tests/test_find.py @@ -111,12 +111,18 @@ def test_findCards(): # full search f = deck.newNote() f['Front'] = u'helloworld' - f['Back'] = u'' + f['Back'] = u'abc' deck.addNote(f) + # as it's the sort field, it matches + assert len(deck.findCards("helloworld")) == 2 + assert len(deck.findCards("helloworld", full=True)) == 2 + # if we put it on the back, it won't + (f['Front'], f['Back']) = (f['Back'], f['Front']) + f.flush() assert len(deck.findCards("helloworld")) == 0 - assert len(deck.findCards("helloworld", full=True)) == 1 + assert len(deck.findCards("helloworld", full=True)) == 2 assert len(deck.findCards("front:helloworld")) == 0 - assert len(deck.findCards("front:helloworld", full=True)) == 1 + 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