Use the same component for similar topics as search results.

This commit is contained in:
Robin Ward
2015-06-24 15:08:22 -04:00
parent b4960d48b4
commit 6422d5efbd
14 changed files with 162 additions and 103 deletions

View File

@ -149,19 +149,6 @@ class TopicsController < ApplicationController
success ? render_serialized(topic, BasicTopicSerializer) : render_json_error(topic)
end
def similar_to
params.require(:title)
params.require(:raw)
title, raw = params[:title], params[:raw]
[:title, :raw].each { |key| check_length_of(key, params[key]) }
# Only suggest similar topics if the site has a minimum amount of topics present.
return render json: [] unless Topic.count_exceeds_minimum?
topics = Topic.similar_to(title, raw, current_user).to_a
render_serialized(topics, TopicListItemSerializer, root: :topics)
end
def feature_stats
params.require(:category_id)
category_id = params[:category_id].to_i
@ -510,11 +497,6 @@ class TopicsController < ApplicationController
topic.move_posts(current_user, post_ids_including_replies, args)
end
def check_length_of(key, attr)
str = (key == :raw) ? "body" : key.to_s
invalid_param(key) if attr.length < SiteSetting.send("min_#{str}_similar_length")
end
def check_for_status_presence(key, attr)
invalid_param(key) unless %w(pinned pinned_globally visible closed archived).include?(attr)
end