Skip to content

Commit

Permalink
Sort results before limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed Jul 30, 2024
1 parent 4adb453 commit 936753b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Share/Postgres/Search/DefinitionSearch/Queries.hs
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,10 @@ defNameCompletionSearch mayCaller mayFilter (Query query) limit = do
best_results(project_id, release_id, name, tag) AS (
SELECT m.project_id, m.release_id, m.name, m.tag
FROM matches_deduped_by_project m
-- Prefer matches where the query is near the end of the name,
-- Prefer matches where the original query appears (case-matched),
-- then matches where the query is near the end of the name,
-- e.g. for query 'List', 'data.List' should come before 'data.List.map'
ORDER BY length(m.name) - position(LOWER(#{query}) in LOWER(m.name)) ASC
ORDER BY m.name LIKE ('%' || #{query} || '%') DESC, length(m.name) - position(LOWER(#{query}) in LOWER(m.name)) ASC
LIMIT #{limit}
)
-- THEN sort docs to the bottom.
Expand Down

0 comments on commit 936753b

Please sign in to comment.