Skip to content

Commit a8e1137

Browse files
committed
Improve sorting of name-based search results
1 parent 1ae58eb commit a8e1137

File tree

1 file changed

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

1 file changed

+5
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,11 @@ definitionNameSearch mayCaller mayFilter limit (Query query) = do
381381
ORDER BY doc.project_id, doc.name, r.major_version, r.minor_version, r.patch_version
382382
) SELECT m.project_id, m.release_id, m.name, m.metadata
383383
FROM matches_deduped_by_project m
384-
-- Score matches by name similarity
385-
ORDER BY word_similarity(#{query}, m.name) DESC
384+
-- Score matches by:
385+
-- - whether it contains the exact provided spelling
386+
-- - how close the query is to the END of the name (generally we want to match the last segment)
387+
-- - 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
386389
LIMIT #{limit}
387390
|]
388391
rows

0 commit comments

Comments
 (0)