From fc01f2cd27721cccbda35ae01ab5413bb8e099db Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sat, 17 Apr 2010 21:00:58 -0400 Subject: cgi_sql_common, sample search form, on navigation of matched results --- lib/sisu/v2/cgi_sql_common.rb | 155 +++++++++++++++++------------------------- 1 file changed, 64 insertions(+), 91 deletions(-) (limited to 'lib') 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'
match limit: - 1,000 - 2,000 - 5,000 - 10,000 + 1,000 + 2,500
echo query 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$/ - %{

+ %{
pg. #{page.to_s}  >>
} elsif page.to_s =~ /^2$/ - %{

+ %{
<<  @@ -497,7 +493,7 @@ module SiSU_CGI_sql
} else - %{

+ %{
|<  @@ -513,14 +509,14 @@ module SiSU_CGI_sql else if page.to_s =~ /^1$/; '' elsif page.to_s =~ /^2$/ - %{

+ %{
<<  pg. #{page.to_s}
} else - %{

+ %{
|<  @@ -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/; %{search } - else %{search } - end + can_txt_srch=(cgi['view']=~/index/) \ + ? %{search } \ + : %{search } title=%{toc html #{ti} by #{c['creator_author']} #{can_txt_srch}toc html epub pdf portrait pdf landscape odf manifest
} if file_suffix=~/s/ #hmm watch file_suffix - if @text_search_flag; title='

'+title - else title='
'+title - end + title=@text_search_flag \ + ? '

'+title \ + : '
'+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(/(<\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{\\1}) - else c['body'] - end + matched_para=(@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) \ + ? (c['body'].gsub(/(<\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{\\1})) \ + : c['body'] %{

ocn #{c['ocn']}:

#{matched_para}} elsif c['suffix'] =~/1/ #doc %{#{title}

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 - %{


Found in the main body of #{over_this_number} #{@counter_txt_doc} documents, and at #{over_limit} #{@counter_txt_ocn} locations within.
} + @@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 + %{
Found #{@counter_txt_ocn} times in the main body of #{@counter_txt_doc} documents [ matches #{start} to #{range} ]
} 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/; %{search } - else %{search } - end + can_txt_srch=(cgi['view']=~/index/) \ + ? %{search } \ + : %{search } title=%{

toc html #{ti} by #{e['creator_author']} #{can_txt_srch}toc html epub pdf portrait pdf landscape odf manifest
} 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(/(<\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{\\1}) - else e['body'] - end + matched_endnote=(@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) \ + ? matched=e['body'].gsub(/(<\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{\\1}) \ + : e['body'] output=%{#{title}
note #{e['nr']} referred to from ocn #{e['ocn']}: #{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 - %{Found in the endnotes of #{over_this_number} #{@counter_endn_doc} documents, and at #{over_limit} #{@counter_endn_ocn} locations within.
} - 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 + %{Found #{@counter_endn_ocn} times in the endnotes of #{@counter_endn_doc} documents [ matches #{start} to #{range} ]
} + 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='
' + CGI::escapeHTML(e.backtrace.reverse.join("\n"))
           s << CGI::escapeHTML(e.message) + '
' -- cgit v1.2.3