Suppress search in topic unless we have more than 10 posts

(configurable in site setting)
This commit is contained in:
Sam 2014-02-19 08:59:18 +11:00
parent 18e98851e3
commit 2a8734f0d5
4 changed files with 17 additions and 0 deletions

View File

@ -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." 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" 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" enable_names: "Allow users to show their full names"
display_name_on_posts: "Also show a user's full name on their posts" display_name_on_posts: "Also show a user's full name on their posts"

View File

@ -437,4 +437,5 @@ uncategorized:
meta_category_id: meta_category_id:
default: -1 default: -1
hidden: true hidden: true
min_posts_for_search_in_topic: 10

View File

@ -46,6 +46,10 @@ class Search
@search_context = @opts[:search_context] @search_context = @opts[:search_context]
@limit = Search.per_facet * Search.facets.size @limit = Search.per_facet * Search.facets.size
@results = GroupedSearchResults.new(@opts[:type_filter]) @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 end
# Query a term # Query a term

View File

@ -133,6 +133,9 @@ describe Search do
end end
it 'displays multiple results within a topic' do it 'displays multiple results within a topic' do
SiteSetting.stubs(:min_posts_for_search_in_topic).returns(3)
topic = Fabricate(:topic) topic = Fabricate(:topic)
topic2 = Fabricate(:topic) topic2 = Fabricate(:topic)
@ -144,6 +147,9 @@ describe Search do
post4 = new_post('this is my fourth post I am posting', topic) post4 = new_post('this is my fourth post I am posting', topic)
new_post('this is my fifth post I am posting', topic2) 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| results = Search.new('posting', search_context: post1.topic).execute.find do |r|
r[:type] == "topic" r[:type] == "topic"
end[:results] end[:results]
@ -160,6 +166,11 @@ describe Search do
# trigger expanded search # trigger expanded search
results = Search.new('birds', search_context: post1.topic).execute 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
end end