diff --git a/src/calibre/library/caches.py b/src/calibre/library/caches.py index b161e8ec02..d792f693d2 100644 --- a/src/calibre/library/caches.py +++ b/src/calibre/library/caches.py @@ -281,6 +281,10 @@ class ResultCache(SearchQueryParser): matches = set([]) if len(query) == 0: return matches + if query == 'false': + query = '0' + elif query == 'true': + query = '>0' relop = None for k in self.rating_search_relops.keys(): if query.startswith(k): @@ -298,8 +302,13 @@ class ResultCache(SearchQueryParser): loc = self.FIELD_MAP['rating'] for item in self._data: - if item is None or item[loc] is None: continue - if relop(item[loc]/2, r): + if item is None: + continue + if not item[loc]: + i = 0 + else: + i = item[loc]/2 + if relop(i, r): matches.add(item[0]) return matches @@ -312,13 +321,13 @@ class ResultCache(SearchQueryParser): if (location in ('pubdate', 'date')) or \ ((location in self.custom_column_label_map) and \ self.custom_column_label_map[location]['datatype'] == 'datetime'): - return self.get_dates_matches(location, query) + return self.get_dates_matches(location, query.lower()) ### take care of ratings special case if location == 'rating' or \ ((location in self.custom_column_label_map) and \ self.custom_column_label_map[location]['datatype'] == 'rating'): - return self.get_ratings_matches(location, query) + return self.get_ratings_matches(location, query.lower()) ### everything else matchkind = CONTAINS_MATCH diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 64314d306f..931841b8bf 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -636,7 +636,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): tooltip = self.custom_column_label_map[category]['name'] formatter = self.tag_browser_formatters.get(tn, lambda x: x) categories[category] = [Tag(formatter(r[1]), count=r[2], id=r[0], icon=icon, tooltip = tooltip) - for r in data if r[2] > 0] + for r in data + if r[2] > 0 and (category != 'rating' or len(formatter(r[1])) > 0)] categories['format'] = [] for fmt in self.conn.get('SELECT DISTINCT format FROM data'): fmt = fmt[0]