diff --git a/src/calibre/gui2/viewer/search.py b/src/calibre/gui2/viewer/search.py index f42311aae2..c819dea109 100644 --- a/src/calibre/gui2/viewer/search.py +++ b/src/calibre/gui2/viewer/search.py @@ -18,6 +18,7 @@ from calibre.gui2.progress_indicator import ProgressIndicator from calibre.gui2.viewer.config import vprefs from calibre.gui2.viewer.web_view import get_data, get_manifest from calibre.gui2.viewer.widgets import ResultsDelegate, SearchBox +from calibre.utils.icu import primary_collator_without_punctuation from polyglot.builtins import iteritems from polyglot.functools import lru_cache from polyglot.queue import Queue @@ -312,9 +313,15 @@ def toc_nodes_for_search_result(sr): def search_in_name(name, search_query, ctx_size=75): raw = searchable_text_for_name(name)[0] - def miter(): - for match in search_query.regex.finditer(raw): - yield match.span() + if search_query.mode in ('word', 'regex') or search_query.case_sensitive: + def miter(): + for match in search_query.regex.finditer(raw): + yield match.span() + else: + spans = [] + a = lambda s, l: spans.append((s, s + l)) + primary_collator_without_punctuation().find_all(search_query.text, raw, a) + miter = lambda: spans for (start, end) in miter(): before = raw[max(0, start-ctx_size):start] @@ -371,7 +378,8 @@ class SearchInput(QWidget): # {{{ qt.addItem(_('Regex'), 'regex') qt.setToolTip('

' + _( 'Choose the type of search: