Class: Admin::ContentController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/admin/content_controller.rb

Instance Method Summary collapse

Instance Method Details

#analyseObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/admin/content_controller.rb', line 40

def analyse
  @page = Page.where(:id=>params[:id]).sys(_sid).first
  
  content = ''
  @page.current_content.each { |cc| content += ' ' + cc.value }
  
  content.gsub!(/<[^<>]*>/, "") 
  @wordcount = content.split(' ').size
  @sentencecount = content.split('.').size

  @histogram = Word.histogram(content, {:stem=>true, :de_stem=>true, :threshold=>1})
end

#matchObject



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