diff --git a/src/calibre/gui2/preferences/search.py b/src/calibre/gui2/preferences/search.py index e41f2f50b6..936d1a2e9e 100644 --- a/src/calibre/gui2/preferences/search.py +++ b/src/calibre/gui2/preferences/search.py @@ -26,6 +26,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): r('search_as_you_type', config) r('highlight_search_matches', config) r('limit_search_columns', prefs) + r('use_primary_find_in_search', prefs) r('limit_search_columns_to', prefs, setting=CommaSeparatedList) fl = db.field_metadata.get_search_terms() self.opt_limit_search_columns_to.update_items_cache(fl) diff --git a/src/calibre/gui2/preferences/search.ui b/src/calibre/gui2/preferences/search.ui index 33c61dd215..8e8ea35199 100644 --- a/src/calibre/gui2/preferences/search.ui +++ b/src/calibre/gui2/preferences/search.ui @@ -7,7 +7,7 @@ 0 0 670 - 556 + 663 @@ -21,14 +21,21 @@ - + + + + Unaccented characters match accented characters + + + + &Highlight search results instead of restricting the book list to the results - + What to search by default @@ -77,17 +84,7 @@ - - - - Clear search histories from all over calibre. Including the book list, e-book viewer, fetch news dialog, etc. - - - Clear search &histories - - - - + Grouped Search Terms @@ -107,12 +104,6 @@ - - true - - - 10 - Contains the names of the currently-defined group search terms. Create a new name by entering it into the empty box, then @@ -120,6 +111,12 @@ pressing Save. Rename a search term by selecting it then changing the name and pressing Save. Change the value of a search term by changing the value box then pressing Save. + + true + + + 10 + @@ -201,7 +198,17 @@ to be shown as user categories - + + + + Clear search histories from all over calibre. Including the book list, e-book viewer, fetch news dialog, etc. + + + Clear search &histories + + + + What to search when searching similar books @@ -211,7 +218,7 @@ to be shown as user categories <p>When you search for similar books by right clicking the - book and selecting "Similar books...", + book and selecting "Similar books...", calibre constructs a search using the column lookup names specified below. By changing the lookup name to a grouped search term you can search multiple columns at once.</p> @@ -239,8 +246,7 @@ to be shown as user categories - - + @@ -260,8 +266,7 @@ to be shown as user categories - - + @@ -271,12 +276,10 @@ to be shown as user categories - - + - - + @@ -286,12 +289,10 @@ to be shown as user categories - - + - - + diff --git a/src/calibre/gui2/preferences/tweaks.py b/src/calibre/gui2/preferences/tweaks.py index 290fff37ba..43370642c5 100644 --- a/src/calibre/gui2/preferences/tweaks.py +++ b/src/calibre/gui2/preferences/tweaks.py @@ -341,9 +341,11 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): tweak = self.tweaks.data(idx, Qt.UserRole) self.context_menu = QMenu(self) self.context_menu.addAction(self.copy_icon, - _('Copy to clipboard'), - partial(self.copy_item_to_clipboard, - val=tweak.name)) + _('Copy to clipboard'), + partial(self.copy_item_to_clipboard, + val=u"%s (%s: %s)"%(tweak.name, + _('ID'), + tweak.var_names[0]))) self.context_menu.popup(self.mapToGlobal(point)) return True diff --git a/src/calibre/library/caches.py b/src/calibre/library/caches.py index caf519e87b..99923657d5 100644 --- a/src/calibre/library/caches.py +++ b/src/calibre/library/caches.py @@ -118,6 +118,9 @@ class MetadataBackup(Thread): # {{{ # }}} +# This is a global for performance +pref_use_primary_find_in_search = False + ### Global utility function for get_match here and in gui2/library.py CONTAINS_MATCH = 0 EQUALS_MATCH = 1 @@ -148,9 +151,12 @@ def _match(query, value, matchkind): elif query == t: return True elif matchkind == REGEXP_MATCH: - return re.search(query, icu_lower(t), re.I|re.UNICODE) + return re.search(query, t, re.I|re.UNICODE) elif matchkind == CONTAINS_MATCH: - return primary_find(query, t)[0] != -1 + if pref_use_primary_find_in_search: + return primary_find(query, t)[0] != -1 + else: + return query in t except re.error: pass return False @@ -611,6 +617,9 @@ class ResultCache(SearchQueryParser): # {{{ def get_matches(self, location, query, candidates=None, allow_recursion=True): + global pref_use_primary_find_in_search + pref_use_primary_find_in_search = prefs['use_primary_find_in_search'] + matches = set([]) if candidates is None: candidates = self.universal_set() @@ -637,8 +646,10 @@ class ResultCache(SearchQueryParser): # {{{ else: invert = False for loc in location: - matches |= self.get_matches(loc, query, + m = self.get_matches(loc, query, candidates=candidates, allow_recursion=False) + matches |= m + candidates -= m if invert: matches = self.universal_set() - matches return matches @@ -655,8 +666,10 @@ class ResultCache(SearchQueryParser): # {{{ if terms: for l in terms: try: - matches |= self.get_matches(l, query, + m = self.get_matches(l, query, candidates=candidates, allow_recursion=allow_recursion) + matches |= m + candidates -= m except: pass return matches diff --git a/src/calibre/utils/config_base.py b/src/calibre/utils/config_base.py index ab22c6b30b..a50d0fd153 100644 --- a/src/calibre/utils/config_base.py +++ b/src/calibre/utils/config_base.py @@ -422,6 +422,12 @@ def _prefs(): 'title:Red. Enter a list of search/lookup names ' 'separated by commas. Only takes effect if you set the option ' 'to limit search columns above.')) + c.add_opt('use_primary_find_in_search', default=True, + help=_('Characters typed in the search box will match their ' + 'accented versions, based on the language you have chosen ' + 'for the calibre interface. For example, in ' + u' English, searching for n will match ñ and n, but if ' + 'your language is Spanish it will only match n.')) c.add_opt('migrated', default=False, help='For Internal use. Don\'t modify.') return c