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:
Kovid Goyal 2022-04-23 12:51:54 +05:30
parent 303006cb11
commit aad20ae447
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 16 additions and 7 deletions

View File

@ -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

View File

@ -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: "Gravitys 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

View File

@ -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ñas</string>
</property>
<property name="text">
<string>Unaccented characters match &amp;accented characters</string>
<string>Unaccented characters match &amp;accented characters and punctuation is ignored</string>
</property>
</widget>
</item>
@ -165,7 +169,7 @@
</property>
</widget>
</item>
<item row="0" column="1">
<item row="0" column="1">
<widget class="QComboBox" name="gst_names">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -212,7 +216,7 @@ a search term by changing the value box then pressing Save.</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="1" column="1">
<widget class="EditWithComplete" name="gst_value">
<property name="toolTip">
<string>Enter a comma-separated list of lookup names of the columns

View File

@ -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
_primary_no_punc_collator.set_attribute(_icu.UCOL_ALTERNATE_HANDLING, _icu.UCOL_SHIFTED)
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