--- loncom/interface/lonsearchcat.pm 2004/05/05 14:14:10 1.222 +++ loncom/interface/lonsearchcat.pm 2004/05/10 13:06:29 1.226 @@ -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.226 2004/05/10 13:06:29 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -231,24 +231,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 +417,14 @@ sub clean_up_environment { } } +sub hidden_field { + my ($name,$value) = @_; + if (! defined($value)) { + $value = $ENV{'form.'.$name}; + } + return ''.$/; +} + ###################################################################### ###################################################################### ## @@ -616,7 +619,8 @@ sub print_basic_search_form { ''. ''. - (' 'x2).$closebutton.(' 'x2).&viewoptions(). + (' 'x2).$closebutton.(' 'x2). + &viewoptions(). ''. ''.$/; $scrout .= ''.$/.''.''; @@ -959,7 +963,7 @@ Outputs: text for box with view options ###################################################################### ###################################################################### sub viewoptions { - my $scrout="\n".''; + my $scrout; if (! defined($ENV{'form.viewselect'})) { $ENV{'form.viewselect'}='detailed'; } @@ -1244,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'}) { @@ -1259,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); } } # @@ -1396,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="SELECT * FROM metadata WHERE ".join(" AND ",@queries); } elsif ($customquery) { $query = ''; } @@ -1480,34 +1484,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 +1570,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 +1870,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', @@ -2098,6 +2140,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 @@ -2281,13 +2327,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; } @@ -2308,32 +2354,16 @@ sub prev_next_buttons { my ($current_min,$show,$total,$parms) = @_; return '' if ($show eq 'all'); # No links if you get them all at once. # - # Create links - my $prev_min = $current_min - $show; - $prev_min = 1 if $prev_min < 1; - my $prevlink = - qq{}; - # - my $next_min = $current_min + $show; - $next_min = $current_min if ($next_min > $total); - my $nextlink = - qq{}; - my $reloadlink = - qq{}; - # - # Determine which parameters to pass - my $String = '[_1]prev[_2]   [_3]reload[_4]   [_5]next[_6]'; - if ($prev_min == $current_min) { - $String =~ s:\[_[12]\]::g; - } - if ($next_min == $current_min) { - $String =~ s:\[_[56]\]::g; - } - my $links = &mt($String, - $prevlink, '', - $reloadlink,'', - $nextlink, ''); - return $links; + # Create buttons + my $buttons = ''; + $buttons .= ' 'x3; + $buttons .= '$total_results); my $min = $ENV{'form.start'}; my $max; if ($ENV{'form.show'} eq 'all') { @@ -2407,14 +2444,19 @@ sub display_results { $max = $total_results if ($max > $total_results); } ## + ## Output form elements + $r->print(&hidden_field('table'). + &hidden_field('phase'). + &hidden_field('persistent_db_id'). + &hidden_field('start') + ); + ## ## Output links (if necessary) for 'prev' and 'next' pages. $r->print - ('
'. - &prev_next_buttons($min,$ENV{'form.show'},$total_results, - "table=".$ENV{'form.table'}. - "&phase=results". - "&persistent_db_id=".$ENV{'form.persistent_db_id'}) - ."
\n" + ('
'. + &prev_next_buttons($min,$ENV{'form.show'},$total_results). + ''. + &viewoptions().'
' ); if ($total_results == 0) { $r->print(''. @@ -2753,7 +2795,7 @@ SCRIPT $result.=< $bodytag -
+ $importbutton END @@ -2811,6 +2853,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 @@ -2832,10 +2909,9 @@ extra custom metadata to show. ###################################################################### sub detailed_citation_view { my ($prefix,%values) = @_; - my $icon= my $result; $result .= ''.$prefix. - ''. + ''.' '. ''.$values{'title'}."\n"; $result .= "

\n"; @@ -2843,6 +2919,9 @@ sub detailed_citation_view { ' '.$values{'owner'}.'
'; foreach my $field ( + { name=>'url', + translate => 'URL: [_1]', + special => 'url link',}, { name=>'subject', translate => 'Subject: [_1]',}, { name=>'keywords', @@ -2855,67 +2934,84 @@ sub detailed_citation_view { translate => 'Standards:[_1]',}, { name=>'copyrighttag', translate => 'Copyright/Distribution: [_1]',}, + { name=>'count', + format => "%d", + translate => 'Access Count: [_1]',}, { name=>'stdno', + format => "%d", translate => 'Number of Students: [_1]',}, { name=>'avetries', + format => "%.2f", translate => 'Average Tries: [_1]',}, { name=>'disc', + format => "%.2f", translate => 'Degree of Discrimination: [_1]',}, { name=>'difficulty', + format => "%.2f", translate => 'Degree of Difficulty: [_1]',}, { name=>'clear', + format => "%.2f", translate => 'Clear: [_1]',}, { name=>'depth', + format => "%.2f", translate => 'Depth: [_1]',}, { name=>'helpful', + format => "%.2f", translate => 'Helpful: [_1]',}, { name=>'correct', - translate => 'Correcy: [_1]',}, + format => "%.2f", + translate => 'Correct: [_1]',}, { name=>'technical', + format => "%.2f", translate => 'Technical: [_1]',}, + { name=>'comefrom_list', + type => 'list', + translate => 'Resources that lead up to this resource in maps',}, + { name=>'goto_list', + type => 'list', + translate => 'Resources that follow this resource in maps',}, + { name=>'sequsage_list', + type => 'list', + translate => 'Resources using or importing resource',}, ) { - $result.= &mt($field->{'translate'},$values{$field->{'name'}}). - "
\n"; + next if (! exists($values{$field->{'name'}}) || + $values{$field->{'name'}} eq ''); + if (exists($field->{'type'}) && $field->{'type'} eq 'list') { + $result .= ''.&mt($field->{'translate'}).'

    '; + foreach my $item (split(',',$values{$field->{'name'}})){ + $result .= '
  • '. + ''.$item.'
  • '; + } + $result .= '
'; + } elsif (exists($field->{'format'}) && $field->{'format'} ne ''){ + $result.= &mt($field->{'translate'}, + sprintf($field->{'format'}, + $values{$field->{'name'}})).'
'."\n"; + } else { + if ($field->{'special'} eq 'url link') { + $result.= + &mt($field->{'translate'}, + ''. + $values{$field->{'name'}}. + ''); + } else { + $result.= &mt($field->{'translate'}, + $values{$field->{'name'}}); + } + $result .= "
\n"; + } } - $result .= "

".$values{'extrashow'}. - '

'.$values{'shortabstract'}.'

'; - $result .= '
'."\n"; - return $result; -} - -###################################################################### -###################################################################### - -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; + $result .= "

"; + if (exists($values{'extrashow'}) && $values{'extrashow'} ne '') { + $result .= '

'.$values{'extrashow'}.'

'; } - 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; + if (exists($values{'shortabstract'}) && $values{'shortabstract'} ne '') { + $result .= '

'.$values{'shortabstract'}.'

'; } - return 0; -} - -sub evalfields { - return ('clear','technical','correct','helpful','depth'); + $result .= '
'."\n"; + return $result; } ###################################################################### @@ -2932,7 +3028,8 @@ sub summary_view { my ($prefix,%values) = @_; my $icon=&Apache::loncommon::icon($values{'url'}); my $result=<  +$values{'author'}
$values{'title'}
$values{'owner'} -- $values{'lastrevisiondate'}
@@ -2957,12 +3054,11 @@ END ###################################################################### sub compact_view { my ($prefix,%values) = @_; - my $icon=&Apache::loncommon::icon($values{'url'}); - my $result=< -$values{'title'} -$values{'author'}
-END + my $result = + $prefix.' '. + $values{'title'}.''.(' 'x2). + ''.$values{'author'}.'
'; return $result; }