mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 01:41:25 +08:00
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:
@ -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
|
||||
|
Reference in New Issue
Block a user