--- loncom/interface/lonsearchcat.pm 2006/06/13 14:42:24 1.269
+++ loncom/interface/lonsearchcat.pm 2006/09/26 15:24:18 1.276
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.269 2006/06/13 14:42:24 www Exp $
+# $Id: lonsearchcat.pm,v 1.276 2006/09/26 15:24:18 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -139,7 +139,7 @@ sub handler {
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['catalogmode','launch','acts','mode','form','element','pause',
'phase','persistent_db_id','table','start','show',
- 'cleargroupsort','titleelement']);
+ 'cleargroupsort','titleelement','area']);
##
## The following is a trick - we wait a few seconds if asked to so
## the daemon running the search can get ahead of the daemon
@@ -249,6 +249,9 @@ sub handler {
if (exists($env{'form.mode'})) {
$hidden_fields .= &hidden_field('mode');
}
+ if (exists($env{'form.area'})) {
+ $hidden_fields .= &hidden_field('area');
+ }
##
## Configure dynamic components of interface
##
@@ -318,7 +321,8 @@ END
} elsif ($env{'form.phase'} eq 'disp_adv') {
&print_advanced_search_form($r,$closebutton,$hidden_fields);
} elsif ($env{'form.phase'} eq 'results') {
- &display_results($r,$importbutton,$closebutton,$diropendb);
+ &display_results($r,$importbutton,$closebutton,$diropendb,
+ $env{'form.area'});
} elsif ($env{'form.phase'} =~ /^(sort|run_search)$/) {
my ($query,$customquery,$customshow,$libraries,$pretty_string) =
&get_persistent_data($persistent_db_file,
@@ -328,7 +332,7 @@ END
&print_sort_form($r,$pretty_string);
} elsif ($env{'form.phase'} eq 'run_search') {
&run_search($r,$query,$customquery,$customshow,
- $libraries,$pretty_string);
+ $libraries,$pretty_string,$env{'form.area'});
}
} elsif ($env{'form.phase'} eq 'course_search') {
&course_search($r);
@@ -358,7 +362,7 @@ END
$persistent_db_file);
#
# Set up table
- if (! defined(&create_results_table())) {
+ if (! defined(&create_results_table($env{'form.area'}))) {
my $errorstring=&Apache::lonmysql::get_error();
&Apache::lonnet::logthis('lonsearchcat.pm: Unable to create '.
'needed table. lonmysql error:'.
@@ -665,68 +669,13 @@ sub print_basic_search_form {
&Apache::lonhtmlcommon::breadcrumbs('Searching','Search_Basic',
$env{'form.catalogmode'} ne 'import');
my $scrout = &Apache::loncommon::start_page('Search').$bread_crumb;
+# Search form for resource space
if (&Apache::lonnet::allowed('bre',$env{'request.role.domain'})) {
- # Define interface components
- my $userelatedwords= ''.
- &mt('[_1] use related words',
- &Apache::lonhtmlcommon::checkbox
- ('related',$env{'form.related'},'related')).' ';
- my $onlysearchdomain=''.
- &mt('[_1] only search domain [_2]',
- &Apache::lonhtmlcommon::checkbox('domains',
- $env{'form.domains'},
- $r->dir_config('lonDefDomain')
- ),
- $r->dir_config('lonDefDomain')
- ).' ';
- my $inclext= ''.
- &mt('[_1] include external resources',
- &Apache::lonhtmlcommon::checkbox
- ('inclext',$env{'form.inclext'})).' ';
- my $adv_search_link =
- ''.&mt('Advanced Search').' ';
- #
- $scrout.='
';
+ $scrout .= &setup_basic_search($r,'res',$hidden_fields,$closebutton);
+ $scrout .= ' ';
}
+# Search form for accessible portfolio files
+ $scrout.= &setup_basic_search($r,'portfolio',$hidden_fields,$closebutton);
if ($env{'request.course.id'}) {
my %lt=&Apache::lonlocal::texthash('srch' => 'Search',
'header' => 'Course Search',
@@ -777,6 +726,75 @@ ENDENDCOURSE
$r->print($scrout);
return;
}
+
+sub setup_basic_search {
+ my ($r,$area,$hidden_fields,$closebutton) = @_;
+ # Define interface components
+ my %lt = &Apache::lonlocal::texthash (
+ res => 'LON-CAPA Catalog Search',
+ portfolio => 'Portfolio Search',
+ );
+ my ($userelatedwords,$onlysearchdomain,$inclext,$adv_search_link,$scrout);
+ $userelatedwords = ''.&mt('[_1] use related words',
+ &Apache::lonhtmlcommon::checkbox('related',$env{'form.related'},'related')).
+ ' ';
+ $onlysearchdomain = ''.&mt('[_1] only search domain [_2]',
+ &Apache::lonhtmlcommon::checkbox('domains',$env{'form.domains'},
+ $r->dir_config('lonDefDomain'))).
+ ' ';
+ if ($area eq 'res') {
+ $inclext= ''.&mt('[_1] include external resources',
+ &Apache::lonhtmlcommon::checkbox('inclext',$env{'form.inclext'})).
+ ' ';
+ }
+ $adv_search_link = ''.&mt('Advanced Search').' ';
+ #
+ $scrout.='';
+ return $scrout;
+}
+
######################################################################
######################################################################
@@ -871,20 +889,26 @@ ENDHEADER
&titlefield(&mt('Domains')).''.
&Apache::loncommon::domain_select('domains',
$env{'form.domains'},1).
- ''.
- &mt('[_1] include external resources',
- &Apache::lonhtmlcommon::checkbox
- ('inclext',$env{'form.inclext'})).' '.$/;
+ '';
+ if ($env{'form.area'} ne 'portfolio') {
+ $scrout .= &mt('[_1] include external resources',
+ &Apache::lonhtmlcommon::checkbox
+ ('inclext',$env{'form.inclext'})).' '
+ }
+ $scrout .= ''.$/;
#
# Misc metadata
- $scrout.=''.
- &titlefield(&mt('Copyright/Distribution')).' '.
- &Apache::lonmeta::selectbox('copyright',
- $env{'form.copyright'},
- \&Apache::loncommon::copyrightdescription,
- ( undef,
- &Apache::loncommon::copyrightids)
- ).' '.$/;
+ if ($env{'form.area'} ne 'portfolio') {
+ $scrout.=''.
+ &titlefield(&mt('Copyright/Distribution')).
+ ' '.
+ &Apache::lonmeta::selectbox('copyright',
+ $env{'form.copyright'},
+ \&Apache::loncommon::copyrightdescription,
+ ( undef,
+ &Apache::loncommon::copyrightids)
+ ).' '.$/;
+ }
$scrout.=''.
&titlefield(&mt('Language')).' '.
&Apache::lonmeta::selectbox('language',
@@ -892,62 +916,94 @@ ENDHEADER
\&Apache::loncommon::languagedescription,
('any',&Apache::loncommon::languageids)
).' ';
- $scrout .= "\n";
- #
- # Dynamic metadata
- $scrout .= ''.&mt('Problem Statistics').' ';
- $scrout .= "\n";
- $scrout .= ' '.&mt('Minimum').' '.
- ''.&mt('Maximum').' '."\n";
- foreach my $statistic
- ({ name=>'count',
- description=>'Network-wide number of accesses (hits)',},
- { name=>'stdno',
- description=>
- 'Total number of students who have worked on this problem',},
- { name => 'avetries',
- description=>'Average number of tries till solved',},
- { name => 'difficulty',
- description=>'Degree of difficulty',},
- { name => 'disc',
- description=>'Degree of discrimination'}) {
- $scrout .= ''.
- &titlefield(&mt($statistic->{'description'})).
- ' '.
- ' '.
- ' '.
- ' '.
- ' '.$/;
- }
$scrout .= "
\n";
- $scrout .= ''.&mt('Evaluation Data').' ';
- $scrout .= "\n";
- $scrout .= ' '.&mt('Minimum').' '.
- ''.&mt('Maximum').' '."\n";
- foreach my $evaluation
- ( { name => 'clear',
- description => 'Material presented in clear way'},
- { name =>'depth',
- description => 'Material covered with sufficient depth'},
- { name => 'helpful',
- description => 'Material is helpful'},
- { name => 'correct',
- description => 'Material appears to be correct'},
- { name => 'technical',
- description => 'Resource is technically correct'}){
- $scrout .= ''.
- &titlefield(&mt($evaluation->{'description'})).
- ' '.
- ' '.
- ' '.
- ' '.
- ' '.$/;
+
+
+ if ($env{'form.area'} eq 'portfolio') {
+ # Added fields
+ $scrout .= ''.&mt('Custom Metadata fields').' ';
+ $scrout .= "';
+ } else {
+ #
+ # Dynamic metadata
+ $scrout .= ''.&mt('Problem Statistics').' ';
+ $scrout .= "\n";
+ $scrout .= ' '.
+ &mt('Minimum').' '.''.
+ &mt('Maximum').' '."\n";
+ foreach my $statistic
+ ({ name=>'count',
+ description=>'Network-wide number of accesses (hits)',},
+ { name=>'stdno',
+ description=>
+ 'Total number of students who have worked on this problem',},
+ { name => 'avetries',
+ description=>'Average number of tries till solved',},
+ { name => 'difficulty',
+ description=>'Degree of difficulty',},
+ { name => 'disc',
+ description=>'Degree of discrimination'}) {
+ $scrout .= ''.
+ &titlefield(&mt($statistic->{'description'})).
+ ' '.
+ ' '.
+ ' '.$/;
+ }
+ $scrout .= "
\n";
+ $scrout .= ''.&mt('Evaluation Data').' ';
+ $scrout .= "\n";
}
- $scrout .= "
\n";
#
# Creation/Modification date limits
$scrout .= ''.&mt('Creation and Modification dates').' ';
@@ -1429,29 +1485,40 @@ sub parse_advanced_search {
&Apache::loncommon::copyrightdescription($env{'form.copyright'}).
" \n";
}
- #
- # Statistics
- foreach my $field (@StatsFields,@EvalFields) {
- my ($min,$max);
- if (exists($env{'form.'.$field.'_min'}) &&
- $env{'form.'.$field.'_min'} ne '') {
- $min = $env{'form.'.$field.'_min'};
- }
- if (exists($env{'form.'.$field.'_max'}) &&
- $env{'form.'.$field.'_max'} ne '') {
- $max = $env{'form.'.$field.'_max'};
- }
- next if (! defined($max) && ! defined($min));
- if (defined($min) && defined($max)) {
- ($min,$max) = sort {$a <=>$b} ($min,$max);
- }
- if (defined($min) && $min =~ /^(\d+\.\d+|\d+|\.\d+)$/) {
- push(@queries,'('.$field.'>'.$min.')');
- $pretty_search_string.=$font.$field.'>'.$min.' ';
- }
- if (defined($max) && $max =~ /^(\d+\.\d+|\d+|\.\d+)$/) {
- push(@queries,'('.$field.'<'.$max.')');
- $pretty_search_string.=$font.$field.'<'.$max.' ';
+ if ($env{'form.area'} eq 'portfolio') {
+ #
+ # Added metadata fields
+ for (my $i=0; $i<$env{'form.numaddedfields'} ; $i++) {
+ if (($env{'form.addedfield_'.$i} ne '') &&
+ ($env{'form.addedvalue_'.$i} ne '')) {
+ my $stuff = 1; #FIXME
+ }
+ }
+ } else {
+ #
+ # Statistics
+ foreach my $field (@StatsFields,@EvalFields) {
+ my ($min,$max);
+ if (exists($env{'form.'.$field.'_min'}) &&
+ $env{'form.'.$field.'_min'} ne '') {
+ $min = $env{'form.'.$field.'_min'};
+ }
+ if (exists($env{'form.'.$field.'_max'}) &&
+ $env{'form.'.$field.'_max'} ne '') {
+ $max = $env{'form.'.$field.'_max'};
+ }
+ next if (! defined($max) && ! defined($min));
+ if (defined($min) && defined($max)) {
+ ($min,$max) = sort {$a <=>$b} ($min,$max);
+ }
+ if (defined($min) && $min =~ /^(\d+\.\d+|\d+|\.\d+)$/) {
+ push(@queries,'('.$field.'>'.$min.')');
+ $pretty_search_string.=$font.$field.'>'.$min.' ';
+ }
+ if (defined($max) && $max =~ /^(\d+\.\d+|\d+|\.\d+)$/) {
+ push(@queries,'('.$field.'<'.$max.')');
+ $pretty_search_string.=$font.$field.'<'.$max.' ';
+ }
}
}
#
@@ -1540,12 +1607,12 @@ sub parse_domain_restrictions {
$domain_hash{$_}++;
}
if ($domain_hash{'any'}) {
- $pretty_domains_string = "In all LON-CAPA domains.";
+ $pretty_domains_string = &mt("in all LON-CAPA domains.");
} else {
if (@allowed_domains > 1) {
- $pretty_domains_string = "In LON-CAPA domains:";
+ $pretty_domains_string = &mt("in LON-CAPA domains:");
} else {
- $pretty_domains_string = "In LON-CAPA domain ";
+ $pretty_domains_string = &mt("in LON-CAPA domain ");
}
foreach (sort @allowed_domains) {
$pretty_domains_string .= "".$_." ";
@@ -1596,10 +1663,13 @@ sub parse_basic_search {
}
my $pretty_search_string=$search_string;
my @Queries;
- my $searchfield = 'concat_ws(" ",'.join(',',
- ('title','author','subject',
- 'notes','abstract','keywords')
- ).')';
+ my @fields = ('title','author','subject','notes','abstract','keywords');
+ my $searchfield;
+ if ($env{'form.area'} eq 'portfolio') {
+ $searchfield = 'concat_ws(" ",pm.'.join(',pm.',@fields).')';
+ } else {
+ $searchfield = 'concat_ws(" ",'.join(',',@fields).')';
+ }
my ($error,$SQLQuery) = &process_phrase_input($search_string,
$env{'form.related'},
$searchfield);
@@ -1612,14 +1682,22 @@ sub parse_basic_search {
#foreach my $q (@Queries) {
# &Apache::lonnet::logthis(' '.$q);
#}
- my $final_query = 'SELECT * FROM metadata WHERE '.join(" AND ",@Queries);
+ my $final_query;
+ if ($env{'form.area'} eq 'portfolio') {
+ $final_query = 'SELECT pm.*,pa.keynum,pa.scope FROM portfolio_metadata pm, portfolio_access pa WHERE (pm.url = pa.url AND (pa.start < NOW() AND (pa.end IS NULL OR pa.end > NOW())) AND '.join(" AND ",@Queries).')';
+ } else {
+ $final_query = 'SELECT * FROM metadata WHERE '.join(" AND ",@Queries);
+ }
#
+ if ($env{'form.related'}) {
+ $pretty_search_string.=' '.&mt('(including related words)');
+ }
if (defined($pretty_domains_string) && $pretty_domains_string ne '') {
$pretty_search_string .= ' '.$pretty_domains_string;
}
$pretty_search_string .= " \n";
$pretty_search_string =~ s:^ and ::;
- #&Apache::lonnet::logthis('simple search final query = '.$/.$final_query);
+ &Apache::lonnet::logthis('simple search final query = '.$/.$final_query);
return ($final_query,$pretty_search_string,
$libraries_to_query);
}
@@ -2104,7 +2182,7 @@ sub print_sort_form {
END
my $start_page = &Apache::loncommon::start_page('Results',$js,
- {'only_body' => 1});
+ {'no_title' => 1});
my $breadcrumbs=
&Apache::lonhtmlcommon::breadcrumbs('Searching','Searching',
$env{'form.catalogmode'} ne 'import');
@@ -2114,7 +2192,7 @@ $start_page
$breadcrumbs
END
@@ -2173,7 +2251,7 @@ my @Fullindicies;
Creates the table of search results by calling lonmysql. Stores the
table id in $env{'form.table'}
-Inputs: none.
+Inputs: search area - either res or portfolio
Returns: the identifier of the table on success, undef on error.
@@ -2182,8 +2260,9 @@ Returns: the identifier of the table on
######################################################################
######################################################################
sub set_up_table_structure {
+ my ($tabletype) = @_;
my ($datatypes,$fullindicies) =
- &LONCAPA::lonmetadata::describe_metadata_storage();
+ &LONCAPA::lonmetadata::describe_metadata_storage($tabletype);
# Copy the table description before modifying it...
@Datatypes = @{$datatypes};
unshift(@Datatypes,{name => 'id',
@@ -2196,7 +2275,12 @@ sub set_up_table_structure {
}
sub create_results_table {
- &set_up_table_structure();
+ my ($area) = @_;
+ if ($area eq 'portfolio') {
+ &set_up_table_structure('portfolio_search');
+ } else {
+ &set_up_table_structure('metadata');
+ }
my $table = &Apache::lonmysql::create_table
( { columns => \@Datatypes,
FULLTEXT => [{'columns' => \@Fullindicies},],
@@ -2328,14 +2412,18 @@ results into MySQL.
######################################################################
######################################################################
sub run_search {
- my ($r,$query,$customquery,$customshow,$serverlist,$pretty_string) = @_;
-
+ my ($r,$query,$customquery,$customshow,$serverlist,
+ $pretty_string,$area) = @_;
+ my $tabletype = 'metadata';
+ if ($area eq 'portfolio') {
+ $tabletype = 'portfolio_search';
+ }
my $connection = $r->connection;
#
# Print run_search header
#
my $start_page = &Apache::loncommon::start_page('Search Status',undef,
- {'only_body' => 1});
+ {'no_title' => 1});
my $breadcrumbs =
&Apache::lonhtmlcommon::breadcrumbs('Searching','Searching',
$env{'form.catalogmode'} ne 'import');
@@ -2343,7 +2431,7 @@ sub run_search {
$start_page
$breadcrumbs