Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add more like this to topic

  • Loading branch information...
commit ad4201b7b8faa63be5283af10b2da324a4debf51 1 parent 6c3ccfc
@quake quake authored
View
10 app/cells/topics/sidebar_for_more_like_this.html.erb
@@ -0,0 +1,10 @@
+<% if @topics.present? %>
+<div class="nodes box clearfix">
+ <h2><%= t("topics.more_like_this") %></h2>
+ <ul>
+ <% for topic in @topics do %>
+ <li><%= link_to(truncate(topic.title, :length => 20), topic_path(topic), :title => topic.title) %></li>
+ <% end %>
+ </ul>
+</div>
+<% end %>
View
14 app/cells/topics_cell.rb
@@ -39,7 +39,19 @@ def sidebar_for_new_topic_node(args)
@action = args[:action]
render
end
-
+
+ # 相关类似话题, 取相关词出现最少3次,相关度最高的3篇
+ cache :sidebar_for_more_like_this, :expires_in => 1.day do |cell, args|
+ args[:topic].id
+ end
+ def sidebar_for_more_like_this(args)
+ @topics = args[:topic].more_like_this do
+ minimum_term_frequency 3
+ paginate :page => 1, :per_page => 3
+ end.results
+ render
+ end
+
def reply_help_block(opts = {})
@full = opts[:full] || false
render
View
6 app/models/topic.rb
@@ -38,9 +38,9 @@ class Topic
counter :hits, :default => 0
searchable do
- text :title, :stored => true
- text :body, :stored => true
- text :replies, :stored => true do
+ text :title, :stored => true, :more_like_this => true
+ text :body, :stored => true, :more_like_this => true
+ text :replies, :stored => true, :more_like_this => true do
replies.map { |reply| reply.body }
end
integer :node_id, :user_id
View
1  app/views/topics/show.html.erb
@@ -8,6 +8,7 @@
<% end %>
<div class="sidebar">
<%= render_cell :topics, :sidebar_for_new_topic_node, { :action => params[:action], :node => @node } %>
+ <%= render_cell :topics, :sidebar_for_more_like_this, { :topic => @topic} %>
</div>
<div class="content">
View
3  config/locales/topics.zh-CN.yml
@@ -21,4 +21,5 @@
add_image: "上传图片"
topic_was_deleted: "[该主题已被删除]"
have_no_new_reply: "在你读过以后还没有新变化"
- has_new_replies: "有新内容"
+ has_new_replies: "有新内容"
+ more_like_this: "相关贴子"
View
1  config/locales/topics.zh-TW.yml
@@ -22,3 +22,4 @@
topic_was_deleted: "[該主題已被刪除]"
have_no_new_reply: "在你讀過以後還沒有新回應"
has_new_replies: "有新內容"
+ more_like_this: "相關話題"
View
1  solr/conf/solrconfig.xml
@@ -610,6 +610,7 @@
</lst>
-->
</searchComponent>
+ <searchComponent name="mlt" class="org.apache.solr.handler.component.MoreLikeThisComponent" />
<!-- A request handler utilizing the spellcheck component.
#############################################################################
NOTE: This is purely as an example. The whole purpose of the
Please sign in to comment.
Something went wrong with that request. Please try again.