--- loncom/interface/lonsearchcat.pm 2001/04/02 16:57:38 1.92 +++ loncom/interface/lonsearchcat.pm 2001/04/02 21:18:35 1.93 @@ -711,6 +711,13 @@ sub output_results { my %rhash=%{$replyref}; my $compiledresult=''; my $timeremain=30; + my $resultflag=0; + my $tflag=1; + + # make query information persistent to allow for subsequent revision + my $persistent=&make_persistent(); + + # output beginning of search page $r->print(< @@ -740,6 +747,31 @@ SCRIPT

Search Catalog

CATALOGBEGIN + $r->print(< + +$closebutton +$persistent +
+

Search Query

+RESULTS + if ($mode eq 'Basic') { + $r->print(< +Basic search: $ENV{'form.basicexp'} +

+RESULTS + } + elsif ($mode eq 'Advanced') { + $r->print(< +Advanced search +$query +

+RESULTS + } + $r->print('

Search Results

'); $r->rflush(); $r->print(< @@ -759,9 +791,14 @@ ENDPOP my $servernum=(keys %rhash)+0; $r->print(''); + $servernum.', 0%, count=0/'.$servernum.'";'); $r->rflush(); + my $servercount=0; foreach my $rkey (keys %rhash) { + $servercount++; + $tflag=1; + $compiledresult=''; + my $hostname=$rkey; $r->print(''); $r->rflush(); @@ -769,30 +806,40 @@ ENDPOP my @results; my $replyfile=''; - $reply=~/^([\.\w]+)$/; # must do since 'use strict' checks for tainting - $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1; - $reply=~/(.*?)\_/; - my $hostname=$1; - { - while (1) { - $r->print('') if -e $replyfile; - $r->rflush(); - last if -e "$replyfile.end"; - last unless $timeremain; - sleep 1; - $timeremain--; - $r->print(''); - $r->rflush(); - } - # QUESTION: how should I handle this error condition.. - # I'm sure there is syntax elsewhere I can use.. - my $fh=Apache::File->new($replyfile) or - ($r->print('file cannot be opened') and return OK); - @results=<$fh>; - } + if ($reply eq 'con_lost') { + my $percent=sprintf('%3.0f',($servercount/$servernum*100)); + $r->print(''); + } + else { + $reply=~/^([\.\w]+)$/; # must do since 'use strict' checks for tainting + $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1; + $reply=~/(.*?)\_/; + { + while (1) { + if (-e $replyfile && $tflag) { + $r->print(''); + $r->rflush(); + $tflag=0; + } + last if -e "$replyfile.end"; + last unless $timeremain; + sleep 1; + $timeremain--; + $r->print(''); + $r->rflush(); + } + # QUESTION: how should I handle this error condition.. + # I'm sure there is syntax elsewhere I can use.. + my $fh=Apache::File->new($replyfile) or + ($r->print('ERROR: file cannot be opened') and return OK); + @results=<$fh>; + } + } my $customshow=''; my $extrashow=''; my @customfields; @@ -800,7 +847,7 @@ ENDPOP $customshow=$ENV{'form.customshow'}; $customshow=~s/[^\w\s]//g; my @fields=map {"$_:"} - split(/\s+/,$customshow); + split(/\s+/,$customshow); @customfields=split(/\s+/,$customshow); if ($customshow) { $extrashow="
  • ".join("
  • ",@fields)."
\n"; @@ -822,8 +869,8 @@ ENDPOP chomp $result; next unless $result; my @fields=map - {&Apache::lonnet::unescape($_)} - (split(/\,/,$result)); + {&Apache::lonnet::unescape($_)} + (split(/\,/,$result)); my ($title,$author,$subject,$url,$keywords,$version, $notes,$abstract,$mime,$lang, $creationdate,$lastrevisiondate,$owner,$copyright)=@fields; @@ -835,19 +882,19 @@ ENDPOP foreach my $field (@customfields) { my $value=''; if ($customhash{$url}=~/\<${field}[^\>]*\>(.*?)\<\/${field}[^\>]*\>/s) { - $value=$1; + $value=$1; } - $extrashow2=~s/\<\!\-\- $field \-\-\>/ $value/g; - } - } - - $compiledresult.=</ $value/g; + } + } + + $compiledresult.=< END - $compiledresult.=< END - $compiledresult.=< @@ -855,74 +902,54 @@ onClick="javascript:select_data('$title' END my $httphost=$ENV{'HTTP_HOST'}; - my $viewselect; - if ($mode eq 'Basic') { + my $viewselect; + if ($mode eq 'Basic') { $viewselect=$ENV{'form.basicviewselect'}; } - elsif ($mode eq 'Advanced') { - $viewselect=$ENV{'form.advancedviewselect'}; - } + elsif ($mode eq 'Advanced') { + $viewselect=$ENV{'form.advancedviewselect'}; + } if ($viewselect eq 'Detailed Citation View') { - $compiledresult.=&detailed_citation_view(@fields, - $hostname,$httphost, - $extrashow2); + $compiledresult.=&detailed_citation_view(@fields, + $hostname,$httphost, + $extrashow2); } elsif ($viewselect eq 'Summary View') { $compiledresult.=&summary_view(@fields,$hostname,$httphost, - $extrashow2); + $extrashow2); } elsif ($viewselect eq 'Fielded Format') { $compiledresult.=&fielded_format_view(@fields,$hostname, - $httphost,$extrashow2); + $httphost,$extrashow2); } elsif ($viewselect eq 'XML/SGML') { $compiledresult.=&xml_sgml_view(@fields,$hostname,$httphost, - $extrashow2); + $extrashow2); } - + } - unless ($compiledresult) { - $compiledresult="There were no results that matched your query"; + if ($compiledresult) { + $resultflag=1; } - # make query information persistent to allow for subsequent revision - my $persistent=&make_persistent(); - - $r->print(< -$customdata - -$closebutton -$persistent -
-

Search Query

-RESULTS - if ($mode eq 'Basic') { $r->print(< -Basic search: $ENV{'form.basicexp'} -

+$compiledresult RESULTS + my $percent=sprintf('%3.0f',($servercount/$servernum*100)); + $r->print(''); } - elsif ($mode eq 'Advanced') { - $r->print(< -Advanced search -$query -

-RESULTS + unless ($resultflag) { + $r->print("\nThere were no results that matched your query\n"); } - $r->print(<Search Results -$compiledresult + $r->print(''); $r->rflush(); + $r->print(< RESULTS - } - $r->print(''); $r->rflush(); } # ------------------------------------------------------------- build_SQL_query