--- loncom/interface/lonsearchcat.pm 2003/06/16 19:18:00 1.178 +++ loncom/interface/lonsearchcat.pm 2003/09/22 00:48:32 1.186 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.178 2003/06/16 19:18:00 matthew Exp $ +# $Id: lonsearchcat.pm,v 1.186 2003/09/22 00:48:32 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -82,6 +82,7 @@ use Text::Query; use GDBM_File; use Apache::loncommon(); use Apache::lonmysql(); +use Apache::lonlocal; # ---------------------------------------- variables used throughout the module @@ -186,7 +187,7 @@ sub handler { # This button is different for the RAT compared to # normal invocation. # - $r->content_type('text/html'); + &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; return OK if $r->header_only; ## @@ -207,7 +208,7 @@ sub handler { ## this once, so the pause indicator is deleted ## if (exists($ENV{'form.pause'})) { - sleep(3); + sleep(1); delete($ENV{'form.pause'}); } ## @@ -382,7 +383,8 @@ END (undef,undef,undef,undef); my $pretty_string; if ($ENV{'form.phase'} eq 'basic_search') { - ($query,$pretty_string) = &parse_basic_search($r,$closebutton); + ($query,$pretty_string,$libraries) = + &parse_basic_search($r,$closebutton); } else { # Advanced search ($query,$customquery,$customshow,$libraries,$pretty_string) = &parse_advanced_search($r,$closebutton); @@ -554,12 +556,15 @@ then press SEARCH below. ENDDOCUMENT $scrout.=' '.&simpletextfield('basicexp',$ENV{'form.basicexp'},40). ' '; - my $checkbox = &simplecheckbox('related',$ENV{'form.related'}); + my $relatedcheckbox = &simplecheckbox('related',$ENV{'form.related'}); + my $domain = $r->dir_config('lonDefDomain'); + my $domaincheckbox = &simplecheckbox('domains',$domain); $scrout.=<Advanced Search -$checkbox use related words +$relatedcheckbox use related words + $domaincheckbox only search domain $domain

@@ -579,10 +584,10 @@ per page.

ENDDOCUMENT - if ($ENV{'request.course.id'}) { $scrout.='
'; } -} -if ($ENV{'request.course.id'}) { - $scrout.=(<

Course Search

@@ -594,10 +599,13 @@ Enter terms or phrases, then press SEARC @@ -605,7 +613,7 @@ $scrout.=(<

ENDENDCOURSE -} + } $scrout.=(< @@ -845,6 +853,13 @@ sub get_persistent_form_data { # Loop through the keys, looking for 'form.' foreach my $name (keys(%persistent_db)) { next if ($name !~ /^form./); + # Kludgification begins! + if ($name eq 'form.domains' && + $ENV{'form.searchmode'} eq 'basic' && + $ENV{'form.phase'} ne 'disp_basic') { + next; + } + # End kludge (hopefully) next if (exists($ENV{$name})); my @values = map { &Apache::lonnet::unescape($_); @@ -859,6 +874,7 @@ sub get_persistent_form_data { untie (%persistent_db); return 1; } + ###################################################################### ###################################################################### @@ -1017,11 +1033,11 @@ If $value eq 'on' the box is checked. ############################################### ############################################### -sub simplecheckbox { - my ($name,$value)=@_; - my $checked=''; - $checked="checked" if $value eq 'on'; - return ''; +sub simplecheckbox{ + my ($name,$value,$checked)=@_; + $checked="checked" if ($value eq 'on'); + return ''; } ############################################### @@ -1214,6 +1230,7 @@ sub selectbox { my ($title,$name,$default,$anyvalue,$anytag,$functionref,@idlist)=@_; if (! defined($functionref)) { $functionref = sub { $_[0]}; } my $selout=''; + $title=&mt($title); if (defined($title)) { my $uctitle=uc($title); $selout="\n".'

'. @@ -1415,11 +1432,33 @@ sub parse_advanced_search { ## --------------------------------------------------------------- ## Deal with restrictions to given domains ## + my ($libraries_to_query,$pretty_domains_string) = + &parse_domain_restrictions(); + $pretty_search_string .= $pretty_domains_string."
\n"; + # + if (@queries) { + $query=join(" AND ",@queries); + $query="select * from metadata where $query"; + } elsif ($customquery) { + $query = ''; + } + return ($query,$customquery,$customshow,$libraries_to_query, + $pretty_search_string); +} + +sub parse_domain_restrictions { my $libraries_to_query = undef; # $ENV{'form.domains'} can be either a scalar or an array reference. # We need an array. - my @allowed_domains = (ref($ENV{'form.domains'}) ? @{$ENV{'form.domains'}} - : ($ENV{'form.domains'}) ); + if (! exists($ENV{'form.domains'})) { + return (undef,''); + } + my @allowed_domains; + if (ref($ENV{'form.domains'})) { + @allowed_domains = @{$ENV{'form.domains'}}; + } else { + @allowed_domains = ($ENV{'form.domains'}); + } my %domain_hash = (); my $pretty_domains_string; foreach (@allowed_domains) { @@ -1442,16 +1481,7 @@ sub parse_advanced_search { } } } - $pretty_search_string .= $pretty_domains_string."
\n"; - # - if (@queries) { - $query=join(" AND ",@queries); - $query="select * from metadata where $query"; - } elsif ($customquery) { - $query = ''; - } - return ($query,$customquery,$customshow,$libraries_to_query, - $pretty_search_string); + return ($libraries_to_query,$pretty_domains_string); } ###################################################################### @@ -1479,7 +1509,8 @@ sub parse_basic_search { $ENV{"form.$_"}=&Apache::lonnet::unescape($ENV{"form.$_"}); $ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g; } - + my ($libraries_to_query,$pretty_domains_string) = + &parse_domain_restrictions(); # Check to see if enough is filled in unless (&filled($ENV{'form.basicexp'})) { &output_blank_field_error($r,$closebutton,'phase=disp_basic'); @@ -1503,8 +1534,14 @@ sub parse_basic_search { 'keywords')); $concatarg='title' if $ENV{'form.titleonly'}; $query=&build_SQL_query('concat_ws(" ",'.$concatarg.')',$search_string); + if (defined($pretty_domains_string) && $pretty_domains_string ne '') { + $pretty_search_string .= ' '.$pretty_domains_string; + } $pretty_search_string .= "
\n"; - return 'SELECT * FROM metadata WHERE '.$query,$pretty_search_string; + my $final_query = 'SELECT * FROM metadata WHERE '.$query; +# &Apache::lonnet::logthis($final_query); + return ($final_query,$pretty_search_string, + $libraries_to_query); } @@ -2137,22 +2174,23 @@ END if (@Servers_to_contact) { # Contact one server my $server = shift(@Servers_to_contact); + &update_status($r,'contacting '.$server); my $reply=&Apache::lonnet::metadata_query($query,$customquery, $customshow,[$server]); ($server) = keys(%$reply); $Server_status{$server} = $reply->{$server}; - &update_status($r,'contacting '.$server); } else { # wait a sec. to give time for files to be written # This sleep statement is here instead of outside the else # block because we do not want to pause if we have servers # left to contact. + if (scalar (keys(%Server_status))) { + &update_status($r, + 'waiting on '.(join(' ',keys(%Server_status)))); + } sleep(1); } # - 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. @@ -2369,7 +2407,8 @@ sub display_results { ."\n" ); if ($total_results == 0) { - $r->print("There are currently no results.\n". + $r->print(''. + '

There are currently no results.

'. ""); return; } else { @@ -2704,10 +2743,19 @@ SCRIPT $result.=<
ENDCOURSESEARCH - $scrout.=' '.&simpletextfield('courseexp',$ENV{'form.courseexp'},40); - my $crscheckbox = &simplecheckbox('crsfulltext',$ENV{'form.crsfulltext'}); - my $relcheckbox = &simplecheckbox('crsrelated',$ENV{'form.crsrelated'}); -$scrout.=(<
$relcheckbox use related words
$crscheckbox fulltext search (time consuming)