check sort field when searching

If the field they want to search is the one being used to sort, this saves us
having to go the full search route
This commit is contained in:
Damien Elmes 2011-12-08 09:53:27 +09:00
parent 08660f6bf8
commit 95106908dd
2 changed files with 12 additions and 5 deletions

View file

@ -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

View file

@ -111,12 +111,18 @@ def test_findCards():
# full search
f = deck.newNote()
f['Front'] = u'hello<b>world</b>'
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