Diff for /loncom/interface/lonsearchcat.pm between versions 1.43 and 1.44

version 1.43, 2001/03/20 12:21:56 version 1.44, 2001/03/20 17:49:03
Line 468  sub advancedsearch { Line 468  sub advancedsearch {
     }      }
   
     my $query='';      my $query='';
   
       my $testquery='';
       # Go through logical expression AND/OR/NOT phrase fields.
       foreach my $field ('title','author','subject','notes','abstract') {
    if ($ENV{'form.'.$field}) {
       $testquery=build_SQL_query($field,$ENV{'form.'.$field});
    }
       }
   
 #    my $concatarg=join(',"    ",',  #    my $concatarg=join(',"    ",',
 #       ('title', 'author', 'subject', 'notes', 'abstract'));  #       ('title', 'author', 'subject', 'notes', 'abstract'));
   
     $query="select * from metadata where concat(title) like '\%$ENV{'form.title'}\%'";      $query="select * from metadata where $testquery";
   
     my $reply=&Apache::lonnet::metadata_query($query);      my $reply=&Apache::lonnet::metadata_query($query);
   
     &output_results('Advanced',$r,$envhash,$reply);      &output_results('Advanced',$r,$envhash,$query,$reply);
     return OK;      return OK;
 }  }
   
Line 505  sub basicsearch { Line 515  sub basicsearch {
   
     $query="select * from metadata where concat($concatarg) like '\%$ENV{'form.basicexp'}\%'";      $query="select * from metadata where concat($concatarg) like '\%$ENV{'form.basicexp'}\%'";
     my $reply=&Apache::lonnet::metadata_query($query);      my $reply=&Apache::lonnet::metadata_query($query);
     &output_results('Basic',$r,$envhash,$reply);      &output_results('Basic',$r,$envhash,$query,$reply);
     return OK;      return OK;
 }  }
   
   # ---------------- Message to output when there are not enough fields filled in
 sub output_blank_field_error {  sub output_blank_field_error {
     my ($r)=@_;      my ($r)=@_;
     # make query information persistent to allow for subsequent revision      # make query information persistent to allow for subsequent revision
Line 555  RESULTS Line 566  RESULTS
   
 # ----------------------------- format and output results based on a reply list  # ----------------------------- format and output results based on a reply list
 sub output_results {  sub output_results {
     my ($mode,$r,$envhash,@replylist)=@_;      my ($mode,$r,$envhash,$query,@replylist)=@_;
     my %ENV=%{$envhash};      my %ENV=%{$envhash};
       my $compiledresult='';
   
     foreach my $reply (@replylist) {      foreach my $reply (@replylist) {
   
  my @results;   my @results;
Line 579  sub output_results { Line 592  sub output_results {
     @results=<$fh>;      @results=<$fh>;
  }   }
   
  my $compiledresult='';  
   
  foreach my $result (@results) {   foreach my $result (@results) {
     my ($title,$author,$subject,$url,$keywords,$version,      my ($title,$author,$subject,$url,$keywords,$version,
  $notes,$abstract,$mime,$lang,   $notes,$abstract,$mime,$lang,
Line 677  RESULTS Line 688  RESULTS
 <b>Basic search:</b> $ENV{'form.basicexp'}  <b>Basic search:</b> $ENV{'form.basicexp'}
 </p>  </p>
 RESULTS  RESULTS
       }
     elsif ($mode eq 'Advanced') {      elsif ($mode eq 'Advanced') {
  $r->print(<<RESULTS);   $r->print(<<RESULTS);
 <p>  <p>
 <b>Advanced search</b>  <b>Advanced search</b>
   $query
 </p>  </p>
 RESULTS  RESULTS
     }      }
    $r->print(<<RESULTS);
 <h3>Search Results</h3>  <h3>Search Results</h3>
 $compiledresult  $compiledresult
 </body>  </body>
Line 698  sub build_SQL_query { Line 712  sub build_SQL_query {
     my $q=new Text::Query('abc',      my $q=new Text::Query('abc',
   -parse => 'Text::Query::ParseAdvanced',    -parse => 'Text::Query::ParseAdvanced',
   -build => 'Text::Query::Build');    -build => 'Text::Query::Build');
     $q->prepare($statement);      $q->prepare($logic_statement);
     my $matchexp=${$q}{'matchexp'}; chomp $matchexp;      my $matchexp=${$q}{'matchexp'}; chomp $matchexp;
     my $sql_query=&recursive_SQL_query_build($field_name,$matchexp);      my $sql_query=&recursive_SQL_query_build($field_name,$matchexp);
       return $sql_query;
 }  }
   
 # - Recursively parse a reverse notation expression into a SQL query expression  # - Recursively parse a reverse notation expression into a SQL query expression
Line 710  sub recursive_SQL_query_build { Line 725  sub recursive_SQL_query_build {
     return $pattern unless @matches;      return $pattern unless @matches;
     foreach my $match (@matches) {      foreach my $match (@matches) {
  $match=~/\[ (\w+)\s(.*) \]/;   $match=~/\[ (\w+)\s(.*) \]/;
  ($key,$value)=($1,$2);   my ($key,$value)=($1,$2);
  my $replacement='';   my $replacement='';
  if ($key eq 'literal') {   if ($key eq 'literal') {
     $replacement="($dkey like \"\%$value\%\")";      $replacement="($dkey like \"\%$value\%\")";

Removed from v.1.43  
changed lines
  Added in v.1.44


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>