--- loncom/interface/lonsearchcat.pm 2001/03/08 16:55:43 1.5 +++ loncom/interface/lonsearchcat.pm 2001/03/12 17:28:32 1.7 @@ -7,6 +7,9 @@ package Apache::lonsearchcat; use strict; use Apache::Constants qw(:common); +use Apache::lonnet(); +use Apache::File(); +use CGI qw(:standard); my %language; my $scrout; @@ -16,6 +19,17 @@ my %mimetag; sub handler { my $r = shift; + +# -------------------------------------- see if called from an interactive mode + map { + my ($name, $value) = split(/=/,$_); + $value =~ tr/+/ /; + $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; + if ($name eq 'catalogmode') { + $ENV{'form.'.$name}=$value; + } + } (split(/&/,$ENV{'QUERY_STRING'})); + $r->content_type('text/html'); $r->send_http_header; return OK if $r->header_only; @@ -56,6 +70,10 @@ sub handler { } <$fh>; } + if ($ENV{'form.basicsubmit'} eq 'SEARCH') { + return &basicsearch($r,$ENV{'form.basicexp'}); + } + $scrout=""; $scrout.=&searchphrasefield('Limit by title','title', ''); @@ -616,6 +634,22 @@ LASTREVISIONDATEEND
+ +
+
Enter terms or phrases separated by search operators
such as AND or OR then press SEARCH below. Terms should be specific
to the title, author, subject, notes, or abstract information associated
@@ -681,5 +719,92 @@ sub selectbox {
return $selout.'';
}
+# --------------------------------------------------- Performing a basic search
+sub basicsearch {
+ my ($r,$expression)=@_;
+
+ my $query=$expression;
+# $query="select * from metadata where concat(title,':\@:',author) like '\%Sci\%'";
+ $query="select * from metadata where concat(title,\" \",author) like '\%$expression\%'";
+# my $reply=&Apache::lonnet::reply("querysend:DESCRIBE metadata","msul3");
+ my $reply=&Apache::lonnet::reply("querysend:$query",'msul3');
+# my $reply=&Apache::lonnet::reply('querysend:select * from metadata','msul3');
+
+ 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) {
+ last if -e $replyfile;
+ sleep 1;
+ }
+ # 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 $compiledresult='';
+
+ foreach my $result (@results) {
+ my ($title,$author,$subject,$notes,$abstract,$mime,$lang,
+ $creationdate,$lastrevisiondate,$owner,$copyright
+ )=map {&Apache::lonnet::unescape($_)} (split(/\,/,$result));
+ my $shortabstract=$abstract;
+ $shortabstract=substr($abstract,0,200) if length($abstract)>200;
+ $compiledresult=<
+Author(s): $author
+Subject: $subject
+Keyword(s): not available yet
+Notes: $notes
+Abstract: $shortabstract
+MIME Type: $mimetag{$mime}
+Language: $language{$lang}
+Creation Date: $creationdate
+Last Revision Date: $lastrevisiondate
+Publisher/Owner: $owner
+Copyright/Distribution: $copyright
+Repository Location: $hostname
+