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
|
||||
|
||||
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 qstring_to_unicode
|
||||
|
||||
@ -160,7 +160,7 @@ class BooksModel(QAbstractTableModel):
|
||||
ans = []
|
||||
for i in tokens:
|
||||
try:
|
||||
ans.append(re.compile(i, re.IGNORECASE))
|
||||
ans.append(SearchToken(i))
|
||||
except sre_constants.error:
|
||||
continue
|
||||
return ans
|
||||
@ -505,7 +505,7 @@ class DeviceBooksModel(BooksModel):
|
||||
add = True
|
||||
q = self.db[i].title + ' ' + self.db[i].authors + ' ' + ', '.join(self.db[i].tags)
|
||||
for token in tokens:
|
||||
if not token.search(q):
|
||||
if not token.match(q):
|
||||
add = False
|
||||
break
|
||||
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:
|
||||
keep = True
|
||||
test = ' '.join([item[i] if item[i] else '' for i in (1,2,3,7,8,9,13)])
|
||||
for filter in filters:
|
||||
if not filter.search(test):
|
||||
for token in filters:
|
||||
if not token.match(test):
|
||||
keep = False
|
||||
break
|
||||
if keep:
|
||||
@ -1237,6 +1237,19 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
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__':
|
||||
db = LibraryDatabase('/home/kovid/library1.db')
|
||||
|
Loading…
x
Reference in New Issue
Block a user