5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/controllers/admin/content_controller.rb', line 5
def match
@page = Page.where(:id=>params[:id]).sys(_sid).first
if params[:words]
words = params[:words]
else
content = ''
@page.current_content.each { |cc| content += ' ' + cc.value }
content.gsub!(/<[^<>]*>/, "")
@histogram = Word.histogram(content, {:stem=>true, :de_stem=>true, :threshold=>1})
words = []
@histogram.each do |k,v|
words << k
break if words.size>10
end
if words.size==0
render :text=>"You must create and save some content before you can see related content." and return
end
end
indexes = [ "pages", "topic_posts", "topic_threads" ]
system_id = _sid
search = Tire.search indexes.map { |name| "#{index_name}_#{name}"}.join(',') do
query do
string words.join(' ')
end
size 10
filter :term, :system_id=>system_id
end
@pages = search.results
render :layout=>false
end
|