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

Incorrect search ranking #250

Closed
abstractionfactory opened this issue Nov 26, 2024 · 6 comments · Fixed by #248
Closed

Incorrect search ranking #250

abstractionfactory opened this issue Nov 26, 2024 · 6 comments · Fixed by #248
Assignees
Labels
bug Something isn't working

Comments

@abstractionfactory
Copy link
Contributor

The current search ranking is less than optimal and should be improved.

@abstractionfactory abstractionfactory added the bug Something isn't working label Nov 26, 2024
@cam72cam
Copy link
Member

WITH search_terms AS (
  SELECT unnest(regexp_split_to_array('vsphere', '[ /]+')) AS term
),
term_matches AS (
  SELECT e.*
  FROM entities e
  INNER JOIN search_terms st
    ON e.addr ILIKE '%' || st.term || '%'
    OR e.description ILIKE '%' || st.term || '%'
  GROUP BY e.id
),
ranked_entities AS (
  SELECT *,
    CASE WHEN link_variables->>'namespace' = 'hashicorp' THEN 1 WHEN link_variables->>'namespace' = 'opentofu' THEN 0 ELSE 0.5 END as popularity_fudge,
    similarity(tm.addr, 'vsphere') as title_sim,
    similarity(tm.description, 'vsphere') as description_sim,
    similarity(link_variables->>'name', 'vsphere') as name_sim
  FROM term_matches tm
),
providers AS (
  SELECT *
  FROM ranked_entities
  WHERE type LIKE 'provider%'
  ORDER BY
    popularity_fudge DESC,
    title_sim DESC,
    name_sim DESC,
    description_sim DESC
  LIMIT 10
),
modules AS (
  SELECT *
  FROM ranked_entities
  WHERE type LIKE 'module%'
  ORDER BY
    popularity_fudge DESC,
    title_sim DESC,
    name_sim DESC,
    description_sim DESC
  LIMIT 10
)
select * from providers
UNION ALL
select * from modules;

@abstractionfactory
Copy link
Contributor Author

Thanks @cam72cam with some tweaks this partially fixed it, still need to add the popularity ranking later.

@abstractionfactory abstractionfactory linked a pull request Dec 2, 2024 that will close this issue
4 tasks
@diofeher
Copy link
Member

@cam72cam I think we can close this issue since the popularity ranking is implemented here https://github.com/opentofu/registry-ui/blob/main/search/worker/src/query.ts#L22

Feel free to reopen if there's something I've missed.

@diofeher
Copy link
Member

I'm reopening since I just tested with cloudflare and cloudflare/cloudflare appears as the third result instead of being the first one:

Image

@diofeher diofeher reopened this Feb 25, 2025
@diofeher
Copy link
Member

diofeher commented Feb 25, 2025

It seems the rank is right locally, production code is not up to date. I'll leave this ticket open until we deploy it there.

Image

@diofeher diofeher self-assigned this Feb 25, 2025
@diofeher
Copy link
Member

Fixed with 50e7c1b and deployed. Closing the ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants