--- loncom/interface/lonsearchcat.pm 2006/07/28 19:16:08 1.274
+++ 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.274 2006/07/28 19:16:08 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.' ';
+ }
}
}
#
@@ -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,7 +1682,12 @@ 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)');
@@ -1622,7 +1697,7 @@ sub parse_basic_search {
}
$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);
}
@@ -2176,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.
@@ -2185,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',
@@ -2199,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},],
@@ -2331,8 +2412,12 @@ 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
@@ -2407,6 +2492,7 @@ END
##
## Prepare for the big loop.
my $hitcountsum;
+ my %matches;
my $server;
my $status;
my $revise = &revise_button();
@@ -2461,7 +2547,7 @@ END
delete ($Server_status{$server});
next;
}
- $status=~s|/||g;
+ $status=~s|/||g;
my $datafile=$r->dir_config('lonDaemons').'/tmp/'.$status;
if (-e $datafile && ! -e "$datafile.end") {
&update_status($r,&mt('Receiving results from [_1]',$server));
@@ -2490,7 +2576,7 @@ END
next if (! $result);
#
# Parse the result.
- my %Fields = &parse_raw_result($result,$server);
+ my %Fields = &parse_raw_result($result,$server,$tabletype);
$Fields{'hostname'} = $server;
#
# Skip if external and we did not want that
@@ -2498,6 +2584,12 @@ END
# Skip based on copyright
next if (! ©right_check(\%Fields));
+ if ($area eq 'portfolio') {
+ next if (defined($matches{$Fields{'url'}}));
+ # Skip if inaccessible
+ next if (!&Apache::lonnet::portfolio_access($Fields{'url'}));
+ $matches{$Fields{'url'}} = 1;
+ }
#
# Store the result in the mysql database
my $result = &Apache::lonmysql::store_row($table,\%Fields);
@@ -2584,7 +2676,7 @@ Prints the results out for selection and
######################################################################
######################################################################
sub display_results {
- my ($r,$importbutton,$closebutton,$diropendb) = @_;
+ my ($r,$importbutton,$closebutton,$diropendb,$area) = @_;
my $connection = $r->connection;
$r->print(&search_results_header($importbutton,$closebutton));
##
@@ -2654,7 +2746,8 @@ sub display_results {
$r->print(&hidden_field('table').
&hidden_field('phase').
&hidden_field('persistent_db_id').
- &hidden_field('start')
+ &hidden_field('start').
+ &hidden_field('area')
);
#
# Build sorting selector
@@ -2675,6 +2768,16 @@ sub display_results {
{key =>'lowestgradelevel'},
{key =>'highestgradelevel'},
{key =>'standards',desc=>'Standards'},
+ );
+ if ($area eq 'portfolio') {
+ push(@fields,
+ (
+ {key => 'scope'},
+ {key => 'keynum'},
+ ));
+ } else {
+ push(@fields,
+ (
{key =>'count',desc=>'Number of accesses'},
{key =>'stdno',desc=>'Students Attempting'},
{key =>'avetries',desc=>'Average Number of Tries'},
@@ -2685,7 +2788,8 @@ sub display_results {
{key =>'correct',desc=>'Evaluation: Material is Correct'},
{key =>'helpful',desc=>'Evaluation: Material is Helpful'},
{key =>'depth',desc=>'Evaluation: Material has Depth'},
- );
+ ));
+ }
my %fieldnames = &Apache::lonmeta::fieldnames();
my @field_order;
foreach my $field_data (@fields) {
@@ -2702,7 +2806,13 @@ sub display_results {
my %sort_fields = map {$_->{'key'},$_->{'desc'}} @fields;
$sort_fields{'select_form_order'} = \@field_order;
$env{'form.sortorder'} = 'desc' if (! exists($env{'form.sortorder'}));
- $env{'form.sortfield'} = 'count' if (! exists($env{'form.sortfield'}));
+ if (! exists($env{'form.sortfield'})) {
+ if ($area eq 'portfolio') {
+ $env{'form.sortfield'} = 'owner';
+ } else {
+ $env{'form.sortfield'} = 'count';
+ }
+ }
if (! exists($env{'form.sortorder'})) {
if ($env{'form.sortfield'}=~/^(count|stdno|disc|clear|technical|correct|helpful)$/) {
$env{'form.sortorder'}='desc';
@@ -2766,12 +2876,16 @@ sub display_results {
my @Results = &Apache::lonmysql::get_rows($table,$sort_command);
##
## Loop through the results and output them.
+ my $tabletype = 'metadata';
+ if ($area eq 'portfolio') {
+ $tabletype = 'portfolio_search';
+ }
foreach my $row (@Results) {
if ($connection->aborted()) {
&cleanup();
return;
}
- my %Fields = %{&parse_row(@$row)};
+ my %Fields = %{&parse_row($tabletype,@$row)};
my $output="\n";
if (! defined($Fields{'title'}) || $Fields{'title'} eq '') {
$Fields{'title'} = 'Untitled';
@@ -2855,10 +2969,10 @@ Parse a row returned from the database.
######################################################################
######################################################################
sub parse_row {
- my @Row = @_;
+ my ($tabletype,@Row) = @_;
my %Fields;
if (! scalar(@Datatypes)) {
- &set_up_table_structure();
+ &set_up_table_structure($tabletype);
}
for (my $i=0;$i<=$#Row;$i++) {
$Fields{$Datatypes[$i]->{'name'}}=&unescape($Row[$i]);
@@ -2894,12 +3008,13 @@ The 'title' field is set to "Untitled" i
###########################################################
###########################################################
sub parse_raw_result {
- my ($result,$hostname) = @_;
+ my ($result,$hostname,$tabletype) = @_;
# conclude from self to others regarding fields
my %Fields=&LONCAPA::lonmetadata::metadata_col_to_hash
- (map {
+ ($tabletype,
+ map {
&unescape($_);
- } (split(/\,/,$result)) );
+ } (split(/\,/,$result)) );
return %Fields;
}
@@ -3200,7 +3315,7 @@ sub detailed_citation_view {
my ($prefix,%values) = @_;
my $result;
my $jumpurl=$values{'url'};
- $jumpurl=~s/^\/ext\//http\:\/\//;
+ $jumpurl=~s|^/ext/|http://|;
$result .= ''.$prefix.
' '.' '.
''.$jumpurl.' ';
} else {
$link=&Apache::lonhtmlcommon::crumbs($jumpurl,
@@ -3392,8 +3507,8 @@ sub compact_view {
my ($prefix,%values) = @_;
my $jumpurl=$values{'url'};
my $link;
- if ($jumpurl=~/^\/ext\//) {
- $jumpurl=~s/^\/ext\//http\:\/\//;
+ if ($jumpurl=~m|^/ext/|) {
+ $jumpurl=~s|^/ext/|http://|;
$link=''.$jumpurl.' ';
} else {
$link=&Apache::lonhtmlcommon::crumbs($jumpurl,
@@ -3432,7 +3547,7 @@ sub fielded_format_view {
my $icon=&Apache::loncommon::icon($values{'url'});
my %Translated = &Apache::lonmeta::fieldnames();
my $jumpurl=$values{'url'};
- $jumpurl=~s/^\/ext\//http\:\/\//;
+ $jumpurl=~s|^/ext/|http://|;
my $result=<