Skip to content

Commit

Permalink
add more like this to topic
Browse files Browse the repository at this point in the history
  • Loading branch information
quake committed Feb 3, 2012
1 parent 6c3ccfc commit ad4201b
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 5 deletions.
10 changes: 10 additions & 0 deletions app/cells/topics/sidebar_for_more_like_this.html.erb
Original file line number Diff line number Diff line change
@@ -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 %>
14 changes: 13 additions & 1 deletion app/cells/topics_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/models/topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/views/topics/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
3 changes: 2 additions & 1 deletion config/locales/topics.zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
add_image: "上传图片"
topic_was_deleted: "[该主题已被删除]"
have_no_new_reply: "在你读过以后还没有新变化"
has_new_replies: "有新内容"
has_new_replies: "有新内容"
more_like_this: "相关贴子"
1 change: 1 addition & 0 deletions config/locales/topics.zh-TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
topic_was_deleted: "[該主題已被刪除]"
have_no_new_reply: "在你讀過以後還沒有新回應"
has_new_replies: "有新內容"
more_like_this: "相關話題"
1 change: 1 addition & 0 deletions solr/conf/solrconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ad4201b

Please sign in to comment.