[LON-CAPA-cvs] cvs: loncom /interface lonsearchcat.pm

matthew lon-capa-cvs@mail.lon-capa.org
Tue, 30 Jul 2002 18:30:56 -0000


This is a MIME encoded message

--matthew1028053856
Content-Type: text/plain

matthew		Tue Jul 30 14:30:56 2002 EDT

  Modified files:              
    /loncom/interface	lonsearchcat.pm 
  Log:
  This version should be considered relatively stable.  If you are able to break
  it, please let me know.  To test this version out, I suggest doing a basic
  search on 'a'.
  
  &handler(): More error messages given to user.
  &get_persistent_form_data has been changed a little.
  The MySQL table definition has been changed to match the new requirements of
      lonmysql.pm
  &run_search() Attempts to keep the user abreast of the search status 
      (more to come).
  &display_results now places the 'prev refresh next' links at the bottom of
      the page as well as the top.
  
  
--matthew1028053856
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20020730143056.txt"

Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.146 loncom/interface/lonsearchcat.pm:1.147
--- loncom/interface/lonsearchcat.pm:1.146	Mon Jul 29 17:53:57 2002
+++ loncom/interface/lonsearchcat.pm	Tue Jul 30 14:30:56 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.146 2002/07/29 21:53:57 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.147 2002/07/30 18:30:56 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -191,7 +191,7 @@
     ##     this once, so the pause indicator is deleted
     ##
     if (exists($ENV{'form.pause'})) {
-        sleep(5);
+        sleep(3);
         delete($ENV{'form.pause'});
     }
     ##
@@ -204,7 +204,8 @@
     # set the name of the persistent database
     #          $ENV{'form.persistent_db_id'} can only have digits in it.
     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;
     }
     my $persistent_db_file = "/home/httpd/perl/tmp/".
@@ -212,7 +213,9 @@
             '_'.&Apache::lonnet::escape($ENV{'user.name'}).
                 '_'.$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
     ##
@@ -280,12 +283,31 @@
             ($ENV{'form.phase'} eq 'adv_search')) {
         # Set up table
         if (! defined(&create_results_table())) {
-            # Unable to make table to store results in.  
-            # Definately abort search.
+            my $error = &Apache::lonmysql::get_error();
+            $r->print(<<END);
+<html><head><title>Search Error</title></head>
+<body>
+Unable to create table in which to store search results.  
+The search has been aborted.
+<pre>
+ERROR:
+$error
+</pre>
+</body>
+</html>
+END
+            return OK;
         }
+        delete($ENV{'form.launch'});
         if (! &make_form_data_persistent($r,$persistent_db_file)) {
-            # Unable to store persistent data.
-            # Probably should bail out.
+            $r->print(<<END);
+<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
@@ -299,11 +321,6 @@
                 = &parse_advanced_search($r,$closebutton);
             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,
                          { query => $query,
                            customquery => $customquery,
@@ -608,7 +625,7 @@
 sub get_persistent_form_data {
     my $r = shift;
     my $filename = shift;
-    return undef if (! -e $filename);
+    return 0 if (! -e $filename);
     return undef if (! tie(%persistent_db,'GDBM_File',$filename,
                            &GDBM_READER,0640));
     #
@@ -637,7 +654,6 @@
                 $ENV{$name} = $values[0] if ($values[0]);
             }
         }
-        &write_status($r,"Reconstructed $name = $ENV{$name}");
     }
     untie (%persistent_db);
     return 1;
@@ -717,7 +733,6 @@
         # We handle array references, but not recursively.
         my $store = join(',', map { &Apache::lonnet::escape($_); } @values );
         $persistent_db{$name} = $store;
-        &write_status($r,"Stored $name = $store");
     }
     untie(%persistent_db);
     return 1;
@@ -1527,9 +1542,7 @@
 ##    columns of type 'enum' cannot be used for FULLTEXT.
 ##
 my @DataOrder = qw/id title author subject url keywords version notes
-    abstract mime lang owner copyright creationdate lastrevisiondate hostname
-    idx_title idx_author idx_subject idx_abstract idx_mime idx_language 
-    idx_owner idx_copyright/;
+    abstract mime lang owner copyright creationdate lastrevisiondate hostname/;
 
 my %Datatypes = 
     ( id        =>{ type         => 'INT',
@@ -1555,16 +1568,11 @@
       creationdate     =>{ 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/;
+    
 ######################################################################
 ######################################################################
 
@@ -1587,6 +1595,7 @@
     my $table = &Apache::lonmysql::create_table
         ( { columns => \%Datatypes,
             column_order => \@DataOrder,
+            fullindex => \@Fullindicies,
         } );
     if (defined($table)) {
         $ENV{'form.table'} = $table;
@@ -1649,14 +1658,23 @@
     }
     my %Server_status;
     my $table =$ENV{'form.table'};
-    if (! defined($table)) {
-        # What do I do now?  Print out an error page.
-        &Apache::lonnet::logthis("lonmysql attempted to create a table ".
-                                 "and this was the result:".
+    if (! defined($table) || $table eq '') {
+        $r->print("Unable to determine table id to store search results in.".
+                  "The search has been aborted.");
+        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());
-        $r->print("An internal error occured with the database.<br />".
-                  "The error has been logged, but you should probably alert".
-                  " your system administrator.");
+        return;
+    }
+    if (! $table_status) {
+        $r->print("The table id,$table, we tried to use is invalid.".
+                  "The search has been aborted.");
         return;
     }
     ##
@@ -1665,6 +1683,7 @@
     my $hitcountsum;
     my $server; 
     my $status;
+    $r->print("Searching");
     while ((time - $starttime < $max_time) && 
            ((@Servers_to_contact) || keys(%Server_status))) {
         # Send out a search request if it needs to be done.
@@ -1676,12 +1695,8 @@
             ($server) = keys(%$reply);
             $Server_status{$server} = $reply->{$server};
             # $r->print("Contacted:$server:reply:$Server_status{$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;
-            }
+            $r->print(" .");
+            $r->rflush();
         } else {
             sleep(1); # wait a sec. to give time for files to be written
         }
@@ -1744,9 +1759,9 @@
     #
     # We have run out of time or run out of servers to talk to and
     # results to get.  
-    $r->print("<h1>Search completed.</h1>");
+    $r->print("<br /><b>Search Completed</b><br />");
     if ($hitcountsum) {
-        $r->print($hitcountsum." successful matches to your query.<br />");
+        $r->print($hitcountsum." successful matches were found.<br />");
     } else {
         $r->print("There were no successful matches to your query.<br />");
     }
@@ -1826,7 +1841,7 @@
     ##
     my $action = "/adm/searchcat?phase=results";
     ##
-    ##
+    ## Deal with groupsearch
     ##
     if ($ENV{'form.catalogmode'} eq 'groupsearch') {
         if (! tie(%groupsearch_db,'GDBM_File',$diropendb,
@@ -1920,6 +1935,16 @@
     }
     if (@Results < 1) {
         $r->print("There were no results matching your query");
+    } else {
+        $r->print
+            ('<br /><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><br />\n"
+             );
     }
     $r->print("</body></html>");
     $r->rflush();

--matthew1028053856--