version 1.164, 2003/02/03 04:02:17
|
version 1.172, 2003/03/17 18:35:51
|
Line 74 package Apache::lonsearchcat;
|
Line 74 package Apache::lonsearchcat;
|
|
|
# ------------------------------------------------- modules used by this module |
# ------------------------------------------------- modules used by this module |
use strict; |
use strict; |
use Apache::Constants qw(:common); |
use Apache::Constants qw(:common :http); |
use Apache::lonnet(); |
use Apache::lonnet(); |
use Apache::File(); |
use Apache::File(); |
use CGI qw(:standard); |
use CGI qw(:standard); |
Line 142 my %persistent_db;
|
Line 142 my %persistent_db;
|
my $hidden_fields; |
my $hidden_fields; |
my $bodytag; |
my $bodytag; |
|
|
|
# |
|
# For course search |
|
# |
|
my %alreadyseen; |
|
my $hashtied; |
|
my %hash; |
|
my $totalfound; |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
|
Line 338 END
|
Line 346 END
|
&run_search($r,$query,$customquery,$customshow, |
&run_search($r,$query,$customquery,$customshow, |
$libraries,$pretty_string); |
$libraries,$pretty_string); |
} |
} |
|
} elsif ($ENV{'form.phase'} eq 'course_search') { |
|
&course_search($r); |
} elsif(($ENV{'form.phase'} eq 'basic_search') || |
} elsif(($ENV{'form.phase'} eq 'basic_search') || |
($ENV{'form.phase'} eq 'adv_search')) { |
($ENV{'form.phase'} eq 'adv_search')) { |
$ENV{'form.searchmode'} = 'basic'; |
$ENV{'form.searchmode'} = 'basic'; |
Line 396 END
|
Line 406 END
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
|
|
sub course_search { |
|
my $r=shift; |
|
my $bodytag=&Apache::loncommon::bodytag('Course Search'); |
|
my $pretty_search_string = '<b>'.$ENV{'form.courseexp'}.'</b>'; |
|
my $search_string = $ENV{'form.courseexp'}; |
|
my @New_Words; |
|
if ($ENV{'form.crsrelated'}) { |
|
($search_string,@New_Words) = &related_version($ENV{'form.courseexp'}); |
|
if (@New_Words) { |
|
$pretty_search_string .= " with related words: <b>@New_Words</b>."; |
|
} else { |
|
$pretty_search_string .= " with no related words."; |
|
} |
|
} |
|
my $fulltext=$ENV{'form.crsfulltext'}; |
|
my @allwords=($search_string,@New_Words); |
|
$totalfound=0; |
|
$r->print('<html><head><title>LON-CAPA Course Search</title></head>'. |
|
$bodytag.$pretty_search_string); |
|
$r->rflush(); |
|
# ======================================================= Go through the course |
|
$hashtied=0; |
|
undef %alreadyseen; |
|
%alreadyseen=(); |
|
my $c=$r->connection; |
|
&tiehash(); |
|
foreach (keys %hash) { |
|
if ($c->aborted()) { last; } |
|
if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) { |
|
&checkonthis($r,$hash{$_},0,$hash{'title_'.$1},$fulltext,@allwords); |
|
} |
|
} |
|
&untiehash(); |
|
unless ($totalfound) { |
|
$r->print('<p>No resources found.</p>'); |
|
} |
|
# =================================================== Done going through course |
|
$r->print('</body></html>'); |
|
} |
|
|
|
# ---------------------------------------------------------------- tie the hash |
|
|
|
sub tiehash { |
|
$hashtied=0; |
|
if ($ENV{'request.course.fn'}) { |
|
if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db", |
|
&GDBM_READER(),0640)) { |
|
$hashtied=1; |
|
} |
|
} |
|
} |
|
|
|
sub untiehash { |
|
if ($hashtied) { untie %hash; } |
|
$hashtied=0; |
|
} |
|
|
|
# =============================== This pulls up a resource and its dependencies |
|
|
|
sub checkonthis { |
|
my ($r,$url,$level,$title,$fulltext,@allwords)=@_; |
|
$alreadyseen{$url}=1; |
|
$r->rflush(); |
|
my $result=&Apache::lonnet::metadata($url,'title').' '. |
|
&Apache::lonnet::metadata($url,'subject').' '. |
|
&Apache::lonnet::metadata($url,'abstract').' '. |
|
&Apache::lonnet::metadata($url,'keywords'); |
|
if (($url) && ($fulltext)) { |
|
$result.=&Apache::lonnet::ssi_body($url); |
|
} |
|
$result=~s/\s+/ /gs; |
|
my $applies=0; |
|
foreach (@allwords) { |
|
if ($_=~/\w/) { |
|
if ($result=~/$_/si) { |
|
$applies++; |
|
} |
|
} |
|
} |
|
# Does this resource apply? |
|
if ($applies) { |
|
$r->print('<br />'); |
|
for (my $i=0;$i<=$level*5;$i++) { |
|
$r->print(' '); |
|
} |
|
$r->print('<a href="'.$url.'" target="cat">'. |
|
($title?$title:$url).'</a><br />'); |
|
$totalfound++; |
|
} elsif ($fulltext) { |
|
$r->print(' .'); |
|
} |
|
$r->rflush(); |
|
# Check also the dependencies of this one |
|
my $dependencies= |
|
&Apache::lonnet::metadata($url,'dependencies'); |
|
foreach (split(/\,/,$dependencies)) { |
|
if (($_=~/^\/res\//) && (!$alreadyseen{$_})) { |
|
&checkonthis($r,$_,$level+1,'',$fulltext,@allwords); |
|
} |
|
} |
|
} |
|
|
|
###################################################################### |
|
###################################################################### |
|
|
=pod |
=pod |
|
|
=item &print_basic_search_form() |
=item &print_basic_search_form() |
Line 409 Returns a scalar which holds html for th
|
Line 524 Returns a scalar which holds html for th
|
|
|
sub print_basic_search_form{ |
sub print_basic_search_form{ |
my ($r,$closebutton) = @_; |
my ($r,$closebutton) = @_; |
my $bodytag=&Apache::loncommon::bodytag('Catalog Search'); |
my $bodytag=&Apache::loncommon::bodytag('Search'); |
my $scrout=<<"ENDDOCUMENT"; |
my $scrout=<<"ENDDOCUMENT"; |
<html> |
<html> |
<head> |
<head> |
Line 423 sub print_basic_search_form{
|
Line 538 sub print_basic_search_form{
|
</script> |
</script> |
</head> |
</head> |
$bodytag |
$bodytag |
|
ENDDOCUMENT |
|
if (&Apache::lonnet::allowed('bre',$ENV{'request.role.domain'})) { |
|
$scrout.=(<<ENDDOCUMENT); |
|
<h1>Catalog Search</h1> |
<form method="post" action="/adm/searchcat"> |
<form method="post" action="/adm/searchcat"> |
<input type="hidden" name="phase" value="basic_search" /> |
<input type="hidden" name="phase" value="basic_search" /> |
$hidden_fields |
$hidden_fields |
Line 460 END
|
Line 579 END
|
per page. |
per page. |
</p> |
</p> |
</form> |
</form> |
|
ENDDOCUMENT |
|
if ($ENV{'request.course.id'}) { $scrout.='<hr />'; } |
|
} |
|
if ($ENV{'request.course.id'}) { |
|
$scrout.=(<<ENDCOURSESEARCH); |
|
<h1>Course Search</h1> |
|
<form method="post" action="/adm/searchcat"> |
|
<input type="hidden" name="phase" value="course_search" /> |
|
$hidden_fields |
|
<p> |
|
Enter terms or phrases, then press SEARCH below. |
|
</p> |
|
<p> |
|
<table> |
|
<tr><td> |
|
ENDCOURSESEARCH |
|
$scrout.=' '.&simpletextfield('courseexp',$ENV{'form.courseexp'},40); |
|
my $crscheckbox = &simplecheckbox('crsfulltext',$ENV{'form.crsfulltext'}); |
|
my $relcheckbox = &simplecheckbox('crsrelated',$ENV{'form.crsrelated'}); |
|
$scrout.=(<<ENDENDCOURSE); |
|
</td></tr> |
|
<tr><td>$relcheckbox use related words</td><td></td></tr> |
|
<tr><td>$crscheckbox fulltext search (time consuming)</td><td></td></tr> |
|
</table><p> |
|
<input type="submit" name="coursesubmit" value='SEARCH' /> |
|
</p> |
|
ENDENDCOURSE |
|
} |
|
$scrout.=(<<ENDDOCUMENT); |
</body> |
</body> |
</html> |
</html> |
ENDDOCUMENT |
ENDDOCUMENT |
Line 570 ENDHEADER
|
Line 718 ENDHEADER
|
my @domains =&Apache::loncommon::get_domains(); |
my @domains =&Apache::loncommon::get_domains(); |
# adjust the size of the select box |
# adjust the size of the select box |
my $size = 4; |
my $size = 4; |
my $size = (scalar @domains < ($size - 1) ? scalar @domains + 1 : $size); |
$size = (scalar @domains < ($size - 1) ? scalar @domains + 1 : $size); |
$scrout.="\n".'<font color="#800000" face="helvetica"><b>'. |
$scrout.="\n".'<font color="#800000" face="helvetica"><b>'. |
'DOMAINS</b></font><br />'. |
'DOMAINS</b></font><br />'. |
'<select name="domains" size="'.$size.'" multiple>'."\n". |
'<select name="domains" size="'.$size.'" multiple>'."\n". |
Line 585 ENDHEADER
|
Line 733 ENDHEADER
|
#---------------------------------------------------------------- |
#---------------------------------------------------------------- |
$scrout.=&selectbox('Limit by language','language', |
$scrout.=&selectbox('Limit by language','language', |
$ENV{'form.language'},'any','Any Language', |
$ENV{'form.language'},'any','Any Language', |
\&{Apache::loncommon::languagedescription}, |
\&Apache::loncommon::languagedescription, |
(&Apache::loncommon::languageids), |
(&Apache::loncommon::languageids), |
); |
); |
# ------------------------------------------------ Compute date selection boxes |
# ------------------------------------------------ Compute date selection boxes |
Line 632 LASTREVISIONDATEEND
|
Line 780 LASTREVISIONDATEEND
|
$scrout.=&selectbox('Limit by copyright/distribution','copyright', |
$scrout.=&selectbox('Limit by copyright/distribution','copyright', |
$ENV{'form.copyright'}, |
$ENV{'form.copyright'}, |
'any','Any copyright/distribution', |
'any','Any copyright/distribution', |
\&{Apache::loncommon::copyrightdescription}, |
\&Apache::loncommon::copyrightdescription, |
(&Apache::loncommon::copyrightids), |
(&Apache::loncommon::copyrightids), |
); |
); |
# ------------------------------------------- Compute customized metadata field |
# ------------------------------------------- Compute customized metadata field |
Line 1750 the following format:
|
Line 1898 the following format:
|
|
|
=cut |
=cut |
|
|
## |
##################################################################### |
## Restrictions: |
##################################################################### |
## columns of type 'text' and 'blob' cannot have defaults. |
|
## columns of type 'enum' cannot be used for FULLTEXT. |
my @Datatypes = |
## |
( { name => 'id', |
my @DataOrder = qw/id title author subject url keywords version notes |
type => 'MEDIUMINT', |
abstract mime lang owner copyright creationdate lastrevisiondate hostname/; |
restrictions => 'UNSIGNED NOT NULL', |
|
primary_key => 'yes', |
my %Datatypes = |
auto_inc => 'yes' }, |
( id =>{ type => 'MEDIUMINT', |
{ name => 'title', type=>'TEXT'}, |
restrictions => 'UNSIGNED NOT NULL', |
{ name => 'author', type=>'TEXT'}, |
primary_key => 'yes', |
{ name => 'subject', type=>'TEXT'}, |
auto_inc => 'yes' |
{ name => 'url', type=>'TEXT', restrictions => 'NOT NULL' }, |
}, |
{ name => 'keywords', type=>'TEXT'}, |
title =>{ type=>'TEXT'}, |
{ name => 'version', type=>'TEXT'}, |
author =>{ type=>'TEXT'}, |
{ name => 'notes', type=>'TEXT'}, |
subject =>{ type=>'TEXT'}, |
{ name => 'abstract', type=>'TEXT'}, |
url =>{ type=>'TEXT', |
{ name => 'mime', type=>'TEXT'}, |
restrictions => 'NOT NULL' }, |
{ name => 'lang', type=>'TEXT'}, |
keywords =>{ type=>'TEXT'}, |
{ name => 'owner', type=>'TEXT'}, |
version =>{ type=>'TEXT'}, |
{ name => 'copyright', type=>'TEXT'}, |
notes =>{ type=>'TEXT'}, |
{ name => 'hostname', type=>'TEXT'}, |
abstract =>{ type=>'TEXT'}, |
|
mime =>{ type=>'TEXT'}, |
|
lang =>{ type=>'TEXT'}, |
|
owner =>{ type=>'TEXT'}, |
|
copyright =>{ type=>'TEXT'}, |
|
hostname =>{ type=>'TEXT'}, |
|
#-------------------------------------------------- |
#-------------------------------------------------- |
creationdate =>{ type=>'DATETIME'}, |
{ name => 'creationdate', type=>'DATETIME'}, |
lastrevisiondate =>{ type=>'DATETIME'}, |
{ name => 'lastrevisiondate', type=>'DATETIME'}, |
#-------------------------------------------------- |
#-------------------------------------------------- |
); |
); |
|
|
Line 1808 Returns: the identifier of the table on
|
Line 1950 Returns: the identifier of the table on
|
###################################################################### |
###################################################################### |
sub create_results_table { |
sub create_results_table { |
my $table = &Apache::lonmysql::create_table |
my $table = &Apache::lonmysql::create_table |
( { columns => \%Datatypes, |
( { columns => \@Datatypes, |
column_order => \@DataOrder, |
FULLTEXT => [{'columns' => \@Fullindicies},], |
fullindex => \@Fullindicies, |
|
} ); |
} ); |
if (defined($table)) { |
if (defined($table)) { |
$ENV{'form.table'} = $table; |
$ENV{'form.table'} = $table; |
Line 2336 sub parse_row {
|
Line 2477 sub parse_row {
|
my @Row = @_; |
my @Row = @_; |
my %Fields; |
my %Fields; |
for (my $i=0;$i<=$#Row;$i++) { |
for (my $i=0;$i<=$#Row;$i++) { |
$Fields{$DataOrder[$i]}=&Apache::lonnet::unescape($Row[$i]); |
$Fields{$Datatypes[$i]->{'name'}}=&Apache::lonnet::unescape($Row[$i]); |
} |
} |
$Fields{'language'} = |
$Fields{'language'} = |
&Apache::loncommon::languagedescription($Fields{'lang'}); |
&Apache::loncommon::languagedescription($Fields{'lang'}); |
Line 2968 sub cleanup {
|
Line 3109 sub cleanup {
|
&Apache::lonnet::logthis('Failed cleanup searchcat: groupsearch_db'); |
&Apache::lonnet::logthis('Failed cleanup searchcat: groupsearch_db'); |
} |
} |
} |
} |
|
&untiehash(); |
&Apache::lonmysql::disconnect_from_db(); |
&Apache::lonmysql::disconnect_from_db(); |
} |
} |
|
|