application des alias à la recherche protondb

This commit is contained in:
Kepka Ludovic
2025-08-22 08:58:01 +02:00
parent 9929e88174
commit 978d8f0701
2 changed files with 10 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import re
from algoliasearch.search.client import SearchClientSync, SearchConfig from algoliasearch.search.client import SearchClientSync, SearchConfig
from database.helpers import ConfigurationHelper from database.helpers import ConfigurationHelper
from database.models import GameAlias
def _call_algoliasearch(search_name:str): def _call_algoliasearch(search_name:str):
config = SearchConfig(ConfigurationHelper().getValue('proton_db_api_id'), config = SearchConfig(ConfigurationHelper().getValue('proton_db_api_id'),
@@ -30,8 +31,14 @@ def _is_name_match(name:str, search_name:str) -> bool:
normalized_search_name = re.sub("[^a-z0-9]", "", search_name.lower()) normalized_search_name = re.sub("[^a-z0-9]", "", search_name.lower())
return normalized_game_name.find(normalized_search_name.lower()) >= 0 return normalized_game_name.find(normalized_search_name.lower()) >= 0
def _apply_game_aliases(search_name:str) -> str:
for alias in GameAlias.query.all():
search_name = search_name.replace(alias.alias, alias.name)
return search_name
def searhProtonDb(search_name:str): def searhProtonDb(search_name:str):
results = [] results = []
search_name = _apply_game_aliases(search_name)
responses = _call_algoliasearch(search_name) responses = _call_algoliasearch(search_name)
for hit in responses.model_dump().get('hits'): for hit in responses.model_dump().get('hits'):
id = hit.get('object_id') id = hit.get('object_id')

View File

@@ -31,8 +31,9 @@
<label for="name">Nom</label> <label for="name">Nom</label>
<input name="name" type="text" maxlength="256" required="required" /> <input name="name" type="text" maxlength="256" required="required" />
<input type="Submit" value="Ajouter"> <input type="Submit" value="Ajouter">
<p>Si vous créer un *game alias* **GTA > Grand Theft Auto** alors si un utilisateur rentre la commande **!protondb <p>Si vous créer un alias <strong>GTA : Grand Theft Auto</strong> alors si un utilisateur rentre la commande
GTA 5** cela fera une recherche sur **Grand Theft Auto 5**.</p> <strong>!protondb GTA 5</strong> cela fera une recherche sur <strong>Grand Theft Auto 5</strong>.
</p>
</form> </form>
<h2>Configuration</h2> <h2>Configuration</h2>