diff options
author | Ralph Amissah <ralph@amissah.com> | 2010-04-17 21:00:58 -0400 |
---|---|---|
committer | Ralph Amissah <ralph@amissah.com> | 2010-04-17 21:00:58 -0400 |
commit | fc01f2cd27721cccbda35ae01ab5413bb8e099db (patch) | |
tree | 57df364937b4431dc3a1501de09d06a0abd7a76e | |
parent | param, information on missing author, title, or copyright (diff) |
cgi_sql_common, sample search form, on navigation of matched results
-rw-r--r-- | lib/sisu/v2/cgi_sql_common.rb | 155 |
1 files changed, 64 insertions, 91 deletions
diff --git a/lib/sisu/v2/cgi_sql_common.rb b/lib/sisu/v2/cgi_sql_common.rb index e536551f..65bb01a9 100644 --- a/lib/sisu/v2/cgi_sql_common.rb +++ b/lib/sisu/v2/cgi_sql_common.rb @@ -203,10 +203,8 @@ module SiSU_CGI_sql <<-'WOK_SQL' <br /> match limit: - <input type="radio" name="sql_match_limit" value="1000" #{@checked_sql_limit[:l1k]}> 1,000 - <input type="radio" name="sql_match_limit" value="2000" #{@checked_sql_limit[:l2k]}> 2,000 - <input type="radio" name="sql_match_limit" value="5000" #{@checked_sql_limit[:l5k]}> 5,000 - <input type="radio" name="sql_match_limit" value="10000" #{@checked_sql_limit[:l10k]}> 10,000 + <input type="radio" name="sql_match_limit" value="1000" #{@checked_sql_limit[:l1000]}> 1,000 + <input type="radio" name="sql_match_limit" value="2500" #{@checked_sql_limit[:l2500]}> 2,500 <br /> <input type="checkbox" name="echo" #{@checked_echo}> echo query <input type="checkbox" name="stats" #{@checked_stats}> result stats @@ -334,9 +332,7 @@ module SiSU_CGI_sql #@offset||=@@offset #@offset+=@@limit search={ :text => [],:endnotes => [] } - cse=if c =~/\S/; true - else false - end + cse=(c =~/\S/) ? true : false st=Dbi_search_string.new('doc_objects.clean',search_for.text1,q['s1'],cse).string se=Dbi_search_string.new('endnotes.clean',search_for.text1,q['s1'],cse).string @text_search_flag=st[:flag] @@ -480,14 +476,14 @@ module SiSU_CGI_sql page=(sql_offset.to_i + sql_match_limit.to_i)/sql_match_limit.to_i if beyond_limit if page.to_s =~ /^1$/ - %{<hr /><br /><center> + %{<br /><center> pg. #{page.to_s} <a href="#{can.next}"> <img border="0" width="22" height="22" src="#{img}/arrow_next_red.png" alt=" >>" /> </a> </center>} elsif page.to_s =~ /^2$/ - %{<hr /><br /><center> + %{<br /><center> <a href="#{can.previous}"> <img border="0" width="22" height="22" src="#{img}/arrow_prev_red.png" alt="<< " /> </a> @@ -497,7 +493,7 @@ module SiSU_CGI_sql </a> </center>} else - %{<hr /><br /><center> + %{<br /><center> <a href="#{can.start}"> <img border="0" width="22" height="22" src="#{img}/arrow_prev_red.png" alt="|< " /> </a> @@ -513,14 +509,14 @@ module SiSU_CGI_sql else if page.to_s =~ /^1$/; '' elsif page.to_s =~ /^2$/ - %{<hr /><br /><center> + %{<br /><center> <a href="#{can.previous}"> <img border="0" width="22" height="22" src="#{img}/arrow_prev_red.png" alt="<< " /> </a> pg. #{page.to_s} </center>} else - %{<hr /><br /><center> + %{<br /><center> <a href="#{can.start}"> <img border="0" width="22" height="22" src="#{img}/arrow_prev_red.png" alt="|< " /> </a> @@ -650,22 +646,14 @@ module SiSU_CGI_sql "#{@db_name_prefix}#{@stub}" end checked_url,checked_stats,checked_searched,checked_tip,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,selected_db='','','','','','','','','' - if cgi['view']=~/text/ - result_type={:index=>'',:text=>'checked'} - else - result_type={:index=>'checked',:text=>''} - end - @@limit=if cgi['sql_match_limit'].to_s=~/10000/ - checked_sql_limit={:l1k=>'',:l2k=>'',:l5k=>'',:l10k=>'checked'} - '10000' - elsif cgi['sql_match_limit'].to_s=~/5000/ - checked_sql_limit={:l1k=>'',:l2k=>'',:l5k=>'checked',:l10k=>''} - '5000' - elsif cgi['sql_match_limit'].to_s=~/2000/ - checked_sql_limit={:l1k=>'',:l2k=>'checked',:l5k=>'',:l10k=>''} - '2000' + result_type=(cgi['view']=~/text/) \ + ? result_type={:index=>'',:text=>'checked'} \ + : result_type={:index=>'checked',:text=>''} + @@limit=if cgi['sql_match_limit'].to_s=~/2500/ + checked_sql_limit={:l1000=>'',:l2500=>'checked'} + '2500' else - checked_sql_limit={:l1k=>'checked',:l2k=>'',:l5k=>'',:l10k=>''} + checked_sql_limit={:l1000=>'checked',:l2500=>''} '1000' end checked_echo='checked' if cgi['echo'] =~/\S/ @@ -728,10 +716,9 @@ module SiSU_CGI_sql dta='&dta=' + CGI.escape(@search_for.date_available) if @search_for.date_available=~/\S/ dtv='&dtv=' + CGI.escape(@search_for.date_valid) if @search_for.date_valid=~/\S/ fns='&fns=' + CGI.escape(@search_for.filename) if @search_for.filename=~/\S/ - @@canned_search_url=if checked_all =~/checked/ - "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}&a=1" - else "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}" - end + @@canned_search_url=(checked_all =~/checked/) \ + ? "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}&a=1" \ + : "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}" mod=ft=~/\S+/ ? (ft.gsub(/ft/,'s1')) : s1 @canned_base_url="#{@base}?#{mod}&db=#{cgi['db']}" if checked_case=~/\S/ @@ -802,10 +789,9 @@ module SiSU_CGI_sql print "Content-type: text/html\n\n" puts (@header+@tail) else #% searches - s1=if @search_for.text1 =~/\S/ - @search_for.text1 - else 'Unavailable' - end + s1=(@search_for.text1 =~/\S/) \ + ? @search_for.text1 \ + : 'Unavailable' if checked_case=~/\S/ @search[:text]<<%{doc_objects.clean~'#{CGI.unescape(s1)}'} @search[:endnotes]<<%{endnotes.clean~'#{CGI.unescape(s1)}'} @@ -845,13 +831,13 @@ module SiSU_CGI_sql #metadata_found_body if c['tid'].to_i != oldtid.to_i ti=c['title'] - can_txt_srch=if cgi['view']=~/index/; %{<a href="#{@canned_base_url}&fns=#{c['filename']}&view=text"><img border="0" width="24" height="16" src="#{@image_src}/b_search.png" alt="search"></a> } - else %{<a href="#{@canned_base_url}&fns=#{c['filename']}&view=index"><img border="0" width="24" height="16" src="#{@image_src}/b_search.png" alt="search"></a> } - end + can_txt_srch=(cgi['view']=~/index/) \ + ? %{<a href="#{@canned_base_url}&fns=#{c['filename']}&view=text"><img border="0" width="24" height="16" src="#{@image_src}/b_search.png" alt="search"></a> } \ + : %{<a href="#{@canned_base_url}&fns=#{c['filename']}&view=index"><img border="0" width="24" height="16" src="#{@image_src}/b_search.png" alt="search"></a> } title=%{<span style="background-color: #{@color_heading}"><a href="#{@hosturl_files}/#{@stub}/#{location}/toc#{lang}.html"><img border="0" width="15" height="18" src="#{@image_src}/b_toc.png" alt="toc html"> #{ti}</a></span> by #{c['creator_author']} #{can_txt_srch}<a href="#{@hosturl_files}/#{@stub}/#{location}/toc#{lang}.html"><img border="0" width="15" height="18" src="#{@image_src}/b_toc.png" alt="toc html"></a> <a href="#{@hosturl_files}/#{@stub}/epub/#{location}#{lang}.epub"><img border="0" width="15" height="15" src="#{@image_src}/b_epub.png" alt="epub"></a> <a href="#{@hosturl_files}/#{@stub}/#{location}/portrait#{lang}.pdf"><img border="0" width="15" height="18" src="#{@image_src}/b_pdf.png" alt="pdf portrait"></a> <a href="#{@hosturl_files}/#{@stub}/#{location}/landscape#{lang}.pdf"><img border="0" width="18" height="15" src="#{@image_src}/b_pdf.png" alt="pdf landscape"></a></a> <a href="#{@hosturl_files}/#{@stub}/#{location}/opendocument#{lang}.odt"><img border="0" width="15" height="15" src="#{@image_src}/b_odf.png" alt="odf"></a> <a href="#{@hosturl_files}/#{@stub}/#{location}/sisu_manifest#{lang}.html"><img border="0" width="15" height="15" src="#{@image_src}/b_info.png" alt="manifest"></a><br />} if file_suffix=~/s/ #hmm watch file_suffix - if @text_search_flag; title='<br /><hr>'+title - else title='<br />'+title - end + title=@text_search_flag \ + ? '<br /><hr>'+title \ + : '<br />'+title @counter_txt_doc+=1 oldtid=c['tid'].to_i else title='' @@ -871,10 +857,9 @@ module SiSU_CGI_sql @search_regx=if unescaped_search #check search_regex=[] build=unescaped_search.scan(/\S+/).each do |g| - if g.to_s =~/(AND|OR)/ - search_regex << '|' - else search_regex << %{#{g.to_s}} - end + (g.to_s =~/(AND|OR)/) \ + ? (search_regex << '|') \ + : (search_regex << %{#{g.to_s}}) end search_regex=search_regex.join(' ') search_regex=search_regex.gsub(/\s*\|\s*/,'|') @@ -883,10 +868,9 @@ module SiSU_CGI_sql end else nil end - matched_para=if (@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) - matched=c['body'].gsub(/(<a\s+href="https?:\/\/[^><\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{<span style="background-color: #{@color_match}">\\1</span>}) - else c['body'] - end + matched_para=(@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) \ + ? (c['body'].gsub(/(<a\s+href="https?:\/\/[^><\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{<span style="background-color: #{@color_match}">\\1</span>})) \ + : c['body'] %{<hr><p><font size="2">ocn <b><a href="#{@hosturl_files}/#{@stub}/#{location}/#{c['seg']}#{lang}.html##{c['ocn']}">#{c['ocn']}</a></b>:</font></p>#{matched_para}} elsif c['suffix'] =~/1/ #doc %{#{title}<hr><p><font size="2">ocn #{c['ocn']}:#{c['body']}} @@ -906,24 +890,19 @@ module SiSU_CGI_sql end else @counter_txt_ocn+=1 - output=unless c['suffix'] =~/1/; title+index - else %{#{title}#{c['ocn'].sort}, } - end + output=c['suffix'] !~/1/ \ + ? title+index \ + : %{#{title}#{c['ocn'].sort}, } end end else output=title end @counters_txt=if @counter_txt_doc > 0 if checked_stats =~/\S/ - @@lt_t=if @counter_txt_ocn==dbi_statement.sql_match_limit.to_i - over_limit='over the limit set of' - over_this_number='more than' - true - else - over_limit,over_this_number='','' - false - end - %{<hr /><font size="2" color="#666666">Found in the main body of #{over_this_number} #{@counter_txt_doc} documents, and at #{over_limit} #{@counter_txt_ocn} locations within.</font><br />} + @@lt_t=(@counter_txt_ocn==dbi_statement.sql_match_limit.to_i) ? true : false + start=(@@offset.to_i+1).to_s + range=(@@offset.to_i+@counter_txt_ocn.to_i).to_s + %{<hr /><font size="2" color="#666666">Found #{@counter_txt_ocn} times in the main body of #{@counter_txt_doc} documents [ matches #{start} to #{range} ]</font><br />} else '' end else '' @@ -945,9 +924,9 @@ module SiSU_CGI_sql if @text_search_flag if e['metadata_tid'].to_i != oldtid.to_i ti=e['title'] - can_txt_srch=if cgi['view']=~/index/; %{<a href="#{@canned_base_url}&fns=#{e['filename']}&view=text"><img border="0" width="24" height="16" src="#{@image_src}/b_search.png" alt="search"></a> } - else %{<a href="#{@canned_base_url}&fns=#{e['filename']}&view=index"><img border="0" width="24" height="16" src="#{@image_src}/b_search.png" alt="search"></a> } - end + can_txt_srch=(cgi['view']=~/index/) \ + ? %{<a href="#{@canned_base_url}&fns=#{e['filename']}&view=text"><img border="0" width="24" height="16" src="#{@image_src}/b_search.png" alt="search"></a> } \ + : %{<a href="#{@canned_base_url}&fns=#{e['filename']}&view=index"><img border="0" width="24" height="16" src="#{@image_src}/b_search.png" alt="search"></a> } title=%{<br /><hr><span style="background-color: #{@color_heading}"><a href="#{@hosturl_files}/#{@stub}/#{location}/toc#{lang}.html"><img border="0" width="15" height="18" src="#{@image_src}/b_toc.png" alt="toc html"> #{ti}</a></span> by #{e['creator_author']} #{can_txt_srch}<a href="#{@hosturl_files}/#{@stub}/#{location}/toc#{lang}.html"><img border="0" width="15" height="18" src="#{@image_src}/b_toc.png" alt="toc html"></a> <a href="#{@hosturl_files}/#{@stub}/epub/#{location}#{lang}.epub"><img border="0" width="15" height="15" src="#{@image_src}/b_epub.png" alt="epub"></a> <a href="#{@hosturl_files}/#{@stub}/#{location}/portrait.pdf"><img border="0" width="15" height="18" src="#{@image_src}/b_pdf.png" alt="pdf portrait"></a> <a href="#{@hosturl_files}/#{@stub}/#{location}/landscape.pdf"><img border="0" width="18" height="15" src="#{@image_src}/b_pdf.png" alt="pdf landscape"></a> <a href="#{@hosturl_files}/#{@stub}/#{location}/opendocument#{lang}.odt"><img border="0" width="15" height="15" src="#{@image_src}/b_odf.png" alt="odf"></a> <a href="#{@hosturl_files}/#{@stub}/#{location}/sisu_manifest#{lang}.html"><img border="0" width="15" height="15" src="#{@image_src}/b_info.png" alt="manifest"></a><br />} if file_suffix=~/s/ @counter_endn_doc+=1 oldtid=e['metadata_tid'].to_i @@ -956,10 +935,9 @@ module SiSU_CGI_sql if cgi['view']=~/text/ \ or (cgi['view']!~/index/ and cgi['search'] !~/search db/) #% txt endnotes @counter_endn_ocn+=1 - matched_endnote=if (@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) - matched=e['body'].gsub(/(<a\s+href="https?:\/\/[^><\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{<span style="background-color: #{@color_match}">\\1</span>}) - else e['body'] - end + matched_endnote=(@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) \ + ? matched=e['body'].gsub(/(<a\s+href="https?:\/\/[^><\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{<span style="background-color: #{@color_match}">\\1</span>}) \ + : e['body'] output=%{#{title}<hr><font size="2">note <b><a href="#{@hosturl_files}/#{@stub}/#{location}/endnotes.html#_#{e['nr']}">#{e['nr']}</a></b> referred to from ocn <a href="#{@hosturl_files}/#{@stub}/#{location}/doc.html##{e['ocn']}">#{e['ocn']}</a>:</font> #{matched_endnote}} else #elsif cgi['view']=~/index/ #% idx endnotes @counter_endn_ocn+=1 @@ -967,33 +945,28 @@ module SiSU_CGI_sql end @counters_endn=if @counter_endn_doc > 0 if checked_stats =~/\S/ - @@lt_e=if @counter_endn_ocn==dbi_statement.sql_match_limit.to_i - over_limit='over the limit set of' - over_this_number='more than' - true - else - over_limit,over_this_number='','' - false - end - %{<font size="2" color="#666666">Found in the endnotes of #{over_this_number} #{@counter_endn_doc} documents, and at #{over_limit} #{@counter_endn_ocn} locations within.</font><br />} - else '' - end + @@lt_e=@counter_endn_ocn==dbi_statement.sql_match_limit.to_i \ + ? true \ + : false + start=(@@offset.to_i+1).to_s + range=(@@offset.to_i+@counter_endn_ocn.to_i).to_s + %{<font size="2" color="#666666">Found #{@counter_endn_ocn} times in the endnotes of #{@counter_endn_doc} documents [ matches #{start} to #{range} ]</font><br />} + else '' end - @endnotes << output #+ details - else @endnotes=[] #does not take out yet end + @endnotes << output #+ details + else @endnotes=[] #does not take out yet end - offset=dbi_statement.sql_offset.to_s - limit=dbi_statement.sql_match_limit.to_s - @@lt_t ||=false; @@lt_e ||=false - canned=if (@@lt_t or @@lt_e) - dbi_statement.pre_next(true,@image_src).to_s - else - dbi_statement.pre_next(false,@image_src).to_s - end - limit=dbi_statement.sql_match_limit.to_s - cgi.out{@header + @counters_txt + @counters_endn + @body_main.join + @endnotes.join + canned + @tail} #% print cgi_output_header+counters+body+endnotes end + offset=dbi_statement.sql_offset.to_s + limit=dbi_statement.sql_match_limit.to_s + @@lt_t ||=false; @@lt_e ||=false + canned=(@@lt_t or @@lt_e) \ + ? dbi_statement.pre_next(true,@image_src).to_s \ + : dbi_statement.pre_next(false,@image_src).to_s + limit=dbi_statement.sql_match_limit.to_s + cgi.out{@header + @counters_txt + @counters_endn + canned + @body_main.join + @endnotes.join + canned + @tail} #% print cgi_output_header+counters+body+endnotes + end rescue Exception => e s='<pre>' + CGI::escapeHTML(e.backtrace.reverse.join("\n")) s << CGI::escapeHTML(e.message) + '</pre>' |