Skip to content

Project search fixups #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/Share/Postgres/Queries.hs
Original file line number Diff line number Diff line change
@@ -170,10 +170,22 @@ searchProjects caller userIdFilter (Query query) limit = do
SELECT p.id, p.owner_user_id, p.slug, p.summary, p.tags, p.private, p.created_at, p.updated_at, owner.handle
FROM to_tsquery('english', #{queryToken}) AS tokenquery, projects AS p
JOIN users AS owner ON p.owner_user_id = owner.id
WHERE (tokenquery @@ p.project_text_document OR p.slug ILIKE (like_escape(#{query}) || '%'))
WHERE (tokenquery @@ p.project_text_document OR p.slug ILIKE ('%' || like_escape(#{query}) || '%'))
AND (NOT p.private OR (#{caller} IS NOT NULL AND EXISTS (SELECT FROM accessible_private_projects WHERE user_id = #{caller} AND project_id = p.id)))
AND (#{userIdFilter} IS NULL OR p.owner_user_id = #{userIdFilter})
ORDER BY ts_rank_cd(p.project_text_document, tokenquery) DESC, p.slug ASC
ORDER BY
p.slug = #{query} DESC,
-- Prefer prefix matches
p.slug ILIKE (like_escape(#{query}) || '%') DESC,
-- Otherwise infix matches
p.slug ILIKE ('%' || like_escape(#{query}) || '%') DESC,
-- Prefer projects in the unison org
COALESCE(FALSE, p.owner_user_id = (SELECT unison.id FROM users unison WHERE unison.handle = 'unison')) DESC,
-- Prefer projects in the catalog
EXISTS(SELECT FROM project_categories pc WHERE pc.project_id = p.id) DESC,
ts_rank_cd(p.project_text_document, tokenquery) DESC,
-- Lastly sort by name, just so results are deterministic
p.slug ASC
LIMIT #{limit}
|]
pure (results <&> \(project PG.:. PG.Only handle) -> (project, handle))
2 changes: 1 addition & 1 deletion transcripts/share-apis/code-browse/run.zsh
Original file line number Diff line number Diff line change
@@ -19,6 +19,6 @@ fetch "$transcripts_user" GET codebase-definition-by-hash-constructor "/users/tr
fetch "$transcripts_user" GET codebase-find "/users/transcripts/projects/code-browse/branches/main/find?query=oranges.tw"
fetch "$transcripts_user" GET codebase-namespace-by-name "/users/transcripts/projects/code-browse/branches/main/namespaces/by-name/names"
fetch "$transcripts_user" GET codebase-namespace-by-name-root "/users/transcripts/projects/code-browse/branches/main/namespaces/by-name/"
fetch "$transcripts_user" GET search "/search?query=te"
fetch "$transcripts_user" GET search "/search?query=tes"
fetch "$transcripts_user" GET account "/account"
fetch "$transcripts_user" GET user-info "/user-info"
15 changes: 15 additions & 0 deletions transcripts/share-apis/search/omni-search-projects.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"body": [
{
"projectRef": "@transcripts/search",
"summary": null,
"tag": "project",
"visibility": "private"
}
],
"status": [
{
"status_code": 200
}
]
}
2 changes: 2 additions & 0 deletions transcripts/share-apis/search/run.zsh
Original file line number Diff line number Diff line change
@@ -93,3 +93,5 @@ fetch "$transcripts_user" GET 'omni-search-orgs' '/search?query=%40uni'

# Omni search should find regular users
fetch "$transcripts_user" GET 'omni-search-users' '/search?query=%40tes'
# Omni search should find projects by infix
fetch "$transcripts_user" GET 'omni-search-projects' '/search?query=%40ear'