mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Don't throw exception when searching with token:
This commit is contained in:
parent
d015f179ac
commit
c2f74ca22a
@ -239,7 +239,18 @@ class BooksModel(QAbstractTableModel):
|
|||||||
self.endInsertRows()
|
self.endInsertRows()
|
||||||
self.count_changed()
|
self.count_changed()
|
||||||
|
|
||||||
|
def clean_search_text(self, text):
|
||||||
|
tokens = text.split(' ')
|
||||||
|
for i, token in enumerate(tokens):
|
||||||
|
if token.strip().endswith(':') or token.strip() == '':
|
||||||
|
del tokens[i]
|
||||||
|
text = ' '.join(tokens)
|
||||||
|
if text.strip() == '':
|
||||||
|
text = None
|
||||||
|
return text
|
||||||
|
|
||||||
def search(self, text, refinement, reset=True):
|
def search(self, text, refinement, reset=True):
|
||||||
|
text = self.clean_search_text(text)
|
||||||
self.db.search(text)
|
self.db.search(text)
|
||||||
self.last_search = text
|
self.last_search = text
|
||||||
if reset:
|
if reset:
|
||||||
@ -851,9 +862,9 @@ class DeviceBooksModel(BooksModel):
|
|||||||
flags |= Qt.ItemIsEditable
|
flags |= Qt.ItemIsEditable
|
||||||
return flags
|
return flags
|
||||||
|
|
||||||
|
|
||||||
def search(self, text, refinement, reset=True):
|
def search(self, text, refinement, reset=True):
|
||||||
if not text or not text.strip():
|
text = self.clean_search_text(text)
|
||||||
|
if not text:
|
||||||
self.map = list(range(len(self.db)))
|
self.map = list(range(len(self.db)))
|
||||||
else:
|
else:
|
||||||
matches = self.search_engine.parse(text)
|
matches = self.search_engine.parse(text)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user