File: search.rb

package info (click to toggle)
aswiki 1.0.4-7
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 348 kB
  • ctags: 302
  • sloc: ruby: 2,189; makefile: 63; xml: 16; sh: 12
file content (36 lines) | stat: -rw-r--r-- 812 bytes parent folder | download | duplicates (4)
1
2
3
4
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
# Copyritght (c) 2003 TANIGUCHI Takaki
# This program is distributed under the GNU GPL 2 or later.

require 'aswiki/plugin'

module AsWiki
  # mknmz -U -t text/plain -a -k -L ja ../text
  class SearchPlugin < Plugin
    Name = 'search'
    include I18N
    include Util
    def onview(line, b, e, av=[])
      require 'search/namazu'
      word = ''
      if av[1..-1].empty?
	word = CGI.new.value('word')[0]
      else
	word = av.join(' ')
      end
      url = []
      if word
	res = Search::Namazu::search(word, 'namazu')
	url = res.result.sort{|a,b| a.rank <=> b.rank}.collect{|r|
	  page = CGI::unescape(File.basename(r.fields['uri']))
	  {:page => page, :url => cgiurl([],page)}
	}
      end
      @data = {
	:word   => word,
	:result => url,
      }
      load_parts	
      return self
    end
  end
end