--- loncom/interface/lonsearchcat.pm 2002/09/16 20:57:28 1.158
+++ loncom/interface/lonsearchcat.pm 2003/01/06 13:54:25 1.162
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.158 2002/09/16 20:57:28 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.162 2003/01/06 13:54:25 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -439,7 +439,9 @@ ENDDOCUMENT
' ';
my $checkbox = &simplecheckbox('related',$ENV{'form.related'});
$scrout.=<Advanced Search |
+Advanced Search |
$checkbox use related words | |
@@ -542,13 +544,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 +694,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 +1136,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 +1147,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 +1168,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 +1187,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'}\")";
@@ -1976,7 +1995,7 @@ END
my $time_remaining = $max_time - (time - $starttime) ;
my $last_time = $time_remaining;
&update_seconds($r,$time_remaining);
- while (($time_remaining > 0) &&
+ while (($time_remaining > 0) &&
((@Servers_to_contact) || keys(%Server_status))) {
# Send out a search request if it needs to be done.
if (@Servers_to_contact) {
@@ -1994,7 +2013,13 @@ END
# left to contact.
sleep(1);
}
- &update_status($r,'waiting on '.(join(' ',keys(%Server_status))));
+ #
+ if (scalar (keys(%Server_status))) {
+ &update_status($r,'waiting on '.(join(' ',keys(%Server_status))));
+ }
+ #
+ # Loop through the servers we have contacted but do not
+ # have results from yet, looking for results.
while (my ($server,$status) = each(%Server_status)) {
last if ($connection->aborted());
if ($status eq 'con_lost') {
@@ -2057,6 +2082,7 @@ END
}
last if ($connection->aborted());
# Finished looping through the servers
+ $starttime = time if (@Servers_to_contact);
$time_remaining = $max_time - (time - $starttime) ;
if ($last_time - $time_remaining > 0) {
$last_time = $time_remaining;
@@ -2224,8 +2250,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)};
@@ -2937,6 +2962,11 @@ sub start_fresh_session {
1;
+sub cleanup {
+ untie %groupsearch_db if (tied(%groupsearch_db));
+ &Apache::lonmysql::disconnect_from_db();
+}
+
__END__
=pod