mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 19:39:30 +08:00
FEATURE: Allow categories to be prioritized/deprioritized in search. (#7209)
This commit is contained in:
@ -486,6 +486,26 @@ describe Search do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'categories with different priorities' do
|
||||
let(:category2) { Fabricate(:category) }
|
||||
|
||||
it "should return posts in the right order" do
|
||||
raw = "The pure genuine evian"
|
||||
post = Fabricate(:post, topic: category.topic, raw: raw)
|
||||
post2 = Fabricate(:post, topic: category2.topic, raw: raw)
|
||||
|
||||
search = Search.execute(raw)
|
||||
|
||||
expect(search.posts).to eq([post2, post])
|
||||
|
||||
category.update!(search_priority: Searchable::PRIORITIES[:high])
|
||||
|
||||
search = Search.execute(raw)
|
||||
|
||||
expect(search.posts).to eq([post, post2])
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'groups' do
|
||||
|
@ -0,0 +1,26 @@
|
||||
require 'rails_helper'
|
||||
require 'validators/category_search_priority_weights_validator'
|
||||
|
||||
RSpec.describe CategorySearchPriorityWeightsValidator do
|
||||
it "should validate the results correctly" do
|
||||
expect do
|
||||
SiteSetting.category_search_priority_very_low_weight = 0.9
|
||||
end.to raise_error(Discourse::InvalidParameters)
|
||||
|
||||
[1, 0].each do |value|
|
||||
expect do
|
||||
SiteSetting.category_search_priority_low_weight = value
|
||||
end.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
['0.2', 10].each do |value|
|
||||
expect do
|
||||
SiteSetting.category_search_priority_high_weight = value
|
||||
end.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
expect do
|
||||
SiteSetting.category_search_priority_very_high_weight = 1.1
|
||||
end.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user