Skip to content

Commit

Permalink
Use operator version of word_similarity because the function version …
Browse files Browse the repository at this point in the history
…doesn't use the index
  • Loading branch information
ChrisPenner committed Jul 30, 2024
1 parent 2265dea commit 4adb453
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Share/Postgres/Search/DefinitionSearch/Queries.hs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ defNameCompletionSearch mayCaller mayFilter (Query query) limit = do
SELECT br.project_id, br.release_id, br.name, br.tag
FROM best_results br
-- docs and tests to the bottom, but otherwise sort by the quality of the match.
-- e.g. for query 'List', 'data.List' should come before 'data.List.map', and
-- e.g. for query 'List', 'data.List' should come before 'data.List.map', and
-- we should prioritize the correct case, e.g. 'Text' should match 'Text' before 'text'.
ORDER BY br.tag <> 'doc'::definition_tag DESC, br.tag <> 'test'::definition_tag DESC,
br.name LIKE ('%' || #{query} || '%') DESC,
Expand Down Expand Up @@ -376,8 +376,8 @@ definitionNameSearch mayCaller mayFilter limit (Query query) = do
JOIN projects p ON p.id = doc.project_id
JOIN project_releases r ON r.id = doc.release_id
WHERE
-- Adjust the similarity threshold as needed (between 0 and 1)
word_similarity(#{query}, doc.name) >= 0.5
-- We may wish to adjust the similarity threshold before the query.
#{query} <% doc.name
AND (NOT p.private OR (#{mayCaller} IS NOT NULL AND EXISTS (SELECT FROM accessible_private_projects pp WHERE pp.user_id = #{mayCaller} AND pp.project_id = p.id)))
^{filters}
ORDER BY doc.project_id, doc.name, r.major_version, r.minor_version, r.patch_version
Expand Down

0 comments on commit 4adb453

Please sign in to comment.