FEATURE: Sort hashtags starting with term higher priority (#19463)

This introduces another "section" of queries to the
hashtag autocomplete search, which returns results for
each type that start with the search term. So now results
will be in this order, and within these sections ordered
by the types in priority order:

1. Exact matches sorted by type
2. "starts with" sorted by type
3. Everything else sorted by type then name within type
This commit is contained in:
Martin Brennan
2022-12-15 13:01:44 +10:00
committed by GitHub
parent 2b4009c6bc
commit ec9ec1e04e
9 changed files with 289 additions and 134 deletions

View File

@ -183,4 +183,22 @@ RSpec.describe Chat::ChatChannelHashtagDataSource do
expect(described_class.search_without_term(Guardian.new(user), 10)).to be_empty
end
end
describe "#search_sort" do
it "orders by exact slug match, starts with, then text" do
results_to_sort = [
HashtagAutocompleteService::HashtagItem.new(
text: "System Tests",
slug: "system-test-development",
),
HashtagAutocompleteService::HashtagItem.new(text: "Ruby Dev", slug: "ruby-dev"),
HashtagAutocompleteService::HashtagItem.new(text: "Dev", slug: "dev"),
HashtagAutocompleteService::HashtagItem.new(text: "Dev Tools", slug: "dev-tools"),
HashtagAutocompleteService::HashtagItem.new(text: "Dev Lore", slug: "dev-lore"),
]
expect(described_class.search_sort(results_to_sort, "dev").map(&:slug)).to eq(
%w[dev dev-lore dev-tools ruby-dev system-test-development],
)
end
end
end