mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Searching: Ignore punctuation when searching in the book list. So that, for example: Gravitys will match Gravity's. Fixes #1969926 [[Enhancement] Match both straight and curly apostrophe types when searching](https://bugs.launchpad.net/calibre/+bug/1969926)
This commit is contained in:
parent
303006cb11
commit
aad20ae447
@ -14,7 +14,7 @@ from calibre.constants import preferred_encoding, DEBUG
|
||||
from calibre.db.utils import force_to_bool
|
||||
from calibre.utils.config_base import prefs
|
||||
from calibre.utils.date import parse_date, UNDEFINED_DATE, now, dt_as_local
|
||||
from calibre.utils.icu import primary_contains, sort_key
|
||||
from calibre.utils.icu import primary_no_punc_contains, sort_key
|
||||
from calibre.utils.localization import lang_map, canonicalize_lang
|
||||
from calibre.utils.search_query_parser import SearchQueryParser, ParseException
|
||||
from polyglot.builtins import iteritems, string_or_bytes
|
||||
@ -76,7 +76,7 @@ def _match(query, value, matchkind, use_primary_find_in_search=True, case_sensit
|
||||
return True
|
||||
elif matchkind == CONTAINS_MATCH:
|
||||
if not case_sensitive and use_primary_find_in_search:
|
||||
if primary_contains(query, t):
|
||||
if primary_no_punc_contains(query, t):
|
||||
return True
|
||||
elif query in t:
|
||||
return True
|
||||
|
@ -324,7 +324,6 @@ class ReadingTest(BaseTest):
|
||||
'formats:#>1', 'formats:#=1', 'formats:=fmt1', 'formats:=fmt2',
|
||||
'formats:=fmt1 or formats:fmt2', '#formats:true', '#formats:false',
|
||||
'#formats:fmt1', '#formats:fmt2', '#formats:fmt1 and #formats:fmt2',
|
||||
|
||||
)}
|
||||
old.conn.close()
|
||||
old = None
|
||||
@ -375,6 +374,9 @@ class ReadingTest(BaseTest):
|
||||
self.assertEqual(cache.search('template:{series}#@#:b:true'), {1,2})
|
||||
self.assertEqual(cache.search('template:{series}#@#:b:false'), {3})
|
||||
|
||||
# test primary search
|
||||
cache.set_field('title', {1: "Gravity’s Raiñbow"})
|
||||
self.assertEqual(cache.search('title:"Gravity\'s Rainbow"'), {1})
|
||||
# Note that the old db searched uuid for un-prefixed searches, the new
|
||||
# db does not, for performance
|
||||
|
||||
|
@ -135,8 +135,12 @@
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="opt_use_primary_find_in_search">
|
||||
<property name="toolTip">
|
||||
<string>Searching will ignore accents on characters as well as punctuation. So for example:
|
||||
Penas will match Peña’s</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Unaccented characters match &accented characters</string>
|
||||
<string>Unaccented characters match &accented characters and punctuation is ignored</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -88,7 +88,10 @@ def primary_collator_without_punctuation():
|
||||
if _primary_no_punc_collator is None:
|
||||
_primary_no_punc_collator = collator().clone()
|
||||
_primary_no_punc_collator.strength = _icu.UCOL_PRIMARY
|
||||
try:
|
||||
_primary_no_punc_collator.set_attribute(_icu.UCOL_ALTERNATE_HANDLING, _icu.UCOL_SHIFTED)
|
||||
except AttributeError:
|
||||
pass # people running from source without latest binary
|
||||
return _primary_no_punc_collator
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user