mirror of
https://github.com/discourse/discourse.git
synced 2025-01-31 06:28:31 +08:00
New site setting: minimum_topics_similar
, allows you to specify a minimum amount
of topics that need to be in the database before it will suggest similar topics as a user creates a post.
This commit is contained in:
parent
00666a596f
commit
5ef6714d48
|
@ -84,7 +84,11 @@ class TopicsController < ApplicationController
|
||||||
raise Discourse::InvalidParameters.new(:title) if title.length < SiteSetting.min_title_similar_length
|
raise Discourse::InvalidParameters.new(:title) if title.length < SiteSetting.min_title_similar_length
|
||||||
raise Discourse::InvalidParameters.new(:raw) if raw.length < SiteSetting.min_body_similar_length
|
raise Discourse::InvalidParameters.new(:raw) if raw.length < SiteSetting.min_body_similar_length
|
||||||
|
|
||||||
|
# Only suggest similar topics if the site has a minimmum amount of topics present.
|
||||||
|
if Topic.count > SiteSetting.minimum_topics_similar
|
||||||
topics = Topic.similar_to(title, raw, current_user)
|
topics = Topic.similar_to(title, raw, current_user)
|
||||||
|
end
|
||||||
|
|
||||||
render_serialized(topics, BasicTopicSerializer)
|
render_serialized(topics, BasicTopicSerializer)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -222,6 +222,8 @@ class SiteSetting < ActiveRecord::Base
|
||||||
client_setting(:topic_views_heat_medium, 2000)
|
client_setting(:topic_views_heat_medium, 2000)
|
||||||
client_setting(:topic_views_heat_high, 5000)
|
client_setting(:topic_views_heat_high, 5000)
|
||||||
|
|
||||||
|
setting(:minimum_topics_similar, 50)
|
||||||
|
|
||||||
def self.generate_api_key!
|
def self.generate_api_key!
|
||||||
self.api_key = SecureRandom.hex(32)
|
self.api_key = SecureRandom.hex(32)
|
||||||
end
|
end
|
||||||
|
|
|
@ -383,7 +383,7 @@ en:
|
||||||
memory_warning: 'Your server is running with less than 1 GB of total memory. At least 1 GB of memory is recommended.'
|
memory_warning: 'Your server is running with less than 1 GB of total memory. At least 1 GB of memory is recommended.'
|
||||||
facebook_config_warning: 'The server is configured to allow signup and log in with Facebook (enable_facebook_logins), but the app id and app secret values are not set. Go to <a href="/admin/site_settings">the Site Settings</a> and update the settings. <a href="https://github.com/discourse/discourse/wiki/The-Discourse-Admin-Quick-Start-Guide#enable-facebook-logins" target="_blank">See this guide to learn more</a>.'
|
facebook_config_warning: 'The server is configured to allow signup and log in with Facebook (enable_facebook_logins), but the app id and app secret values are not set. Go to <a href="/admin/site_settings">the Site Settings</a> and update the settings. <a href="https://github.com/discourse/discourse/wiki/The-Discourse-Admin-Quick-Start-Guide#enable-facebook-logins" target="_blank">See this guide to learn more</a>.'
|
||||||
cas_config_warning: 'The server is configured to allow signup and log in with CAS (enable_cas_logins), but the hostname and domain name values are not set.'
|
cas_config_warning: 'The server is configured to allow signup and log in with CAS (enable_cas_logins), but the hostname and domain name values are not set.'
|
||||||
twitter_config_warning: 'The server is configured to allow signup and log in with Twitter (enable_twitter_logins), but the key and secret values are not set. Go to <a href="/admin/site_settings">the Site Settings</a> and update the settings. <a href="https://github.com/discourse/discourse/wiki/The-Discourse-Admin-Quick-Start-Guide#enable-twitter-logins" target="_blank">See this guide to learn more</a>.'
|
twitter_config_warning: 'The server is configured to allow signup and log in with Twitter (enable_twitter_logins), but the key and secret values are not set. Go to <a href="/admin/site_site_settings">the Site Settings</a> and update the settings. <a href="https://github.com/discourse/discourse/wiki/The-Discourse-Admin-Quick-Start-Guide#enable-twitter-logins" target="_blank">See this guide to learn more</a>.'
|
||||||
github_config_warning: 'The server is configured to allow signup and log in with GitHub (enable_github_logins), but the client id and secret values are not set. Go to <a href="/admin/site_settings">the Site Settings</a> and update the settings. <a href="https://github.com/discourse/discourse/wiki/The-Discourse-Admin-Quick-Start-Guide" target="_blank">See this guide to learn more</a>.'
|
github_config_warning: 'The server is configured to allow signup and log in with GitHub (enable_github_logins), but the client id and secret values are not set. Go to <a href="/admin/site_settings">the Site Settings</a> and update the settings. <a href="https://github.com/discourse/discourse/wiki/The-Discourse-Admin-Quick-Start-Guide" target="_blank">See this guide to learn more</a>.'
|
||||||
failing_emails_warning: 'There are %{num_failed_jobs} email jobs that failed. Check your config/environments/production.rb file and ensure that the config.action_mailer settings are correct. <a href="/sidekiq/retries" target="_blank">See the failed jobs in Sidekiq</a>.'
|
failing_emails_warning: 'There are %{num_failed_jobs} email jobs that failed. Check your config/environments/production.rb file and ensure that the config.action_mailer settings are correct. <a href="/sidekiq/retries" target="_blank">See the failed jobs in Sidekiq</a>.'
|
||||||
default_logo_warning: "You haven't customized the logo images for your site. Update logo_url, logo_small_url, and favicon_url in the <a href='/admin/site_settings'>Site Settings</a>."
|
default_logo_warning: "You haven't customized the logo images for your site. Update logo_url, logo_small_url, and favicon_url in the <a href='/admin/site_settings'>Site Settings</a>."
|
||||||
|
@ -623,6 +623,8 @@ en:
|
||||||
pop3s_polling_username: "The username for the POP3S account to poll for email"
|
pop3s_polling_username: "The username for the POP3S account to poll for email"
|
||||||
pop3s_polling_password: "The password for the POP3S account to poll for email"
|
pop3s_polling_password: "The password for the POP3S account to poll for email"
|
||||||
|
|
||||||
|
minimum_topics_similar: "How many topics need to exist in the database before similar topics are presented."
|
||||||
|
|
||||||
|
|
||||||
notification_types:
|
notification_types:
|
||||||
mentioned: "%{display_username} mentioned you in %{link}"
|
mentioned: "%{display_username} mentioned you in %{link}"
|
||||||
|
|
|
@ -161,22 +161,44 @@ describe TopicsController do
|
||||||
-> { xhr :get, :similar_to, title: title, raw: raw }.should raise_error(Discourse::InvalidParameters)
|
-> { xhr :get, :similar_to, title: title, raw: raw }.should raise_error(Discourse::InvalidParameters)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "delegates to Topic.similar_to" do
|
describe "minimum_topics_similar" do
|
||||||
Topic.expects(:similar_to).with(title, raw, nil).returns([Fabricate(:topic)])
|
|
||||||
|
before do
|
||||||
|
SiteSetting.stubs(:minimum_topics_similar).returns(30)
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
xhr :get, :similar_to, title: title, raw: raw
|
xhr :get, :similar_to, title: title, raw: raw
|
||||||
end
|
end
|
||||||
|
|
||||||
context "logged in" do
|
describe "With enough topics" do
|
||||||
|
before do
|
||||||
|
Topic.stubs(:count).returns(50)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "deletes to Topic.similar_to if there are more topics than `minimum_topics_similar`" do
|
||||||
|
Topic.expects(:similar_to).with(title, raw, nil).returns([Fabricate(:topic)])
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "with a logged in user" do
|
||||||
let(:user) { log_in }
|
let(:user) { log_in }
|
||||||
|
|
||||||
it "passes a user throught if logged in" do
|
it "passes a user through if logged in" do
|
||||||
Topic.expects(:similar_to).with(title, raw, user).returns([Fabricate(:topic)])
|
Topic.expects(:similar_to).with(title, raw, user).returns([Fabricate(:topic)])
|
||||||
xhr :get, :similar_to, title: title, raw: raw
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "does not call Topic.similar_to if there are fewer topics than `minimum_topics_similar`" do
|
||||||
|
Topic.stubs(:count).returns(10)
|
||||||
|
Topic.expects(:similar_to).never
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
context 'clear_pin' do
|
context 'clear_pin' do
|
||||||
it 'needs you to be logged in' do
|
it 'needs you to be logged in' do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user