From ec05978d3c446fb73046ea855a099c7b65c89e40 Mon Sep 17 00:00:00 2001 From: Guillaume Hivert Date: Fri, 2 Aug 2024 00:57:57 +0200 Subject: [PATCH] fix: add primitive types to levenshtein --- apps/backend/src/backend/postgres/queries.gleam | 15 ++++++++++++++- apps/backend/src/backend/router.gleam | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/apps/backend/src/backend/postgres/queries.gleam b/apps/backend/src/backend/postgres/queries.gleam index c8a9042..d6ecf49 100644 --- a/apps/backend/src/backend/postgres/queries.gleam +++ b/apps/backend/src/backend/postgres/queries.gleam @@ -437,7 +437,20 @@ pub fn upsert_package_type_fun_signature( } pub fn find_similar_type_names(db: pgo.Connection, name: String) { - "SELECT DISTINCT ON (name) name + "SELECT * + FROM (VALUES + ('Int'), + ('Float'), + ('String'), + ('Bool'), + ('List'), + ('Nil'), + ('Result'), + ('BitArray') + ) AS t (name) + WHERE levenshtein_less_equal(name, 'Int', 2) <= 2 + UNION + SELECT DISTINCT ON (name) name FROM package_type_fun_signature WHERE (kind = 'type_definition' OR kind = 'type_alias') AND levenshtein_less_equal(name, $1, 2) <= 2" diff --git a/apps/backend/src/backend/router.gleam b/apps/backend/src/backend/router.gleam index 560e3ae..8b5b608 100644 --- a/apps/backend/src/backend/router.gleam +++ b/apps/backend/src/backend/router.gleam @@ -30,7 +30,7 @@ fn search(query: String, ctx: Context) { let exact_type_searches = option.then(ctx.type_search_subject, fn(subject) { - process.try_call(subject, type_search.Find(_, query), within: 10_000) + process.try_call(subject, type_search.Find(_, query), within: 15_000) |> option.from_result |> option.flatten })