--- loncom/interface/lonsearchcat.pm 2004/05/05 14:14:10 1.222
+++ loncom/interface/lonsearchcat.pm 2004/05/10 18:59:18 1.227
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.222 2004/05/05 14:14:10 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.227 2004/05/10 18:59:18 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -174,6 +174,7 @@ sub handler {
'&launch='.$ENV{'form.launch'}.
'&mode='.$ENV{'form.mode'},
text=>"Course and Catalog Search",
+ target=>'_top',
bug=>'Searching',});
} else {
&Apache::lonhtmlcommon::add_breadcrumb
@@ -182,6 +183,7 @@ sub handler {
'&launch='.$ENV{'form.launch'}.
'&mode='.$ENV{'form.mode'},
text=>"Catalog Search",
+ target=>'_top',
bug=>'Searching',});
}
#
@@ -231,24 +233,19 @@ END
$hidden_fields = ''."\n";
if (exists($ENV{'form.catalogmode'})) {
- $hidden_fields .= ''."\n";
+ $hidden_fields .= &hidden_field('catalogmode');
}
if (exists($ENV{'form.form'})) {
- $hidden_fields .= ''."\n";
+ $hidden_fields .= &hidden_field('form');
}
if (exists($ENV{'form.element'})) {
- $hidden_fields .= ''."\n";
+ $hidden_fields .= &hidden_field('element');
}
if (exists($ENV{'form.titleelement'})) {
- $hidden_fields .= ''."\n";
+ $hidden_fields .= &hidden_field('titleelement');
}
if (exists($ENV{'form.mode'})) {
- $hidden_fields .= ''."\n";
+ $hidden_fields .= &hidden_field('mode');
}
##
## Configure dynamic components of interface
@@ -422,6 +419,14 @@ sub clean_up_environment {
}
}
+sub hidden_field {
+ my ($name,$value) = @_;
+ if (! defined($value)) {
+ $value = $ENV{'form.'.$name};
+ }
+ return ''.$/;
+}
+
######################################################################
######################################################################
##
@@ -556,9 +561,11 @@ Prints the form for the basic search. S
######################################################################
sub print_basic_search_form {
my ($r,$closebutton,$hidden_fields) = @_;
+ my $result = ($ENV{'form.catalogmode'} ne 'groupsearch');
my $bodytag=&Apache::loncommon::bodytag('Search').
&Apache::lonhtmlcommon::breadcrumbs(undef,'Searching','Searching',
- undef,undef,! $ENV{'form.launch'});
+ undef,undef,
+ $ENV{'form.catalogmode'} ne 'groupsearch');
my $scrout = &search_html_header().$bodytag;
if (&Apache::lonnet::allowed('bre',$ENV{'request.role.domain'})) {
# Define interface components
@@ -616,7 +623,8 @@ sub print_basic_search_form {
''.
''.
- (' 'x2).$closebutton.(' 'x2).&viewoptions().
+ (' 'x2).$closebutton.(' 'x2).
+ &viewoptions().
''.
''.$/;
$scrout .= ''.$/.''.'';
@@ -685,11 +693,9 @@ Prints the advanced search form.
sub print_advanced_search_form{
my ($r,$closebutton,$hidden_fields) = @_;
my $bodytag=&Apache::loncommon::bodytag('Advanced Catalog Search').
- &Apache::lonhtmlcommon::breadcrumbs(undef,'Searching',
- 'Searching',
- undef,undef,
- ! $ENV{'form.launch'});
-
+ &Apache::lonhtmlcommon::breadcrumbs(undef,'Searching','Searching',
+ undef,undef,
+ $ENV{'form.catalogmode'} ne 'groupsearch');
my %lt=&Apache::lonlocal::texthash('srch' => 'Search',
'reset' => 'Reset',
'help' => 'Help');
@@ -959,7 +965,7 @@ Outputs: text for box with view options
######################################################################
######################################################################
sub viewoptions {
- my $scrout="\n".'';
+ my $scrout;
if (! defined($ENV{'form.viewselect'})) {
$ENV{'form.viewselect'}='detailed';
}
@@ -1184,7 +1190,7 @@ Parse advanced search form and return th
sub parse_advanced_search {
my ($r,$closebutton,$hidden_fields)=@_;
my @BasicFields = ('title','author','subject','keywords','url','version',
- 'notes','abstract','extension','owner',
+ 'notes','abstract','extension','owner','authorspace',
# 'custommetadata','customshow',
'modifyinguser','standards','mime');
my @StatsFields = &statfields();
@@ -1244,8 +1250,8 @@ sub parse_advanced_search {
my $font = '';
# Evaluate logical expression AND/OR/NOT phrase fields.
foreach my $field (@BasicFields) {
- if ($ENV{'form.'.$field}) {
- my $searchphrase = $ENV{'form.'.$field};
+ next if (!defined($ENV{'form.'.$field}) || $ENV{'form.'.$field} eq '');
+ foreach my $searchphrase(&process_phrase_input($ENV{'form.'.$field})){
$pretty_search_string .= $font."$field contains ".
$searchphrase."";
if ($ENV{'form.'.$field.'_related'}) {
@@ -1259,7 +1265,7 @@ sub parse_advanced_search {
}
}
$pretty_search_string .= "
\n";
- push @queries,&build_SQL_query($field,$searchphrase);
+ push @queries,&build_SQL_query($field,$searchphrase);
}
}
#
@@ -1396,7 +1402,7 @@ sub parse_advanced_search {
$pretty_search_string .= $pretty_domains_string."
\n";
#
if (@queries) {
- $query="select * from metadata where ".join(" AND ",@queries);
+ $query="SELECT * FROM metadata WHERE ".join(" AND ",@queries);
} elsif ($customquery) {
$query = '';
}
@@ -1480,34 +1486,74 @@ sub parse_basic_search {
&output_blank_field_error($r,$closebutton,'phase=disp_basic');
return OK;
}
- my $pretty_search_string = ''.$ENV{'form.basicexp'}.'';
- if ($ENV{'form.related'}) {
- my @New_Words;
- ($search_string,@New_Words) = &related_version($ENV{'form.basicexp'});
- if (@New_Words) {
- $pretty_search_string .= " with related words: @New_Words.";
+ my $pretty_search_string='';
+ my @Queries;
+ my $concatarg=join(',',
+ ('title', 'author', 'subject', 'notes', 'abstract',
+ 'keywords'));
+ foreach my $search (&process_phrase_input($search_string)){
+ if ($ENV{'form.related'}) {
+ $pretty_search_string .= ' and
' if ($pretty_search_string ne '');
+ $pretty_search_string .= ''.$search.'';
+ my @New_Words;
+ ($search,@New_Words) = &related_version($search);
+ next if (! $search);
+ if (@New_Words) {
+ $pretty_search_string .=
+ " with related words: @New_Words";
+ }
} else {
- $pretty_search_string .= " with no related words.";
+ $pretty_search_string .= ' and ' if ($pretty_search_string ne '');
+ $pretty_search_string .= ''.$search.'';
}
+ #
+ # Build SQL query string based on form page
+ push(@Queries,
+ &build_SQL_query('concat_ws(" ",'.$concatarg.')',$search));
}
+ my $final_query = 'SELECT * FROM metadata WHERE '.join(" AND ",@Queries);
#
- # Build SQL query string based on form page
- my $query='';
- my $concatarg=join(',',
- ('title', 'author', 'subject', 'notes', 'abstract',
- '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";
- my $final_query = 'SELECT * FROM metadata WHERE '.$query;
- # &Apache::lonnet::logthis($final_query);
+ $pretty_search_string =~ s:^
and ::;
+# &Apache::lonnet::logthis($final_query);
return ($final_query,$pretty_search_string,
$libraries_to_query);
}
+sub process_phrase_input {
+ my ($phrase)=@_;
+ my @Phrases;
+ # &Apache::lonnet::logthis('phrase = :'.$phrase.':');
+ my $in_quotes = 0;
+ my @Words = split(/\s+/,$phrase);
+ foreach my $word (@Words) {
+ $word =~ s/(\w+)\"(\w+)/$1$2/g;
+ if ($in_quotes) {
+ if ($word =~ s/(\")$//) {
+ $in_quotes = 0;
+ }
+ if ($Phrases[-1] ne '') {
+ $Phrases[-1] .= ' ';
+ }
+ $Phrases[-1] .= $word;
+ } else {
+ if ($word =~ s/^(\")//) {
+ $in_quotes=1;
+ }
+ push(@Phrases,$word);
+ }
+ }
+ #
+ #foreach my $p (@Phrases) {
+ # &Apache::lonnet::logthis(' subphrase = '.$p);
+ #}
+ #
+ return @Phrases;
+}
+
######################################################################
######################################################################
@@ -1526,19 +1572,13 @@ Note: Using this twice on a string is pr
######################################################################
######################################################################
sub related_version {
- my $search_string = shift;
- my $result = $search_string;
- my %New_Words = ();
- while ($search_string =~ /(\w+)/cg) {
- my $word = $1;
- next if (lc($word) =~ /\b(or|and|not)\b/);
- my @Words = &Apache::loncommon::get_related_words($word);
- @Words = ($#Words>4? @Words[0..4] : @Words);
- foreach (@Words) { $New_Words{$_}++;}
- my $replacement = join " OR ", ($word,@Words);
- $result =~ s/(\b)$word(\b)/$1($replacement)$2/g;
- }
- return $result,sort(keys(%New_Words));
+ my ($word) = @_;
+ return (undef) if (lc($word) =~ /\b(or|and|not)\b/);
+ my @Words = &Apache::loncommon::get_related_words($word);
+ # Only use 4 related words
+ @Words = ($#Words>4? @Words[0..4] : @Words);
+ my $result = join " OR ", ($word,@Words);
+ return $result,sort(@Words);
}
######################################################################
@@ -1832,7 +1872,11 @@ a link to change the search query.
######################################################################
sub print_sort_form {
my ($r,$pretty_query_string) = @_;
- my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
+ my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1).
+ &Apache::lonhtmlcommon::breadcrumbs
+ (undef,'Searching','Searching',undef,undef,
+ $ENV{'form.catalogmode'} ne 'groupsearch');
+
##
my %SortableFields=&Apache::lonlocal::texthash(
id => 'Default',
@@ -2098,6 +2142,9 @@ results into MySQL.
sub run_search {
my ($r,$query,$customquery,$customshow,$serverlist,$pretty_string) = @_;
my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
+ $bodytag.=&Apache::lonhtmlcommon::breadcrumbs
+ (undef,'Searching','Searching',undef,undef,
+ $ENV{'form.catalogmode'} ne 'groupsearch');
my $connection = $r->connection;
#
# Print run_search header
@@ -2281,13 +2328,13 @@ END
# results to get, so let the client know the top frame needs to be
# loaded from /adm/searchcat
$r->print("