Class: Gonzui::AdvancedSearchServlet

Inherits:
GonzuiAbstractServlet show all
Defined in:
lib/gonzui/webapp/advsearch.rb

Constant Summary

Constants included from URIMaker

URIMaker::ParamTable

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GonzuiAbstractServlet

#format_html, #get_media_type, #get_mime_type, #init_servlet, #initialize, #log, #make_path, #set_content_type_text_html

Methods included from HTMLMaker

#make_content_script_type, #make_css, #make_footer, #make_format_select, #make_h1, #make_html, #make_license_select, #make_meta, #make_meta_and_css, #make_navi, #make_property_select, #make_script, #make_search_form, #make_spacer, #make_status_line, #make_title

Methods included from URIMaker

#decompose_search_query, #escape_path, #get_default_query_value, #get_query_value, #get_short_name, #make_advanced_search_uri, #make_doc_uri, #make_google_uri, #make_lineno_uri, #make_markup_uri, #make_search_uri, #make_search_uri_partial, #make_source_uri, #make_stat_uri, #make_top_uri, #make_uri_general, #make_uri_with_options

Methods included from GetText

#gettext, #gettext_noop, #load_catalog, #set_catalog

Methods included from Util

assert, assert_equal, assert_equal_all, assert_non_nil, assert_not_reached, benchmark, command_exist?, commify, eprintf, format_bytes, program_name, protect_from_signals, require_command, set_verbosity, shell_escape, unix?, vprintf, windows?, wprintf

Constructor Details

This class inherits a constructor from Gonzui::GonzuiAbstractServlet

Class Method Details

.mount_pointObject



14
15
16
# File 'lib/gonzui/webapp/advsearch.rb', line 14

def self.mount_point
  "advsearch"
end

Instance Method Details

#do_GET(request, response) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/gonzui/webapp/advsearch.rb', line 99

def do_GET(request, response)
  init_servlet(request, response)
  log()

  html = make_html
  title = make_title(_("Advanced Search"))
  head = [:head, title, *make_meta_and_css]
  body = [:body]

  h1 = make_h1
  status_line = make_status_line(_("Advanced Search"))
  content = make_advanced_search_form
  footer = make_footer
  body.push(h1, status_line, content, footer)

  html.push(head)
  html.push(body)
  set_content_type_text_html
  response.body = format_html(html)
end

#do_make_status_lineObject



18
19
20
# File 'lib/gonzui/webapp/advsearch.rb', line 18

def do_make_status_line
  []
end

#make_advanced_search_formObject



94
95
96
97
# File 'lib/gonzui/webapp/advsearch.rb', line 94

def make_advanced_search_form
  form = make_target_specific_search_form
  return [:div, {:class =>"advanced-search"}, form]
end

#make_nresults_selectObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/gonzui/webapp/advsearch.rb', line 44

def make_nresults_select
  nr = get_short_name(:nresults_per_page)
  select = [:select, {:name => nr}]
  @config.nresults_candidates.each {|n|
    o = [:option, {:type => "radio", :name => nr, 
        :value => n}, sprintf(_("%d results"), n)]
    select.push(o)
  }
  return select
end

#make_target_selectObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gonzui/webapp/advsearch.rb', line 22

def make_target_select
  tt = get_short_name(:target_type)
  select = [:select, {:name => tt}]
  oall = [:option, {:type => "radio", :name => tt, 
          :value => ""}, _("All")]
  select.push(oall)
  LangScan::Type.each_group {|group|
    og = [:optgroup, {:label => _(group.name)}]
    added_p = false
    group.each {|type_info|
      if @dbm.has_type?(type_info.type)
        o = [:option, {:type => "radio", :name => tt, 
            :value => type_info.type}, _(type_info.name)]
        og.push(o)
        added_p = true
      end
    }
    select.push(og) if added_p
  }
  return select
end

#make_target_specific_search_formObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/gonzui/webapp/advsearch.rb', line 55

def make_target_specific_search_form
  form = [:form, { :method => "get", 
                   :action => make_uri_general(SearchServlet)}]

  ikeyword = [:input, {:type => "text", :size => 30, 
      :name => get_short_name(:basic_query),
      :value => @search_query.keywords.join(" ")}]
  iphrase = [:input, {:type => "text", :size => 30, 
      :name => get_short_name(:phrase_query),
      :value => (@search_query.phrases.first or []).join(" ")}]

  nresults_select = make_nresults_select

  isubmit = [:input, {:type => "submit", :value => _("Search")}]

  table = [:table]
  table.push([:tr, [:td, {:width => "20%"}, _("Keyword")], 
               [:td, {:width => "30%"}, ikeyword], 
               [:td, {:width => "15%"}, nresults_select],
               [:td, {:width => "15%"}, isubmit]])
  table.push([:tr, [:td, {:width => "20%"}, _("Phrase")], 
               [:td, {:width => "30%"}, iphrase]])

  table.push([:tr])

  target_select = make_target_select
  table.push([:tr, [:td, _("Target")], 
               [:td, target_select], [:td]])

  format_select = make_format_select
  table.push([:tr, [:td, _("Format")], [:td, format_select], [:td]])

  license_select = make_license_select
  table.push([:tr, [:td, _("License")], [:td, license_select], [:td]])

  form.push(table)
  return form
end