mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Get Books: Fix title author search handling
Get Books: Fix searching for title and author returning some extra matches, if the title starts with an article like the, a or an. Fixes #1200012 ["Get books" search is too fuzzy](https://bugs.launchpad.net/calibre/+bug/1200012)
This commit is contained in:
parent
5542dcfbb3
commit
b982bcc3f2
@ -229,14 +229,14 @@ class Matches(QAbstractItemModel):
|
||||
if col == 1:
|
||||
return QVariant('<p>%s</p>' % result.title)
|
||||
elif col == 2:
|
||||
return QVariant('<p>' + _('Detected price as: %s. Check with the store before making a purchase to verify this price is correct. This price often does not include promotions the store may be running.') % result.price + '</p>')
|
||||
return QVariant('<p>' + _('Detected price as: %s. Check with the store before making a purchase to verify this price is correct. This price often does not include promotions the store may be running.') % result.price + '</p>') # noqa
|
||||
elif col == 3:
|
||||
if result.drm == SearchResult.DRM_LOCKED:
|
||||
return QVariant('<p>' + _('This book as been detected as having DRM restrictions. This book may not work with your reader and you will have limitations placed upon you as to what you can do with this book. Check with the store before making any purchases to ensure you can actually read this book.') + '</p>')
|
||||
return QVariant('<p>' + _('This book as been detected as having DRM restrictions. This book may not work with your reader and you will have limitations placed upon you as to what you can do with this book. Check with the store before making any purchases to ensure you can actually read this book.') + '</p>') # noqa
|
||||
elif result.drm == SearchResult.DRM_UNLOCKED:
|
||||
return QVariant('<p>' + _('This book has been detected as being DRM Free. You should be able to use this book on any device provided it is in a format calibre supports for conversion. However, before making a purchase double check the DRM status with the store. The store may not be disclosing the use of DRM.') + '</p>')
|
||||
return QVariant('<p>' + _('This book has been detected as being DRM Free. You should be able to use this book on any device provided it is in a format calibre supports for conversion. However, before making a purchase double check the DRM status with the store. The store may not be disclosing the use of DRM.') + '</p>') # noqa
|
||||
else:
|
||||
return QVariant('<p>' + _('The DRM status of this book could not be determined. There is a very high likelihood that this book is actually DRM restricted.') + '</p>')
|
||||
return QVariant('<p>' + _('The DRM status of this book could not be determined. There is a very high likelihood that this book is actually DRM restricted.') + '</p>') # noqa
|
||||
elif col == 4:
|
||||
return QVariant('<p>%s</p>' % result.formats)
|
||||
elif col == 5:
|
||||
@ -337,7 +337,7 @@ class SearchFilter(SearchQueryParser):
|
||||
|
||||
def _match(self, query, value, matchkind):
|
||||
for t in value:
|
||||
try: ### ignore regexp exceptions, required because search-ahead tries before typing is finished
|
||||
try: # ignore regexp exceptions, required because search-ahead tries before typing is finished
|
||||
t = icu_lower(t)
|
||||
if matchkind == self.EQUALS_MATCH:
|
||||
if query == t:
|
||||
@ -375,7 +375,7 @@ class SearchFilter(SearchQueryParser):
|
||||
elif query.startswith('~'):
|
||||
matchkind = self.REGEXP_MATCH
|
||||
query = query[1:]
|
||||
if matchkind != self.REGEXP_MATCH: ### leave case in regexps because it can be significant e.g. \S \W \D
|
||||
if matchkind != self.REGEXP_MATCH: # leave case in regexps because it can be significant e.g. \S \W \D
|
||||
query = query.lower()
|
||||
|
||||
if location not in self.USABLE_LOCATIONS:
|
||||
@ -439,9 +439,9 @@ class SearchFilter(SearchQueryParser):
|
||||
if locvalue in ('affiliate', 'drm', 'download', 'downloads'):
|
||||
continue
|
||||
try:
|
||||
### Can't separate authors because comma is used for name sep and author sep
|
||||
### Exact match might not get what you want. For that reason, turn author
|
||||
### exactmatch searches into contains searches.
|
||||
# Can't separate authors because comma is used for name sep and author sep
|
||||
# Exact match might not get what you want. For that reason, turn author
|
||||
# exactmatch searches into contains searches.
|
||||
if locvalue == 'author' and matchkind == self.EQUALS_MATCH:
|
||||
m = self.CONTAINS_MATCH
|
||||
else:
|
||||
@ -452,13 +452,15 @@ class SearchFilter(SearchQueryParser):
|
||||
elif locvalue in ('author2', 'title2'):
|
||||
m = self.IN_MATCH
|
||||
vals = re.sub(r'(^|\s)(and|not|or|a|the|is|of|,)(\s|$)', ' ', accessor(sr)).split(' ')
|
||||
vals = [x for x in vals if x]
|
||||
final_query = query.lower()
|
||||
else:
|
||||
vals = [accessor(sr)]
|
||||
if self._match(final_query, vals, m):
|
||||
matches.add(sr)
|
||||
break
|
||||
except ValueError: # Unicode errors
|
||||
except ValueError: # Unicode errors
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return matches
|
||||
|
||||
|
@ -236,11 +236,11 @@ class SearchDialog(QDialog, Ui_Dialog):
|
||||
query = re.sub(r'%s:"[^"]"' % loc, '', query)
|
||||
query = re.sub(r'%s:[^\s]*' % loc, '', query)
|
||||
# Remove logic.
|
||||
query = re.sub(r'(^|\s)(and|not|or|a|the|is|of)(\s|$)', ' ', query)
|
||||
query = re.sub(r'(^|\s|")(and|not|or|a|the|is|of)(\s|$|")', r' ', query)
|
||||
# Remove "
|
||||
query = query.replace('"', '')
|
||||
# Remove excess whitespace.
|
||||
query = re.sub(r'\s{2,}', ' ', query)
|
||||
query = re.sub(r'\s+', ' ', query)
|
||||
query = query.strip()
|
||||
return query.encode('utf-8')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user