FEATURE: Allow categories to be prioritized/deprioritized in search. (#7209)

This commit is contained in:
Guo Xiang Tan
2019-03-25 10:59:55 +08:00
committed by GitHub
parent ce75e30bf5
commit ac661e856a
10 changed files with 129 additions and 5 deletions

View File

@ -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

View File

@ -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