--- loncom/interface/lonsearchcat.pm 2004/05/05 17:29:06 1.223 +++ loncom/interface/lonsearchcat.pm 2004/05/07 18:50:14 1.224 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.223 2004/05/05 17:29:06 matthew Exp $ +# $Id: lonsearchcat.pm,v 1.224 2004/05/07 18:50:14 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1248,8 +1248,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'}) { @@ -1263,7 +1263,7 @@ sub parse_advanced_search { } } $pretty_search_string .= "
\n"; - push @queries,&build_SQL_query($field,$searchphrase); + push @queries,&build_SQL_query($field,$searchphrase); } } # @@ -1400,7 +1400,7 @@ sub parse_advanced_search { $pretty_search_string .= $pretty_domains_string."
\n"; # if (@queries) { - $query="select * from metadata where ".join(" AND ",@queries); + $query="SELET * FROM metadata WHERE ".join(" AND ",@queries); } elsif ($customquery) { $query = ''; } @@ -1484,34 +1484,70 @@ 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."; - } else { - $pretty_search_string .= " with no related words."; + my $pretty_search_string=''; + my @Queries; + my $concatarg=join(',', + ('title', 'author', 'subject', 'notes', 'abstract', + 'keywords')); + foreach my $search (&process_phrase_input($search_string)){ + $pretty_search_string .= '
'.''.$search.''; + if ($ENV{'form.related'}) { + my @New_Words; + ($search,@New_Words) = &related_version($search); + next if (! $search); + if (@New_Words) { + $pretty_search_string .= + " with related words: @New_Words"; + } } + # + # 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:^
::; +# &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; +} + ###################################################################### ###################################################################### @@ -1530,19 +1566,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); } ###################################################################### @@ -1566,7 +1596,9 @@ sub build_SQL_query { -build => 'Text::Query::Build'); $q->prepare($logic_statement); my $matchexp=${$q}{'matchexp'}; chomp $matchexp; + &Apache::lonnet::logthis('matchexp = '.$matchexp); my $sql_query=&recursive_SQL_query_build($field_name,$matchexp); + &Apache::lonnet::logthis('sql_query = '.$sql_query); return $sql_query; } @@ -1836,7 +1868,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'} eq 'groupsearch')); + ## my %SortableFields=&Apache::lonlocal::texthash( id => 'Default', @@ -2102,6 +2138,10 @@ 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.launch'}); + my $connection = $r->connection; # # Print run_search header @@ -2285,13 +2325,13 @@ END # results to get, so let the client know the top frame needs to be # loaded from /adm/searchcat $r->print(""); - if ($ENV{'form.catalogmode'} ne 'groupsearch') { +# if ($ENV{'form.catalogmode'} ne 'groupsearch') { $r->print(""); - } +# } return; } @@ -2811,6 +2851,41 @@ ENDFRAMES ###################################################################### ###################################################################### +sub has_stat_data { + my ($values) = @_; + if ( (defined($values->{'count'}) && $values->{'count'} ne '') || + (defined($values->{'stdno'}) && $values->{'stdno'} ne '') || + (defined($values->{'disc'}) && $values->{'disc'} ne '') || + (defined($values->{'avetries'}) && $values->{'avetries'} ne '') || + (defined($values->{'difficulty'}) && $values->{'difficulty'} ne '')) { + return 1; + } + return 0; +} + +sub statfields { + return ('count','stdno','disc','avetries','difficulty'); +} + +sub has_eval_data { + my ($values) = @_; + if ( (defined($values->{'clear'}) && $values->{'clear'} ne '') || + (defined($values->{'technical'}) && $values->{'technical'} ne '') || + (defined($values->{'correct'}) && $values->{'correct'} ne '') || + (defined($values->{'helpful'}) && $values->{'helpful'} ne '') || + (defined($values->{'depth'}) && $values->{'depth'} ne '')) { + return 1; + } + return 0; +} + +sub evalfields { + return ('clear','technical','correct','helpful','depth'); +} + +###################################################################### +###################################################################### + =pod =item Metadata Viewing Functions @@ -2874,7 +2949,7 @@ sub detailed_citation_view { { name=>'helpful', translate => 'Helpful: [_1]',}, { name=>'correct', - translate => 'Correcy: [_1]',}, + translate => 'Correct: [_1]',}, { name=>'technical', translate => 'Technical: [_1]',}, ) { @@ -2906,41 +2981,6 @@ sub detailed_citation_view { } ###################################################################### -###################################################################### - -sub has_stat_data { - my ($values) = @_; - if ( (defined($values->{'count'}) && $values->{'count'} ne '') || - (defined($values->{'stdno'}) && $values->{'stdno'} ne '') || - (defined($values->{'disc'}) && $values->{'disc'} ne '') || - (defined($values->{'avetries'}) && $values->{'avetries'} ne '') || - (defined($values->{'difficulty'}) && $values->{'difficulty'} ne '')) { - return 1; - } - return 0; -} - -sub statfields { - return ('count','stdno','disc','avetries','difficulty'); -} - -sub has_eval_data { - my ($values) = @_; - if ( (defined($values->{'clear'}) && $values->{'clear'} ne '') || - (defined($values->{'technical'}) && $values->{'technical'} ne '') || - (defined($values->{'correct'}) && $values->{'correct'} ne '') || - (defined($values->{'helpful'}) && $values->{'helpful'} ne '') || - (defined($values->{'depth'}) && $values->{'depth'} ne '')) { - return 1; - } - return 0; -} - -sub evalfields { - return ('clear','technical','correct','helpful','depth'); -} - -###################################################################### ###################################################################### =pod