4 homedir = '/users/stian/source/zip-doc'
5 require File.join(homedir, 'zarchive')
6 require File.join(homedir, 'htmlshrinker')
9 archive = ZArchive.new(ARGV[0])
10 htmlshrink = HTMLShrinker.new("/id")
11 class SimpleHandler < Mongrel::HttpHandler
12 def process(req, resp)
16 txt = archive.get_article(req.unparsed_uri[3..-1])
18 out.write = "Sorry, article not found"
20 out.write = htmlshrink.uncompress(txt)
22 puts "Served in #{Time.now - t} seconds."
26 search_proc = lambda do |req, resp|
28 resp['Content-Type'] = "text/html"
29 search_query =req.unparsed_uri[("search".size+2)..-1]
30 puts search_queryearch_query
32 FERRET.search_each(search_query) do |docid, score|
33 @found_documents << {:path => FERRET.reader.get_document(docid)[:filename],
34 :score => score, :highlight => FERRET.highlight(search_query,
35 docid, :pre_tag => '<b>', :post_tag => '</b>',
39 unless @found_documents.empty?
40 resp.body << "<h1>Search results for query <i>#{search_query}</i></h1>"
41 @found_documents.each do |doc|
42 resp.body << "<li><a href=/d/#{doc[:path]}>#{doc[:path]}</a><br>#{doc[:highlight]}<br><hr>"
45 resp.body << "Sorry, no documents found"
47 puts "Served in #{Time.now - t} seconds."
50 h = Mongrel::HttpServer.new("0.0.0.0", "3000")
51 h.register("/", SimpleHandler.new)
52 h.register("/files", Mongrel::DirHandler.new("."))