Skip to content

Commit 31e45ba

Browse files
committed
Add case-sensitivity component to name prioritization
1 parent a8e1137 commit 31e45ba

File tree

1 file changed

+4
-2
lines changed
  • src/Share/Postgres/Search/DefinitionSearch

1 file changed

+4
-2
lines changed

src/Share/Postgres/Search/DefinitionSearch/Queries.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,10 @@ defNameCompletionSearch mayCaller mayFilter (Query query) limit = do
303303
SELECT br.project_id, br.release_id, br.name, br.tag
304304
FROM best_results br
305305
-- docs and tests to the bottom, but otherwise sort by the quality of the match.
306-
-- e.g. for query 'List', 'data.List' should come before 'data.List.map'
306+
-- e.g. for query 'List', 'data.List' should come before 'data.List.map', and
307+
-- we should prioritize the correct case, e.g. 'Text' should match 'Text' before 'text'.
307308
ORDER BY br.tag <> 'doc'::definition_tag DESC, br.tag <> 'test'::definition_tag DESC,
309+
br.name LIKE ('%' || #{query} || '%') DESC,
308310
length(br.name) - position(LOWER(#{query}) in LOWER(br.name)) ASC
309311
|]
310312
-- Names are stored in absolute form, but we usually work with them in relative form.
@@ -385,7 +387,7 @@ definitionNameSearch mayCaller mayFilter limit (Query query) = do
385387
-- - whether it contains the exact provided spelling
386388
-- - how close the query is to the END of the name (generally we want to match the last segment)
387389
-- - similarity, just in case the query is a bit off
388-
ORDER BY m.name ILIKE ('%.' || #{query} || '%') DESC, length(m.name) - position(LOWER(#{query}) in LOWER(m.name)) ASC, word_similarity(#{query}, m.name) DESC
390+
ORDER BY m.name LIKE ('%' || #{query} || '%') DESC, length(m.name) - position(LOWER(#{query}) in LOWER(m.name)) ASC, word_similarity(#{query}, m.name) DESC
389391
LIMIT #{limit}
390392
|]
391393
rows

0 commit comments

Comments
 (0)