Also use the body of the post when looking for similar topics

This commit is contained in:
Robin Ward 2014-04-14 15:48:58 -04:00
parent 0d238db43c
commit b909e26fa4

View file

@ -319,11 +319,12 @@ class Topic < ActiveRecord::Base
return [] unless raw.present? return [] unless raw.present?
# For now, we only match on title. We'll probably add body later on, hence the API hook # For now, we only match on title. We'll probably add body later on, hence the API hook
similar = Topic.select(sanitize_sql_array(["topics.*, similarity(topics.title, :title) AS similarity", title: title])) similar = Topic.select(sanitize_sql_array(["topics.*, similarity(topics.title, :title) + similarity(p.raw, :raw) AS similarity", title: title, raw: raw]))
.visible .visible
.where(closed: false, archived: false) .where(closed: false, archived: false)
.secured(Guardian.new(user)) .secured(Guardian.new(user))
.listable_topics .listable_topics
.joins("LEFT OUTER JOIN posts AS p ON p.topic_id = topics.id AND p.post_number = 1")
.limit(SiteSetting.max_similar_results) .limit(SiteSetting.max_similar_results)
.order('similarity desc') .order('similarity desc')