From ab59eef2d5ef3effc9be3f1e5f987a40d22b33c9 Mon Sep 17 00:00:00 2001 From: Rayhan Hassou Date: Wed, 6 Dec 2023 10:14:18 +0100 Subject: [PATCH] upgrade filter function --- API-Project/src/gateways/ingredients.gateway.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/API-Project/src/gateways/ingredients.gateway.ts b/API-Project/src/gateways/ingredients.gateway.ts index cd476cf..caaa347 100644 --- a/API-Project/src/gateways/ingredients.gateway.ts +++ b/API-Project/src/gateways/ingredients.gateway.ts @@ -100,9 +100,16 @@ export class IngredientsGateway { const client = await this.connection.getPoolClient() const query = { - text: 'SELECT * FROM Ingredients WHERE LOWER(name) LIKE $1 ORDER BY name', - values: [`%${prompt.toLowerCase()}%`], + text: ` + CREATE EXTENSION IF NOT EXISTS pg_trgm; -- Vérifie si l'extension est déjà installée, sinon l'installe + SELECT * + FROM Ingredients + WHERE LOWER(name) LIKE $1 + ORDER BY similarity(name, $2) DESC, name ASC; + `, + values: [`%${prompt.toLowerCase()}%`, prompt.toLowerCase()], }; + const res = await client.query(query);