Suppress search in topic unless we have more than 10 posts
(configurable in site setting)
This commit is contained in:
parent
18e98851e3
commit
2a8734f0d5
|
@ -799,6 +799,7 @@ en:
|
|||
|
||||
dominating_topic_minimum_percent: "What percentage of posts a user has to make in a topic before we consider it dominating."
|
||||
suppress_uncategorized_badge: "Don't show the badge for uncategorized topics in topic lists"
|
||||
min_posts_for_search_in_topic: "Disable search within topic if topics have less than minimum number posts"
|
||||
|
||||
enable_names: "Allow users to show their full names"
|
||||
display_name_on_posts: "Also show a user's full name on their posts"
|
||||
|
|
|
@ -437,4 +437,5 @@ uncategorized:
|
|||
meta_category_id:
|
||||
default: -1
|
||||
hidden: true
|
||||
min_posts_for_search_in_topic: 10
|
||||
|
||||
|
|
|
@ -46,6 +46,10 @@ class Search
|
|||
@search_context = @opts[:search_context]
|
||||
@limit = Search.per_facet * Search.facets.size
|
||||
@results = GroupedSearchResults.new(@opts[:type_filter])
|
||||
|
||||
if Topic === @search_context && @search_context.posts_count < SiteSetting.min_posts_for_search_in_topic
|
||||
@search_context = nil
|
||||
end
|
||||
end
|
||||
|
||||
# Query a term
|
||||
|
|
|
@ -133,6 +133,9 @@ describe Search do
|
|||
end
|
||||
|
||||
it 'displays multiple results within a topic' do
|
||||
|
||||
SiteSetting.stubs(:min_posts_for_search_in_topic).returns(3)
|
||||
|
||||
topic = Fabricate(:topic)
|
||||
topic2 = Fabricate(:topic)
|
||||
|
||||
|
@ -144,6 +147,9 @@ describe Search do
|
|||
post4 = new_post('this is my fourth post I am posting', topic)
|
||||
new_post('this is my fifth post I am posting', topic2)
|
||||
|
||||
# update posts_count
|
||||
topic.reload
|
||||
|
||||
results = Search.new('posting', search_context: post1.topic).execute.find do |r|
|
||||
r[:type] == "topic"
|
||||
end[:results]
|
||||
|
@ -160,6 +166,11 @@ describe Search do
|
|||
# trigger expanded search
|
||||
results = Search.new('birds', search_context: post1.topic).execute
|
||||
|
||||
SiteSetting.stubs(:min_posts_for_search_in_topic).returns(10)
|
||||
results = Search.new('posting', search_context: post1.topic).execute.find do |r|
|
||||
r[:type] == "topic"
|
||||
end[:results].length.should == 2
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue