Improve search results

add new dependency: unidecode
This commit is contained in:
augustin64 2024-06-17 21:06:28 +02:00
parent 9aa156a9b4
commit b71953fd1b
4 changed files with 18 additions and 8 deletions

View File

@ -10,6 +10,7 @@ import os
import pypdf import pypdf
import googlesearch import googlesearch
from unidecode import unidecode
from .db import get_db from .db import get_db
@ -20,20 +21,20 @@ def local_search(query, partitions):
""" """
Renvoie les 5 résultats les plus pertinents parmi une liste donnée Renvoie les 5 résultats les plus pertinents parmi une liste donnée
""" """
query_words = [word.lower() for word in query.split(" ")] query_words = [word.lower() for word in unidecode(query).split()]
def score_attribution(partition): def score_attribution(partition):
score = 0 score = 0
for word in query_words: for word in query_words:
if word != "": if word != "":
if word in partition["name"].lower(): if word in unidecode(partition["name"]).lower():
score += 6 score += 6
elif word in partition["author"].lower(): elif word in unidecode(partition["author"]).lower():
score += 4 score += 4
elif word in partition["body"].lower(): elif word in unidecode(partition["body"]).lower():
score += 2 score += 2
else: else:
score -= 1 score -= 6
for word in partition["name"].split(" "): for word in unidecode(partition["name"]).split():
if word != "" and word.lower() not in query_words: if word != "" and word.lower() not in query_words:
score -= 1 score -= 1
return score return score

View File

@ -3,4 +3,5 @@ flask-babel
google google
colorama colorama
pypdf pypdf
qrcode qrcode
unidecode

View File

@ -187,4 +187,11 @@ def install_babel():
""" """
def install_pypdf(): def install_pypdf():
utils.install_package("pypdf") utils.install_package("pypdf")
"""
v1.10.*
"""
def install_unidecode():
utils.install_package("unidecode")

View File

@ -37,6 +37,7 @@ hooks = [
("v1.5.1", [("Move thumbnails", v1_hooks.move_thumbnails)]), ("v1.5.1", [("Move thumbnails", v1_hooks.move_thumbnails)]),
("v1.7.0", [("Install babel", v1_hooks.install_babel)]), ("v1.7.0", [("Install babel", v1_hooks.install_babel)]),
("v1.8.2", [("Install pypdf", v1_hooks.install_pypdf)]) ("v1.8.2", [("Install pypdf", v1_hooks.install_pypdf)])
("v1.10.3", [("Install unidecode", v1_hooks.install_unidecode)])
] ]