diff --git a/src/calibre/gui2/store/search/models.py b/src/calibre/gui2/store/search/models.py index 59292b54d7..af2c274bd7 100644 --- a/src/calibre/gui2/store/search/models.py +++ b/src/calibre/gui2/store/search/models.py @@ -229,14 +229,14 @@ class Matches(QAbstractItemModel): if col == 1: return QVariant('
%s
' % result.title) elif col == 2: - return QVariant('' + _('Detected price as: %s. Check with the store before making a purchase to verify this price is correct. This price often does not include promotions the store may be running.') % result.price + '
') + return QVariant('' + _('Detected price as: %s. Check with the store before making a purchase to verify this price is correct. This price often does not include promotions the store may be running.') % result.price + '
') # noqa elif col == 3: if result.drm == SearchResult.DRM_LOCKED: - return QVariant('' + _('This book as been detected as having DRM restrictions. This book may not work with your reader and you will have limitations placed upon you as to what you can do with this book. Check with the store before making any purchases to ensure you can actually read this book.') + '
') + return QVariant('' + _('This book as been detected as having DRM restrictions. This book may not work with your reader and you will have limitations placed upon you as to what you can do with this book. Check with the store before making any purchases to ensure you can actually read this book.') + '
') # noqa elif result.drm == SearchResult.DRM_UNLOCKED: - return QVariant('' + _('This book has been detected as being DRM Free. You should be able to use this book on any device provided it is in a format calibre supports for conversion. However, before making a purchase double check the DRM status with the store. The store may not be disclosing the use of DRM.') + '
') + return QVariant('' + _('This book has been detected as being DRM Free. You should be able to use this book on any device provided it is in a format calibre supports for conversion. However, before making a purchase double check the DRM status with the store. The store may not be disclosing the use of DRM.') + '
') # noqa else: - return QVariant('' + _('The DRM status of this book could not be determined. There is a very high likelihood that this book is actually DRM restricted.') + '
') + return QVariant('' + _('The DRM status of this book could not be determined. There is a very high likelihood that this book is actually DRM restricted.') + '
') # noqa elif col == 4: return QVariant('%s
' % result.formats) elif col == 5: @@ -337,7 +337,7 @@ class SearchFilter(SearchQueryParser): def _match(self, query, value, matchkind): for t in value: - try: ### ignore regexp exceptions, required because search-ahead tries before typing is finished + try: # ignore regexp exceptions, required because search-ahead tries before typing is finished t = icu_lower(t) if matchkind == self.EQUALS_MATCH: if query == t: @@ -375,7 +375,7 @@ class SearchFilter(SearchQueryParser): elif query.startswith('~'): matchkind = self.REGEXP_MATCH query = query[1:] - if matchkind != self.REGEXP_MATCH: ### leave case in regexps because it can be significant e.g. \S \W \D + if matchkind != self.REGEXP_MATCH: # leave case in regexps because it can be significant e.g. \S \W \D query = query.lower() if location not in self.USABLE_LOCATIONS: @@ -439,9 +439,9 @@ class SearchFilter(SearchQueryParser): if locvalue in ('affiliate', 'drm', 'download', 'downloads'): continue try: - ### Can't separate authors because comma is used for name sep and author sep - ### Exact match might not get what you want. For that reason, turn author - ### exactmatch searches into contains searches. + # Can't separate authors because comma is used for name sep and author sep + # Exact match might not get what you want. For that reason, turn author + # exactmatch searches into contains searches. if locvalue == 'author' and matchkind == self.EQUALS_MATCH: m = self.CONTAINS_MATCH else: @@ -452,13 +452,15 @@ class SearchFilter(SearchQueryParser): elif locvalue in ('author2', 'title2'): m = self.IN_MATCH vals = re.sub(r'(^|\s)(and|not|or|a|the|is|of|,)(\s|$)', ' ', accessor(sr)).split(' ') + vals = [x for x in vals if x] final_query = query.lower() else: vals = [accessor(sr)] if self._match(final_query, vals, m): matches.add(sr) break - except ValueError: # Unicode errors + except ValueError: # Unicode errors import traceback traceback.print_exc() return matches + diff --git a/src/calibre/gui2/store/search/search.py b/src/calibre/gui2/store/search/search.py index 117bc0dca3..7e39e5d513 100644 --- a/src/calibre/gui2/store/search/search.py +++ b/src/calibre/gui2/store/search/search.py @@ -236,11 +236,11 @@ class SearchDialog(QDialog, Ui_Dialog): query = re.sub(r'%s:"[^"]"' % loc, '', query) query = re.sub(r'%s:[^\s]*' % loc, '', query) # Remove logic. - query = re.sub(r'(^|\s)(and|not|or|a|the|is|of)(\s|$)', ' ', query) + query = re.sub(r'(^|\s|")(and|not|or|a|the|is|of)(\s|$|")', r' ', query) # Remove " query = query.replace('"', '') # Remove excess whitespace. - query = re.sub(r'\s{2,}', ' ', query) + query = re.sub(r'\s+', ' ', query) query = query.strip() return query.encode('utf-8')