From b71953fd1b8e07a81b93ac7fa95edf3b73439a92 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Mon, 17 Jun 2024 21:06:28 +0200 Subject: [PATCH] Improve search results add new dependency: unidecode --- partitioncloud/modules/search.py | 13 +++++++------ requirements.txt | 3 ++- scripts/hooks/v1.py | 9 ++++++++- scripts/migration.py | 1 + 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/partitioncloud/modules/search.py b/partitioncloud/modules/search.py index e28891a..75fafff 100644 --- a/partitioncloud/modules/search.py +++ b/partitioncloud/modules/search.py @@ -10,6 +10,7 @@ import os import pypdf import googlesearch +from unidecode import unidecode 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 """ - query_words = [word.lower() for word in query.split(" ")] + query_words = [word.lower() for word in unidecode(query).split()] def score_attribution(partition): score = 0 for word in query_words: if word != "": - if word in partition["name"].lower(): + if word in unidecode(partition["name"]).lower(): score += 6 - elif word in partition["author"].lower(): + elif word in unidecode(partition["author"]).lower(): score += 4 - elif word in partition["body"].lower(): + elif word in unidecode(partition["body"]).lower(): score += 2 else: - score -= 1 - for word in partition["name"].split(" "): + score -= 6 + for word in unidecode(partition["name"]).split(): if word != "" and word.lower() not in query_words: score -= 1 return score diff --git a/requirements.txt b/requirements.txt index 0fd1cf3..38168b4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ flask-babel google colorama pypdf -qrcode \ No newline at end of file +qrcode +unidecode \ No newline at end of file diff --git a/scripts/hooks/v1.py b/scripts/hooks/v1.py index 995bf78..b16f957 100644 --- a/scripts/hooks/v1.py +++ b/scripts/hooks/v1.py @@ -187,4 +187,11 @@ def install_babel(): """ def install_pypdf(): - utils.install_package("pypdf") \ No newline at end of file + utils.install_package("pypdf") + +""" + v1.10.* +""" + +def install_unidecode(): + utils.install_package("unidecode") \ No newline at end of file diff --git a/scripts/migration.py b/scripts/migration.py index c848aee..c44119e 100644 --- a/scripts/migration.py +++ b/scripts/migration.py @@ -37,6 +37,7 @@ hooks = [ ("v1.5.1", [("Move thumbnails", v1_hooks.move_thumbnails)]), ("v1.7.0", [("Install babel", v1_hooks.install_babel)]), ("v1.8.2", [("Install pypdf", v1_hooks.install_pypdf)]) + ("v1.10.3", [("Install unidecode", v1_hooks.install_unidecode)]) ]