--- loncom/interface/lonsearchcat.pm 2001/04/02 16:57:38 1.92 +++ loncom/interface/lonsearchcat.pm 2001/04/16 18:53:56 1.96 @@ -182,8 +182,8 @@ END $scrout.=&searchphrasefield('Limit by URL','url', $ENV{'form.url'}); - $scrout.=&searchphrasefield('Limit by version','version', - $ENV{'form.version'}); +# $scrout.=&searchphrasefield('Limit by version','version', +# $ENV{'form.version'}); $scrout.=&searchphrasefield('Limit by notes','notes', $ENV{'form.notes'}); @@ -301,9 +301,9 @@ ENDDOCUMENT $r->print(' '); $r->print(&simplecheckbox('titleonly',$ENV{'form.titleonly'})); $r->print('Title only '); - $r->print(&simplecheckbox('allversions',$ENV{'form.allversions'})); +# $r->print(&simplecheckbox('allversions',$ENV{'form.allversions'})); +# Search historic archives $r->print(<Search historic archives
@@ -658,11 +658,13 @@ sub basicsearch { my $query=''; my $concatarg=join('," ",', ('title', 'author', 'subject', 'notes', 'abstract')); - $query='select * from metadata where concat(' . $concatarg . ') like %' . - $ENV{'form.basicexp'} . '%'; + $concatarg='title' if $ENV{'form.titleonly'}; + + $query=&build_SQL_query('concat('.$concatarg.')',$ENV{'form.'.'basicexp'}); + # Get reply (either a hash reference to filehandles or bad connection) - my $reply=&Apache::lonnet::metadata_query($query); + my $reply=&Apache::lonnet::metadata_query('select * from metadata where '.$query); # Output search results &output_results('Basic',$r,$envhash,$query,$reply); @@ -711,6 +713,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 +749,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 +793,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 +808,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(); + + 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>; } - # 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>; } - my $customshow=''; my $extrashow=''; my @customfields; @@ -800,7 +849,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 +871,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 +884,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 +904,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 @@ -964,6 +993,11 @@ sub recursive_SQL_query_build { if ($key eq 'literal') { $replacement="($dkey like \"\%$value\%\")"; } + elsif ($key eq 'not') { + $value=~s/like/not like/; +# $replacement="($dkey not like $value)"; + $replacement="$value"; + } elsif ($key eq 'and') { $value=~/(.*[\"|\)]) ([|\(|\^].*)/; $replacement="($1 AND $2)";