--- loncom/interface/lonsearchcat.pm 2003/03/08 01:43:12 1.167 +++ loncom/interface/lonsearchcat.pm 2003/03/13 19:08:52 1.171 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.167 2003/03/08 01:43:12 www Exp $ +# $Id: lonsearchcat.pm,v 1.171 2003/03/13 19:08:52 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -142,9 +142,13 @@ my %persistent_db; my $hidden_fields; my $bodytag; +# +# For course search +# my %alreadyseen; my $hashtied; my %hash; +my $totalfound; ###################################################################### ###################################################################### @@ -418,6 +422,7 @@ sub course_search { } my $fulltext=$ENV{'form.crsfulltext'}; my @allwords=($search_string,@New_Words); + $totalfound=0; $r->print('LON-CAPA Course Search'. $bodytag.$pretty_search_string); $r->rflush(); @@ -425,13 +430,18 @@ sub course_search { $hashtied=0; undef %alreadyseen; %alreadyseen=(); + my $c=$r->connection; &tiehash(); foreach (keys %hash) { + if ($c->aborted()) { last; } if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) { - &checkonthis($r,$hash{$_},0,$hash{'title_'.$1},@allwords,$fulltext); + &checkonthis($r,$hash{$_},0,$hash{'title_'.$1},$fulltext,@allwords); } } &untiehash(); + unless ($totalfound) { + $r->print('

No resources found.

'); + } # =================================================== Done going through course $r->print(''); } @@ -456,7 +466,7 @@ sub untiehash { # =============================== This pulls up a resource and its dependencies sub checkonthis { - my ($r,$url,$level,$title,@allwords,$fulltext)=@_; + my ($r,$url,$level,$title,$fulltext,@allwords)=@_; $alreadyseen{$url}=1; $r->rflush(); my $result=&Apache::lonnet::metadata($url,'title').' '. @@ -464,7 +474,7 @@ sub checkonthis { &Apache::lonnet::metadata($url,'abstract').' '. &Apache::lonnet::metadata($url,'keywords'); if (($url) && ($fulltext)) { - $result.=&Apache::lonnet::ssibody($url); + $result.=&Apache::lonnet::ssi_body($url); } $result=~s/\s+/ /gs; my $applies=0; @@ -482,15 +492,18 @@ sub checkonthis { $r->print(' '); } $r->print(''. - ($title?$title:$url).''); - $r->rflush(); + ($title?$title:$url).'
'); + $totalfound++; + } elsif ($fulltext) { + $r->print(' .'); } + $r->rflush(); # Check also the dependencies of this one my $dependencies= &Apache::lonnet::metadata($url,'dependencies'); foreach (split(/\,/,$dependencies)) { if (($_=~/^\/res\//) && (!$alreadyseen{$_})) { - &checkonthis($r,$_,$level+1,'',@allwords,$fulltext); + &checkonthis($r,$_,$level+1,'',$fulltext,@allwords); } } } @@ -1885,37 +1898,31 @@ the following format: =cut -## -## Restrictions: -## columns of type 'text' and 'blob' cannot have defaults. -## columns of type 'enum' cannot be used for FULLTEXT. -## -my @DataOrder = qw/id title author subject url keywords version notes - abstract mime lang owner copyright creationdate lastrevisiondate hostname/; - -my %Datatypes = - ( id =>{ type => 'MEDIUMINT', - restrictions => 'UNSIGNED NOT NULL', - primary_key => 'yes', - auto_inc => 'yes' - }, - title =>{ type=>'TEXT'}, - author =>{ type=>'TEXT'}, - subject =>{ type=>'TEXT'}, - url =>{ type=>'TEXT', - restrictions => 'NOT NULL' }, - keywords =>{ type=>'TEXT'}, - version =>{ type=>'TEXT'}, - notes =>{ type=>'TEXT'}, - abstract =>{ type=>'TEXT'}, - mime =>{ type=>'TEXT'}, - lang =>{ type=>'TEXT'}, - owner =>{ type=>'TEXT'}, - copyright =>{ type=>'TEXT'}, - hostname =>{ type=>'TEXT'}, +##################################################################### +##################################################################### + +my @Datatypes = + ( { name => 'id', + type => 'MEDIUMINT', + restrictions => 'UNSIGNED NOT NULL', + primary_key => 'yes', + auto_inc => 'yes' }, + { name => 'title', type=>'TEXT'}, + { name => 'author', type=>'TEXT'}, + { name => 'subject', type=>'TEXT'}, + { name => 'url', type=>'TEXT', restrictions => 'NOT NULL' }, + { name => 'keywords', type=>'TEXT'}, + { name => 'version', type=>'TEXT'}, + { name => 'notes', type=>'TEXT'}, + { name => 'abstract', type=>'TEXT'}, + { name => 'mime', type=>'TEXT'}, + { name => 'lang', type=>'TEXT'}, + { name => 'owner', type=>'TEXT'}, + { name => 'copyright', type=>'TEXT'}, + { name => 'hostname', type=>'TEXT'}, #-------------------------------------------------- - creationdate =>{ type=>'DATETIME'}, - lastrevisiondate =>{ type=>'DATETIME'}, + { name => 'creationdate', type=>'DATETIME'}, + { name => 'lastrevisiondate', type=>'DATETIME'}, #-------------------------------------------------- ); @@ -1943,9 +1950,8 @@ Returns: the identifier of the table on ###################################################################### sub create_results_table { my $table = &Apache::lonmysql::create_table - ( { columns => \%Datatypes, - column_order => \@DataOrder, - fullindex => \@Fullindicies, + ( { columns => \@Datatypes, + FULLTEXT => {'columns' => \@Fullindicies}, } ); if (defined($table)) { $ENV{'form.table'} = $table; @@ -2471,7 +2477,7 @@ sub parse_row { my @Row = @_; my %Fields; for (my $i=0;$i<=$#Row;$i++) { - $Fields{$DataOrder[$i]}=&Apache::lonnet::unescape($Row[$i]); + $Fields{$Datatypes[$i]->{'name'}}=&Apache::lonnet::unescape($Row[$i]); } $Fields{'language'} = &Apache::loncommon::languagedescription($Fields{'lang'});