Skip to content

Commit 936753b

Browse files
committed
Sort results before limiting
1 parent 4adb453 commit 936753b

File tree

1 file changed

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

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,10 @@ defNameCompletionSearch mayCaller mayFilter (Query query) limit = do
294294
best_results(project_id, release_id, name, tag) AS (
295295
SELECT m.project_id, m.release_id, m.name, m.tag
296296
FROM matches_deduped_by_project m
297-
-- Prefer matches where the query is near the end of the name,
297+
-- Prefer matches where the original query appears (case-matched),
298+
-- then matches where the query is near the end of the name,
298299
-- e.g. for query 'List', 'data.List' should come before 'data.List.map'
299-
ORDER BY length(m.name) - position(LOWER(#{query}) in LOWER(m.name)) ASC
300+
ORDER BY m.name LIKE ('%' || #{query} || '%') DESC, length(m.name) - position(LOWER(#{query}) in LOWER(m.name)) ASC
300301
LIMIT #{limit}
301302
)
302303
-- THEN sort docs to the bottom.

0 commit comments

Comments
 (0)