includes/paths.php
changeset 272 e0ec986c0af3
parent 256 62ee6685ad18
child 279 8acd77a6c19d
child 286 b2f985e4cef3
--- a/includes/paths.php	Sun Nov 18 18:44:55 2007 -0500
+++ b/includes/paths.php	Wed Nov 21 15:10:57 2007 -0500
@@ -658,14 +658,14 @@
   }
   
   /**
-   * Fetches a MySQL search query to use for Searcher::searchMySQL()
+   * Generates an SQL query to grab all of the text
    */
    
   function fetch_page_search_resource()
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
     // sha1('') returns "da39a3ee5e6b4b0d3255bfef95601890afd80709"
-    $texts = 'SELECT t.page_text,CONCAT(\'ns=\',t.namespace,\';pid=\',t.page_id) FROM '.table_prefix.'page_text AS t
+    $texts = 'SELECT t.page_text, CONCAT(\'ns=\',t.namespace,\';pid=\',t.page_id) AS page_idstring, t.page_id, t.namespace FROM '.table_prefix.'page_text AS t
                            LEFT JOIN '.table_prefix.'pages AS p
                              ON ( t.page_id=p.urlname AND t.namespace=p.namespace )
                            WHERE p.namespace=t.namespace
@@ -685,9 +685,25 @@
     $texts = Array();
     $textq = $db->sql_unbuffered_query($this->fetch_page_search_resource());
     if(!$textq) $db->_die('');
-    while($row = $db->fetchrow_num())
+    while($row = $db->fetchrow())
     {
-      $texts[(string)$row[1]] = $row[0];
+      if ( isset($this->nslist[$row['namespace']]) )
+      {
+        $idstring = $this->nslist[$row['namespace']] . sanitize_page_id($row['page_id']);
+        if ( isset($this->pages[$idstring]) )
+        {
+          $page = $this->pages[$idstring];
+        }
+        else
+        {
+          $page = array('name' => dirtify_page_id($row['page_id']));
+        }
+      }
+      else
+      {
+        $page = array('name' => dirtify_page_id($row['page_id']));
+      }
+      $texts[(string)$row['page_idstring']] = $row['page_text'] . ' ' . $page['name'];
     }
     $search->buildIndex($texts);
     // echo '<pre>'.print_r($search->index, true).'</pre>';
@@ -725,10 +741,17 @@
     {
       return $db->get_error();
     }
+    if ( $db->numrows() < 1 )
+      return 'E: No rows';
+    $idstring = $this->nslist[$namespace] . sanitize_page_id($page_id);
+    if ( !isset($this->pages[$idstring]) )
+    {
+      return 'E: Can\'t find page metadata';
+    }
     $row = $db->fetchrow();
     $db->free_result();
     $search = new Searcher();
-    $search->buildIndex(Array("ns={$namespace};pid={$page_id}"=>$row['page_text']));
+    $search->buildIndex(Array("ns={$namespace};pid={$page_id}"=>$row['page_text'] . ' ' . $this->pages[$idstring]['name']));
     $new_index = $search->index;
     
     $keys = array_keys($search->index);
@@ -739,20 +762,6 @@
     }
     $keys = "word=0x" . implode ( " OR word=0x", $keys ) . "";
     
-    // Zap the cache
-    $cache = array_keys($search->index);
-    if ( count($cache) < 1 )
-    {
-      return false;
-    }
-    foreach ( $cache as $key => $_unused )
-    {
-      $cache[$key] = $db->escape( $cache[$key] );
-    }
-    $cache = "query LIKE '%" . implode ( "%' OR query LIKE '%", $cache ) . "%'";
-    $sql = 'DELETE FROM '.table_prefix.'search_cache WHERE '.$cache;
-    $db->sql_query($sql);
-    
     $query = $db->sql_query('SELECT word,page_names FROM '.table_prefix.'search_index WHERE '.$keys.';');
     
     while($row = $db->fetchrow())
@@ -785,7 +794,7 @@
     
   }
   
-  /**
+  /*
    * Creates an instance of the Searcher class, including index info
    * @return object
    */