version 1.146, 2002/07/29 21:53:57
|
version 1.148, 2002/07/30 20:08:04
|
Line 191 sub handler {
|
Line 191 sub handler {
|
## this once, so the pause indicator is deleted |
## this once, so the pause indicator is deleted |
## |
## |
if (exists($ENV{'form.pause'})) { |
if (exists($ENV{'form.pause'})) { |
sleep(5); |
sleep(3); |
delete($ENV{'form.pause'}); |
delete($ENV{'form.pause'}); |
} |
} |
## |
## |
Line 204 sub handler {
|
Line 204 sub handler {
|
# set the name of the persistent database |
# set the name of the persistent database |
# $ENV{'form.persistent_db_id'} can only have digits in it. |
# $ENV{'form.persistent_db_id'} can only have digits in it. |
if (! exists($ENV{'form.persistent_db_id'}) || |
if (! exists($ENV{'form.persistent_db_id'}) || |
$ENV{'form.persistent_db_id'} =~ /\D/ ) { |
($ENV{'form.persistent_db_id'} =~ /\D/) || |
|
($ENV{'form.launch'} eq '1')) { |
$ENV{'form.persistent_db_id'} = time; |
$ENV{'form.persistent_db_id'} = time; |
} |
} |
my $persistent_db_file = "/home/httpd/perl/tmp/". |
my $persistent_db_file = "/home/httpd/perl/tmp/". |
Line 212 sub handler {
|
Line 213 sub handler {
|
'_'.&Apache::lonnet::escape($ENV{'user.name'}). |
'_'.&Apache::lonnet::escape($ENV{'user.name'}). |
'_'.$ENV{'form.persistent_db_id'}.'_persistent_search.db'; |
'_'.$ENV{'form.persistent_db_id'}.'_persistent_search.db'; |
## |
## |
&get_persistent_form_data($r,$persistent_db_file); |
if (! &get_persistent_form_data($r,$persistent_db_file)) { |
|
&write_status($r,"Unable to get persistent data"); |
|
} |
## |
## |
## Clear out old values from groupsearch database |
## Clear out old values from groupsearch database |
## |
## |
untie %groupsearch_db if (tied(%groupsearch_db)); |
untie %groupsearch_db if (tied(%groupsearch_db)); |
if ($ENV{'form.launch'} eq '1') { |
if ($ENV{'form.launch'} eq '1') { |
if (tie(%groupsearch_db,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) { |
if (tie(%groupsearch_db,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) { |
&start_fresh_session(); |
&start_fresh_session(); |
untie %groupsearch_db; |
untie %groupsearch_db; |
} else { |
} else { |
Line 280 END
|
Line 283 END
|
($ENV{'form.phase'} eq 'adv_search')) { |
($ENV{'form.phase'} eq 'adv_search')) { |
# Set up table |
# Set up table |
if (! defined(&create_results_table())) { |
if (! defined(&create_results_table())) { |
# Unable to make table to store results in. |
$r->print(<<END); |
# Definately abort search. |
<html><head><title>Search Error</title></head> |
|
<body> |
|
Unable to create table in which to store search results. |
|
The search has been aborted. |
|
</body> |
|
</html> |
|
END |
|
return OK; |
} |
} |
|
delete($ENV{'form.launch'}); |
if (! &make_form_data_persistent($r,$persistent_db_file)) { |
if (! &make_form_data_persistent($r,$persistent_db_file)) { |
# Unable to store persistent data. |
$r->print(<<END); |
# Probably should bail out. |
<html><head><title>Search Error</title></head> |
|
<body> |
|
Unable to properly store search information. The search has been aborted. |
|
</body> |
|
</html> |
|
END |
|
return OK; |
} |
} |
# |
# |
# We are running a search |
# We are running a search |
Line 299 END
|
Line 316 END
|
= &parse_advanced_search($r,$closebutton); |
= &parse_advanced_search($r,$closebutton); |
return OK if (! defined($query)); |
return OK if (! defined($query)); |
} |
} |
&write_status($r,"query = $query"); |
|
&write_status($r,"customquery = $customquery"); |
|
&write_status($r,"customshow = $customshow"); |
|
&write_status($r,"libraries = $libraries"); |
|
&write_status($r,"pretty_string = $pretty_string"); |
|
&make_persistent($r, |
&make_persistent($r, |
{ query => $query, |
{ query => $query, |
customquery => $customquery, |
customquery => $customquery, |
Line 608 to them.
|
Line 620 to them.
|
sub get_persistent_form_data { |
sub get_persistent_form_data { |
my $r = shift; |
my $r = shift; |
my $filename = shift; |
my $filename = shift; |
return undef if (! -e $filename); |
return 0 if (! -e $filename); |
return undef if (! tie(%persistent_db,'GDBM_File',$filename, |
return undef if (! tie(%persistent_db,'GDBM_File',$filename, |
&GDBM_READER,0640)); |
&GDBM_READER(),0640)); |
# |
# |
# These make sure we do not get array references printed out as 'values'. |
# These make sure we do not get array references printed out as 'values'. |
my %arrays_allowed = ('form.category'=>1,'form.domains'=>1); |
my %arrays_allowed = ('form.category'=>1,'form.domains'=>1); |
Line 637 sub get_persistent_form_data {
|
Line 649 sub get_persistent_form_data {
|
$ENV{$name} = $values[0] if ($values[0]); |
$ENV{$name} = $values[0] if ($values[0]); |
} |
} |
} |
} |
&write_status($r,"Reconstructed $name = $ENV{$name}"); |
|
} |
} |
untie (%persistent_db); |
untie (%persistent_db); |
return 1; |
return 1; |
Line 668 sub get_persistent_data {
|
Line 679 sub get_persistent_data {
|
my @Values; # Return array |
my @Values; # Return array |
return undef if (! -e $filename); |
return undef if (! -e $filename); |
return undef if (! tie(%persistent_db,'GDBM_File',$filename, |
return undef if (! tie(%persistent_db,'GDBM_File',$filename, |
&GDBM_READER,0640)); |
&GDBM_READER(),0640)); |
foreach my $name (@Vars) { |
foreach my $name (@Vars) { |
if (! exists($persistent_db{$name})) { |
if (! exists($persistent_db{$name})) { |
push @Values, undef; |
push @Values, undef; |
Line 709 sub make_persistent {
|
Line 720 sub make_persistent {
|
my %save = %{shift()}; |
my %save = %{shift()}; |
my $filename = shift; |
my $filename = shift; |
return undef if (! tie(%persistent_db,'GDBM_File', |
return undef if (! tie(%persistent_db,'GDBM_File', |
$filename,&GDBM_WRCREAT,0640)); |
$filename,&GDBM_WRCREAT(),0640)); |
foreach my $name (keys(%save)) { |
foreach my $name (keys(%save)) { |
next if (! exists($save{$name})); |
next if (! exists($save{$name})); |
next if (! defined($save{$name}) || $save{$name} eq ''); |
next if (! defined($save{$name}) || $save{$name} eq ''); |
Line 717 sub make_persistent {
|
Line 728 sub make_persistent {
|
# We handle array references, but not recursively. |
# We handle array references, but not recursively. |
my $store = join(',', map { &Apache::lonnet::escape($_); } @values ); |
my $store = join(',', map { &Apache::lonnet::escape($_); } @values ); |
$persistent_db{$name} = $store; |
$persistent_db{$name} = $store; |
&write_status($r,"Stored $name = $store"); |
|
} |
} |
untie(%persistent_db); |
untie(%persistent_db); |
return 1; |
return 1; |
Line 1527 the following format:
|
Line 1537 the following format:
|
## columns of type 'enum' cannot be used for FULLTEXT. |
## columns of type 'enum' cannot be used for FULLTEXT. |
## |
## |
my @DataOrder = qw/id title author subject url keywords version notes |
my @DataOrder = qw/id title author subject url keywords version notes |
abstract mime lang owner copyright creationdate lastrevisiondate hostname |
abstract mime lang owner copyright creationdate lastrevisiondate hostname/; |
idx_title idx_author idx_subject idx_abstract idx_mime idx_language |
|
idx_owner idx_copyright/; |
|
|
|
my %Datatypes = |
my %Datatypes = |
( id =>{ type => 'INT', |
( id =>{ type => 'INT', |
Line 1555 my %Datatypes =
|
Line 1563 my %Datatypes =
|
creationdate =>{ type=>'DATETIME'}, |
creationdate =>{ type=>'DATETIME'}, |
lastrevisiondate =>{ type=>'DATETIME'}, |
lastrevisiondate =>{ type=>'DATETIME'}, |
#-------------------------------------------------- |
#-------------------------------------------------- |
idx_title =>{ type=>'FULLTEXT', target=>'title'}, |
|
idx_author =>{ type=>'FULLTEXT', target=>'author'}, |
|
idx_subject =>{ type=>'FULLTEXT', target=>'subject'}, |
|
idx_abstract =>{ type=>'FULLTEXT', target=>'abstract'}, |
|
idx_mime =>{ type=>'FULLTEXT', target=>'mime'}, |
|
idx_language =>{ type=>'FULLTEXT', target=>'lang'}, |
|
idx_owner =>{ type=>'FULLTEXT', target=>'owner'}, |
|
idx_copyright =>{ type=>'FULLTEXT', target=>'copyright'}, |
|
); |
); |
|
|
|
my @Fullindicies = |
|
qw/title author subject abstract mime language owner copyright/; |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
|
Line 1587 sub create_results_table {
|
Line 1590 sub create_results_table {
|
my $table = &Apache::lonmysql::create_table |
my $table = &Apache::lonmysql::create_table |
( { columns => \%Datatypes, |
( { columns => \%Datatypes, |
column_order => \@DataOrder, |
column_order => \@DataOrder, |
|
fullindex => \@Fullindicies, |
} ); |
} ); |
if (defined($table)) { |
if (defined($table)) { |
$ENV{'form.table'} = $table; |
$ENV{'form.table'} = $table; |
Line 1594 sub create_results_table {
|
Line 1598 sub create_results_table {
|
} |
} |
return undef; # Error... |
return undef; # Error... |
} |
} |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
|
Line 1619 sub write_status {
|
Line 1624 sub write_status {
|
|
|
=pod |
=pod |
|
|
|
=item Search Status update functions |
|
|
|
Each of the following functions changes the values of one of the |
|
input fields used to display the search status to the user. |
|
|
|
=over 4 |
|
|
|
=item &update_count_status() |
|
|
|
=item &update_contact_status() |
|
|
|
=item &update_read_status() |
|
|
|
=back |
|
|
|
=cut |
|
|
|
###################################################################### |
|
###################################################################### |
|
sub update_count_status { |
|
my ($r,$text) = @_; |
|
$text =~ s/\'/\\\'/g; |
|
$r->print |
|
("<script>document.statusform.count.value = ' $text'</script>\n"); |
|
$r->rflush(); |
|
} |
|
|
|
sub update_contact_status { |
|
my ($r,$text) = @_; |
|
$text =~ s/\'/\\\'/g; |
|
$r->print |
|
("<script>document.statusform.c_server.value = ' $text'</script>\n"); |
|
$r->rflush(); |
|
} |
|
|
|
sub update_read_status { |
|
my ($r,$text) = @_; |
|
$text =~ s/\'/\\\'/g; |
|
$r->print |
|
("<script>document.statusform.r_server.value = ' $text'</script>\n"); |
|
$r->rflush(); |
|
} |
|
|
|
###################################################################### |
|
###################################################################### |
|
|
|
=pod |
|
|
=item &run_search |
=item &run_search |
|
|
=cut |
=cut |
Line 1627 sub write_status {
|
Line 1680 sub write_status {
|
###################################################################### |
###################################################################### |
sub run_search { |
sub run_search { |
my ($r,$query,$customquery,$customshow,$serverlist,$pretty_string) = @_; |
my ($r,$query,$customquery,$customshow,$serverlist,$pretty_string) = @_; |
|
my $c = $r->connection; |
# |
# |
# Timing variables |
# Timing variables |
# |
# |
Line 1636 sub run_search {
|
Line 1690 sub run_search {
|
# Print run_search header |
# Print run_search header |
# |
# |
$r->print("<html><head><title>Search Status</title></head><body>"); |
$r->print("<html><head><title>Search Status</title></head><body>"); |
$r->print("Search: ".$pretty_string."<br />\n"); |
$r->print("Search: ".$pretty_string."\n"); |
$r->rflush(); |
$r->rflush(); |
# |
# |
# Determine the servers we need to contact. |
# Determine the servers we need to contact. |
Line 1649 sub run_search {
|
Line 1703 sub run_search {
|
} |
} |
my %Server_status; |
my %Server_status; |
my $table =$ENV{'form.table'}; |
my $table =$ENV{'form.table'}; |
if (! defined($table)) { |
if (! defined($table) || $table eq '') { |
# What do I do now? Print out an error page. |
$r->print("Unable to determine table id to store search results in.". |
&Apache::lonnet::logthis("lonmysql attempted to create a table ". |
"The search has been aborted.</body></html>"); |
"and this was the result:". |
return; |
|
} |
|
my $table_status = &Apache::lonmysql::check_table($table); |
|
if (! defined($table_status)) { |
|
$r->print("Unable to determine status of table.</body></html>"); |
|
&Apache::lonnet::logthis("Bogus table id of $table for ". |
|
"$ENV{'user.name'} @ $ENV{'user.domain'}"); |
|
&Apache::lonnet::logthis("lonmysql error = ". |
&Apache::lonmysql::get_error()); |
&Apache::lonmysql::get_error()); |
$r->print("An internal error occured with the database.<br />". |
return; |
"The error has been logged, but you should probably alert". |
} |
" your system administrator."); |
if (! $table_status) { |
|
$r->print("The table id,$table, we tried to use is invalid.". |
|
"The search has been aborted.</body></html>"); |
return; |
return; |
} |
} |
## |
## |
Line 1665 sub run_search {
|
Line 1728 sub run_search {
|
my $hitcountsum; |
my $hitcountsum; |
my $server; |
my $server; |
my $status; |
my $status; |
|
$r->print(<<END); |
|
<form name="statusform" action="" method="post"> |
|
<table> |
|
<tr><th>Contacting</th><th>Receiving</th><th>Total Matches</th></tr> |
|
<tr> |
|
<td><input type="text" name="c_server" value="" size="15" /></td> |
|
<td><input type="text" name="r_server" value="" size="15" /></td> |
|
<td><input type="text" name="count" value="" size="10" /></td> |
|
</tr> |
|
</table> |
|
</form> |
|
END |
|
$r->rflush(); |
while ((time - $starttime < $max_time) && |
while ((time - $starttime < $max_time) && |
((@Servers_to_contact) || keys(%Server_status))) { |
((@Servers_to_contact) || keys(%Server_status))) { |
# Send out a search request if it needs to be done. |
# Send out a search request if it needs to be done. |
Line 1675 sub run_search {
|
Line 1751 sub run_search {
|
$customshow,[$server]); |
$customshow,[$server]); |
($server) = keys(%$reply); |
($server) = keys(%$reply); |
$Server_status{$server} = $reply->{$server}; |
$Server_status{$server} = $reply->{$server}; |
# $r->print("Contacted:$server:reply:$Server_status{$server}"); |
&update_contact_status($r,$server); |
if ($max_time - (time - $starttime) < 20) { |
|
# If there are less than 20 seconds to go in the search, |
|
# give the newly contacted servers 20 more seconds to |
|
# respond.... |
|
$max_time += 20; |
|
} |
|
} else { |
} else { |
|
&update_contact_status($r,'none'); |
sleep(1); # wait a sec. to give time for files to be written |
sleep(1); # wait a sec. to give time for files to be written |
} |
} |
while (my ($server,$status) = each(%Server_status)) { |
while (my ($server,$status) = each(%Server_status)) { |
|
last if ($c->aborted()); |
if ($status eq 'con_lost') { |
if ($status eq 'con_lost') { |
delete ($Server_status{$server}); |
delete ($Server_status{$server}); |
# $r->print("server $server is not responding."); |
|
next; |
next; |
} |
} |
$status=~/^([\.\w]+)$/; |
$status=~/^([\.\w]+)$/; |
my $datafile=$r->dir_config('lonDaemons').'/tmp/'.$1; |
my $datafile=$r->dir_config('lonDaemons').'/tmp/'.$1; |
if (-e $datafile && ! -e "$datafile.end") { |
if (-e $datafile && ! -e "$datafile.end") { |
# Let the user know we are receiving data from the server |
|
# $r->print("$server:Receiving file"); |
|
next; |
next; |
} |
} |
|
last if ($c->aborted()); |
if (-e "$datafile.end") { |
if (-e "$datafile.end") { |
|
&update_read_status($r,$server); |
if (-z "$datafile") { |
if (-z "$datafile") { |
delete($Server_status{$server}); |
delete($Server_status{$server}); |
next; |
next; |
Line 1714 sub run_search {
|
Line 1785 sub run_search {
|
} |
} |
# Read in the whole file. |
# Read in the whole file. |
while (my $result = <$fh>) { |
while (my $result = <$fh>) { |
|
last if ($c->aborted()); |
# handle custom fields? Someday we will! |
# handle custom fields? Someday we will! |
chomp($result); |
chomp($result); |
next unless $result; |
next unless $result; |
Line 1728 sub run_search {
|
Line 1800 sub run_search {
|
} |
} |
# $r->print(&Apache::lonmysql::get_debug()); |
# $r->print(&Apache::lonmysql::get_debug()); |
$hitcountsum ++; |
$hitcountsum ++; |
|
&update_count_status($r,$hitcountsum) if ($hitcountsum % 50 == 0); |
} # End of foreach (@results) |
} # End of foreach (@results) |
$fh->close(); |
$fh->close(); |
# $server is only deleted if the results file has been |
# $server is only deleted if the results file has been |
Line 1736 sub run_search {
|
Line 1809 sub run_search {
|
# $r->print("Received $new_count more results from ". |
# $r->print("Received $new_count more results from ". |
# $server."."); |
# $server."."); |
} |
} |
|
last if ($c->aborted()); |
|
&update_count_status($r,$hitcountsum); |
} |
} |
|
last if ($c->aborted()); |
# Finished looping through the servers |
# Finished looping through the servers |
} |
} |
|
&update_read_status($r,'none'); |
&Apache::lonmysql::disconnect_from_db(); |
&Apache::lonmysql::disconnect_from_db(); |
# Let the user know |
# Let the user know |
# |
# |
# We have run out of time or run out of servers to talk to and |
# We have run out of time or run out of servers to talk to and |
# results to get. |
# results to get. |
$r->print("<h1>Search completed.</h1>"); |
$r->print("<b>Search Completed.</b> "); |
if ($hitcountsum) { |
if ($hitcountsum) { |
$r->print($hitcountsum." successful matches to your query.<br />"); |
$r->print($hitcountsum." matches were found."); |
} else { |
} else { |
$r->print("There were no successful matches to your query.<br />"); |
$r->print("There were no successful matches to your query."); |
} |
} |
$r->print("</body></html>"); |
$r->print("</body></html>"); |
return; |
return; |
Line 1826 sub display_results {
|
Line 1903 sub display_results {
|
## |
## |
my $action = "/adm/searchcat?phase=results"; |
my $action = "/adm/searchcat?phase=results"; |
## |
## |
## |
## Deal with groupsearch |
## |
## |
if ($ENV{'form.catalogmode'} eq 'groupsearch') { |
if ($ENV{'form.catalogmode'} eq 'groupsearch') { |
if (! tie(%groupsearch_db,'GDBM_File',$diropendb, |
if (! tie(%groupsearch_db,'GDBM_File',$diropendb, |
&GDBM_WRCREAT,0640)) { |
&GDBM_WRCREAT(),0640)) { |
$r->print('Unable to tie hash to db file</body></html>'); |
$r->print('Unable to tie hash to db file</body></html>'); |
$r->rflush(); |
$r->rflush(); |
return; |
return; |
Line 1892 sub display_results {
|
Line 1969 sub display_results {
|
## |
## |
$r->print("<center>Results $min to $max out of $total_results</center>\n"); |
$r->print("<center>Results $min to $max out of $total_results</center>\n"); |
$r->print |
$r->print |
('<br /><center>'. |
('<center>'. |
&prev_next_buttons($min,$ENV{'form.show'},$total_results, |
&prev_next_buttons($min,$ENV{'form.show'},$total_results, |
"table=".$ENV{'form.table'}. |
"table=".$ENV{'form.table'}. |
"&phase=results". |
"&phase=results". |
"&persistent_db_id=".$ENV{'form.persistent_db_id'}) |
"&persistent_db_id=".$ENV{'form.persistent_db_id'}) |
."</center><br />\n" |
."</center>\n" |
); |
); |
## |
## |
## Get results from MySQL table |
## Get results from MySQL table |
Line 1920 sub display_results {
|
Line 1997 sub display_results {
|
} |
} |
if (@Results < 1) { |
if (@Results < 1) { |
$r->print("There were no results matching your query"); |
$r->print("There were no results matching your query"); |
|
} else { |
|
$r->print |
|
('<center>'. |
|
&prev_next_buttons($min,$ENV{'form.show'},$total_results, |
|
"table=".$ENV{'form.table'}. |
|
"&phase=results". |
|
"&persistent_db_id=". |
|
$ENV{'form.persistent_db_id'}) |
|
."</center>\n" |
|
); |
} |
} |
$r->print("</body></html>"); |
$r->print("</body></html>"); |
$r->rflush(); |
$r->rflush(); |