mirror of
https://github.com/janeczku/calibre-web
synced 2024-09-28 23:10:48 +00:00
now return empty list if all words of query are < 3 letters, only compare term to words > 3 letters of book attributes
This commit is contained in:
parent
c018ef74bc
commit
b96d02c921
@ -54,8 +54,8 @@ from .pagination import Pagination
|
|||||||
from weakref import WeakSet
|
from weakref import WeakSet
|
||||||
from thefuzz.fuzz import partial_ratio, partial_token_set_ratio, partial_token_sort_ratio, ratio
|
from thefuzz.fuzz import partial_ratio, partial_token_set_ratio, partial_token_sort_ratio, ratio
|
||||||
|
|
||||||
# %-level, 100 means exact match
|
# %-level, 100 means exact match, 75 allows exactly 1 wrong character in a 4 letter word
|
||||||
FUZZY_SEARCH_ACCURACY = 80
|
FUZZY_SEARCH_ACCURACY = 75
|
||||||
|
|
||||||
log = logger.create()
|
log = logger.create()
|
||||||
|
|
||||||
@ -911,6 +911,9 @@ class CalibreDB:
|
|||||||
# put the longest words first to make queries more efficient
|
# put the longest words first to make queries more efficient
|
||||||
words.sort(key=len, reverse=True)
|
words.sort(key=len, reverse=True)
|
||||||
words=[x for x in filter(lambda w:len(w)>3,words)]
|
words=[x for x in filter(lambda w:len(w)>3,words)]
|
||||||
|
# no word in search term is longer than 3 letters -> return empty query #TODO give some kind of error message
|
||||||
|
if not any([len(word)>3 for word in words]):
|
||||||
|
return self.session.query(Books).filter(False)
|
||||||
|
|
||||||
query = self.generate_linked_query(config.config_read_column, Books)
|
query = self.generate_linked_query(config.config_read_column, Books)
|
||||||
if len(join) == 6:
|
if len(join) == 6:
|
||||||
@ -1090,7 +1093,7 @@ def lcase(s):
|
|||||||
def max_ratio(string:str,term):
|
def max_ratio(string:str,term):
|
||||||
"""applies ratio on each word of string and returns the max value"""
|
"""applies ratio on each word of string and returns the max value"""
|
||||||
words=string.split()
|
words=string.split()
|
||||||
return max([ratio(word.strip(":"),term) for word in words])
|
return max([ratio(word.strip(":"),term) if len(word.strip(":")) > 3 else 0 for word in words]) # ignore words of len < 3#do not compare words of len < 3 -> too generic
|
||||||
|
|
||||||
class Category:
|
class Category:
|
||||||
name = None
|
name = None
|
||||||
|
Loading…
Reference in New Issue
Block a user