mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement #459
This commit is contained in:
parent
da51c78758
commit
36ce446990
@ -25,7 +25,7 @@ from PyQt4.QtCore import QAbstractTableModel, QVariant, Qt, QString, \
|
|||||||
QSettings
|
QSettings
|
||||||
|
|
||||||
from libprs500.ptempfile import PersistentTemporaryFile
|
from libprs500.ptempfile import PersistentTemporaryFile
|
||||||
from libprs500.library.database import LibraryDatabase
|
from libprs500.library.database import LibraryDatabase, SearchToken
|
||||||
from libprs500.gui2 import NONE, TableView
|
from libprs500.gui2 import NONE, TableView
|
||||||
from libprs500.gui2 import qstring_to_unicode
|
from libprs500.gui2 import qstring_to_unicode
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ class BooksModel(QAbstractTableModel):
|
|||||||
ans = []
|
ans = []
|
||||||
for i in tokens:
|
for i in tokens:
|
||||||
try:
|
try:
|
||||||
ans.append(re.compile(i, re.IGNORECASE))
|
ans.append(SearchToken(i))
|
||||||
except sre_constants.error:
|
except sre_constants.error:
|
||||||
continue
|
continue
|
||||||
return ans
|
return ans
|
||||||
@ -505,7 +505,7 @@ class DeviceBooksModel(BooksModel):
|
|||||||
add = True
|
add = True
|
||||||
q = self.db[i].title + ' ' + self.db[i].authors + ' ' + ', '.join(self.db[i].tags)
|
q = self.db[i].title + ' ' + self.db[i].authors + ' ' + ', '.join(self.db[i].tags)
|
||||||
for token in tokens:
|
for token in tokens:
|
||||||
if not token.search(q):
|
if not token.match(q):
|
||||||
add = False
|
add = False
|
||||||
break
|
break
|
||||||
if add:
|
if add:
|
||||||
|
@ -805,8 +805,8 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
|||||||
for item in self.data if refilter else self.cache:
|
for item in self.data if refilter else self.cache:
|
||||||
keep = True
|
keep = True
|
||||||
test = ' '.join([item[i] if item[i] else '' for i in (1,2,3,7,8,9,13)])
|
test = ' '.join([item[i] if item[i] else '' for i in (1,2,3,7,8,9,13)])
|
||||||
for filter in filters:
|
for token in filters:
|
||||||
if not filter.search(test):
|
if not token.match(test):
|
||||||
keep = False
|
keep = False
|
||||||
break
|
break
|
||||||
if keep:
|
if keep:
|
||||||
@ -1236,7 +1236,20 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
class SearchToken(object):
|
||||||
|
|
||||||
|
def __init__(self, text_token):
|
||||||
|
if text_token.startswith('!'):
|
||||||
|
self.negate = True
|
||||||
|
text_token = text_token[1:]
|
||||||
|
else:
|
||||||
|
self.negate = False
|
||||||
|
self.pattern = re.compile(text_token, re.IGNORECASE)
|
||||||
|
|
||||||
|
def match(self, text):
|
||||||
|
return bool(self.pattern.search(text)) ^ self.negate
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
db = LibraryDatabase('/home/kovid/library1.db')
|
db = LibraryDatabase('/home/kovid/library1.db')
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user