Skip to content
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

Fixing worker query to include popularity #263

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
5 changes: 3 additions & 2 deletions search/worker/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ const searchQuery = `
ON e.addr ILIKE '%' || st.term || '%'
OR e.description ILIKE '%' || st.term || '%'
GROUP BY id, last_updated, type, addr, version, title, description, link_variables, document, popularity, warnings),
max_popularity AS (SELECT max(popularity) AS max_popularity FROM term_matches tm),
ranked_entities AS (SELECT *,
/* The provider rank fudge ranks providers higher than their resources */
CASE WHEN type = 'provider' THEN 1 ELSE 0 END AS provider_rank_fudge,
/* When warnings are present, rank the provider lower because it's likely deprecated. */
CASE WHEN warnings > 0 THEN -1 ELSE 0 END AS warnings_rank_fudge,
/* Give a slight boost to providers with a higher star rating. */
tm.popularity / (SELECT max(popularity) FROM tm) AS popularity_rank,
tm.popularity / (SELECT CASE WHEN max_popularity > 0 THEN max_popularity ELSE 1 END FROM max_popularity) AS popularity_rank,
/* Text similarity rankings, each taking a value from 0 to 1. */
similarity(tm.addr, $1) AS title_sim,
similarity(tm.description, $1) AS description_sim,
similarity(link_variables ->> 'name', $1) AS name_sim,
similarity(link_variables ->> 'name', $1) AS name_sim
FROM term_matches tm),
providers AS (SELECT *
FROM ranked_entities
Expand Down
Loading