Skip to content

Add relevance sort for labels search

Nick Leonard requested to merge nl-label-similarity into master

What does this MR do and why?

When searching for Labels in /-/labels, sorts labels by search relevance by default to ensure relevant results are easy to find if many results are returned.

Relevance sort is added only when search is applied. Users can still change sorting after searching.

This MR:

  • Adds similarity scope to Label
  • Adds use of similarity scope to LabelsFinder
  • Uses the similarity sort on /-/labels when sort is Relevance
SQL
SELECT
    "labels".*,
    ROUND(CAST((( SIMILARITY (COALESCE("labels"."title", ''), 'UX') * CAST('1' AS numeric)) + (/* gitlab/database/similarity_score */ SIMILARITY(COALESCE("labels"."description", ''), 'UX') * CAST('0.2' AS numeric))) AS numeric), 2) AS similarity
FROM
    "labels"
WHERE
    "labels"."type" = 'GroupLabel'
    AND "labels"."group_id" = 9970
ORDER BY
    ROUND(CAST((( SIMILARITY (COALESCE("labels"."title", ''), 'UX') * CAST('1' AS numeric)) + (/* gitlab/database/similarity_score */ SIMILARITY(COALESCE("labels"."description", ''), 'UX') * CAST('0.2' AS numeric))) AS numeric), 2) DESC,
    "labels"."id" DESC;

"Similarity" vs. "Relevance"

"Similarity" is used in the method name, to match other instances, while "Relevance" is the user-facing terminology. "Relevance" is a better UI label as it may be unclear what "similarity" means (similar to what?); "Relevance" is commonly associated with search in web apps.

Closes #443244

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After Pagination
Screenshot_2024-02-26_at_9.35.25_AM Screenshot_2024-02-26_at_9.32.00_AM paginate

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Enable the label_similarity_sort FF in a group or project, e.g. Feature.enable(:label_similarity_sort, Project.find(7))
  2. Open /-/labels in a group or project (Manage > Labels)
  3. Create a few labels using the same keyword, considering title use, description use, case, etc
  4. Search using your keyword, verifying that exact matches are first. Description matches are typically last, though an exact match in a description will be ahead of an inexact match in the title.
Edited by Nick Leonard

Merge request reports