--- loncom/interface/lonsearchcat.pm 2002/10/29 19:53:45 1.159 +++ loncom/interface/lonsearchcat.pm 2003/02/03 04:02:17 1.164 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.159 2002/10/29 19:53:45 matthew Exp $ +# $Id: lonsearchcat.pm,v 1.164 2003/02/03 04:02:17 harris41 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -79,7 +79,6 @@ use Apache::lonnet(); use Apache::File(); use CGI qw(:standard); use Text::Query; -use DBI; use GDBM_File; use Apache::loncommon(); use Apache::lonmysql(); @@ -439,7 +438,9 @@ ENDDOCUMENT ' '; my $checkbox = &simplecheckbox('related',$ENV{'form.related'}); $scrout.=<Advanced Search +Advanced Search $checkbox use related words

@@ -542,13 +543,13 @@ ENDHEADER $ENV{'form.abstract'}); # Hack - an empty table row. $scrout.="   \n"; - $scrout.=&searchphrasefield('file
extension','mime', - $ENV{'form.mime'}); + $scrout.=&searchphrasefield('file
extension','extension', + $ENV{'form.extension'}); $scrout.="   \n"; $scrout.=&searchphrasefield('publisher
owner','owner', $ENV{'form.owner'}); $scrout.="\n"; - $ENV{'form.category'}='any' unless length($ENV{'form.category'}); + $ENV{'form.category'}='any' if (! defined($ENV{'form.category'})); $scrout.=&selectbox('File Category','category', $ENV{'form.category'}, 'any','Any category', @@ -692,7 +693,7 @@ sub get_persistent_form_data { &GDBM_READER(),0640)); # # These make sure we do not get array references printed out as 'values'. - my %arrays_allowed = ('form.category'=>1,'form.domains'=>1); + my %arrays_allowed = ('form.domains'=>1); # # Loop through the keys, looking for 'form.' foreach my $name (keys(%persistent_db)) { @@ -1134,7 +1135,7 @@ sub parse_advanced_search { 'lastrevisiondatestart_month','lastrevisiondatestart_day', 'lastrevisiondatestart_year','lastrevisiondateend_month', 'lastrevisiondateend_day','lastrevisiondateend_year', - 'notes','abstract','mime','language','owner', + 'notes','abstract','extension','language','owner', 'custommetadata','customshow','category') { $ENV{"form.$field"}=~s/[^\w\/\s\(\)\=\-\"\']//g; } @@ -1145,16 +1146,13 @@ sub parse_advanced_search { $ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g; } # Preprocess the category form element. - $ENV{'form.category'} = 'any' if (ref($ENV{'form.category'})); - if ($ENV{'form.category'} ne 'any') { - my @extensions = &Apache::loncommon::filecategorytypes - ($ENV{'form.category'}); - $ENV{'form.mime'} = join ' OR ',@extensions; - } + $ENV{'form.category'} = 'any' if (! defined($ENV{'form.category'}) || + ref($ENV{'form.category'})); + # # Check to see if enough information was filled in for my $field ('title','author','subject','keywords','url','version', - 'notes','abstract','mime','language','owner', - 'custommetadata') { + 'notes','abstract','category','extension','language', + 'owner','custommetadata') { if (&filled($ENV{"form.$field"})) { $fillflag++; } @@ -1169,7 +1167,7 @@ sub parse_advanced_search { my $font = ''; # Evaluate logical expression AND/OR/NOT phrase fields. foreach my $field ('title','author','subject','notes','abstract','url', - 'keywords','version','owner','mime') { + 'keywords','version','owner') { if ($ENV{'form.'.$field}) { my $searchphrase = $ENV{'form.'.$field}; $pretty_search_string .= $font."$field contains ". @@ -1188,10 +1186,30 @@ sub parse_advanced_search { push @queries,&build_SQL_query($field,$searchphrase); } } - # I dislike the hack below. - if ($ENV{'form.category'}) { - $ENV{'form.mime'}=''; + # + # Make the 'mime' from 'form.category' and 'form.extension' + # + my $searchphrase; + if (exists($ENV{'form.category'}) && + $ENV{'form.category'} !~ /^\s*$/ && + $ENV{'form.category'} ne 'any') { + my @extensions = &Apache::loncommon::filecategorytypes + ($ENV{'form.category'}); + if (scalar(@extensions) > 0) { + $searchphrase = join(' OR ',@extensions); + } + } + if (exists($ENV{'form.extension'}) && $ENV{'form.extension'} !~ /^\s*$/) { + $searchphrase .= ' OR ' if (defined($searchphrase)); + my @extensions = split(/,/,$ENV{'form.extension'}); + $searchphrase .= join(' OR ',@extensions); + } + if (defined($searchphrase)) { + push @queries,&build_SQL_query('mime',$searchphrase); + $pretty_search_string .=$font.'mime contains '. + $searchphrase.'
'; } + ##### # Evaluate option lists if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') { push @queries,"(language like \"$ENV{'form.language'}\")"; @@ -2231,8 +2249,7 @@ sub display_results { ## foreach my $row (@Results) { if ($connection->aborted()) { - untie %groupsearch_db if (tied(%groupsearch_db)); - &Apache::lonmysql::disconnect_from_db(); + &cleanup(); return; } my %Fields = %{&parse_row(@$row)}; @@ -2944,6 +2961,16 @@ sub start_fresh_session { 1; +sub cleanup { + if (tied(%groupsearch_db)) { + &Apache::lonnet::logthis('Cleanup searchcat: groupsearch_db'); + unless (untie(%groupsearch_db)) { + &Apache::lonnet::logthis('Failed cleanup searchcat: groupsearch_db'); + } + } + &Apache::lonmysql::disconnect_from_db(); +} + __END__ =pod