mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
E-book viewer: Ignore accents when doing a search
This commit is contained in:
parent
9814b8060e
commit
559f787adf
@ -18,6 +18,7 @@ from calibre.gui2.progress_indicator import ProgressIndicator
|
|||||||
from calibre.gui2.viewer.config import vprefs
|
from calibre.gui2.viewer.config import vprefs
|
||||||
from calibre.gui2.viewer.web_view import get_data, get_manifest
|
from calibre.gui2.viewer.web_view import get_data, get_manifest
|
||||||
from calibre.gui2.viewer.widgets import ResultsDelegate, SearchBox
|
from calibre.gui2.viewer.widgets import ResultsDelegate, SearchBox
|
||||||
|
from calibre.utils.icu import primary_collator_without_punctuation
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
from polyglot.functools import lru_cache
|
from polyglot.functools import lru_cache
|
||||||
from polyglot.queue import Queue
|
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):
|
def search_in_name(name, search_query, ctx_size=75):
|
||||||
raw = searchable_text_for_name(name)[0]
|
raw = searchable_text_for_name(name)[0]
|
||||||
|
|
||||||
def miter():
|
if search_query.mode in ('word', 'regex') or search_query.case_sensitive:
|
||||||
for match in search_query.regex.finditer(raw):
|
def miter():
|
||||||
yield match.span()
|
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():
|
for (start, end) in miter():
|
||||||
before = raw[max(0, start-ctx_size):start]
|
before = raw[max(0, start-ctx_size):start]
|
||||||
@ -371,7 +378,8 @@ class SearchInput(QWidget): # {{{
|
|||||||
qt.addItem(_('Regex'), 'regex')
|
qt.addItem(_('Regex'), 'regex')
|
||||||
qt.setToolTip('<p>' + _(
|
qt.setToolTip('<p>' + _(
|
||||||
'Choose the type of search: <ul>'
|
'Choose the type of search: <ul>'
|
||||||
'<li><b>Contains</b> will search for the entered text anywhere.'
|
'<li><b>Contains</b> will search for the entered text anywhere. It will ignore punctuation,'
|
||||||
|
' spaces and accents, unless Case sensitive searching is enabled.'
|
||||||
'<li><b>Whole words</b> will search for whole words that equal the entered text.'
|
'<li><b>Whole words</b> will search for whole words that equal the entered text.'
|
||||||
'<li><b>Regex</b> will interpret the text as a regular expression.'
|
'<li><b>Regex</b> will interpret the text as a regular expression.'
|
||||||
))
|
))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user