Fixed some bugs with PostgreSQL and added a word_lcase column to the search_index table because collation is not working under MySQL. TODO: Trigger search index rebuild on upgrade to 1.1.4.
authorDan
Sat, 15 Mar 2008 00:08:01 -0400
changeset 499 6b7fdd898ba3
parent 498 a85af9c28355
child 500 455277559782
Fixed some bugs with PostgreSQL and added a word_lcase column to the search_index table because collation is not working under MySQL. TODO: Trigger search index rebuild on upgrade to 1.1.4.
includes/paths.php
includes/search.php
includes/sessions.php
install/schemas/mysql_stage2.sql
install/schemas/postgresql_stage2.sql
--- a/includes/paths.php	Tue Mar 11 17:09:20 2008 -0400
+++ b/includes/paths.php	Sat Mar 15 00:08:01 2008 -0400
@@ -611,6 +611,8 @@
         unset($text[$i]);
     }
     $text = array_unique(array_values($text));
+    // for debugging purposes (usually XSS safe because of character stripping)
+    // echo ' ' . implode(' ', $text) . '<br />';
     return $text;
   }
   
@@ -669,7 +671,7 @@
                             . "    ON ( p.urlname = t.page_id AND p.namespace = t.namespace )\n"
                             . "  WHERE ( p.password = '' OR p.password = '$sha1_blank' )\n"
                             . "    AND ( p.visible = 1 )\n"
-                            . "  LIMIT $offset, $pages_in_batch;", false);
+                            . "  LIMIT $pages_in_batch OFFSET $offset;", false);
       if ( !$texts )
         $db->_die();
       
@@ -703,9 +705,10 @@
             if ( in_array($word, $stopwords) || strval(intval($word)) === $word || strlen($word) < 3 )
               continue;
             $word_db = $db->escape($word);
+            $word_db_lc = $db->escape(strtolower($word));
             if ( !in_array($word, $master_word_list) )
             {
-              $inserts[] = "( '$word_db', '$page_uniqid' )";
+              $inserts[] = "( '$word_db', '$word_db_lc', '$page_uniqid' )";
             }
             else
             {
@@ -724,7 +727,7 @@
             if ( $verbose && $debug )
               echo 'i';
             $inserts = implode(",\n  ", $inserts);
-            $q = $db->sql_query('INSERT INTO ' . table_prefix . "search_index(word, page_names) VALUES\n  $inserts;", false);
+            $q = $db->sql_query('INSERT INTO ' . table_prefix . "search_index(word, word_lcase, page_names) VALUES\n  $inserts;", false);
             if ( !$q )
               $db->_die();
           }
--- a/includes/search.php	Tue Mar 11 17:09:20 2008 -0400
+++ b/includes/search.php	Sat Mar 15 00:08:01 2008 -0400
@@ -110,7 +110,7 @@
  *   page_text: string, the contents of the page (trimmed to ~150 bytes if necessary)
  *   score: numerical relevance score, 1-100, rounded to 2 digits and calculated based on which terms were present and which were not
  * @param string Search query
- * @param string Will be filled with any warnings encountered whilst parsing the query
+ * @param string|reference Will be filled with any warnings encountered whilst parsing the query
  * @param bool Case sensitivity - defaults to false
  * @param array|reference Will be filled with the parsed list of words.
  * @return array
@@ -197,7 +197,7 @@
       $where_any[] = $term;
     }
 
-    $col_word = ( $case_sensitive ) ? 'word' : ENANO_SQLFUNC_LOWERCASE . '(word)';
+    $col_word = ( $case_sensitive ) ? 'word' : 'word_lcase';
     $where_any = ( count($where_any) > 0 ) ? '( ' . $col_word . ' = \'' . implode('\' OR ' . $col_word . ' = \'', $where_any) . '\' )' : '';
 
     // generate query
--- a/includes/sessions.php	Tue Mar 11 17:09:20 2008 -0400
+++ b/includes/sessions.php	Sat Mar 15 00:08:01 2008 -0400
@@ -1238,7 +1238,7 @@
                              . '    ON ( p.message_to=u.username AND p.message_read=0 )' . "\n"
                              . '  WHERE k.session_key=\''.$keyhash.'\'' . "\n"
                              . '    AND k.salt=\''.$salt.'\'' . "\n"
-                             . '  GROUP BY u.user_id,u.username,u.password,u.email,u.real_name,u.user_level,u.theme,u.style,u.signature,u.reg_time,u.account_active,u.activation_key,u.user_lang,k.source_ip,k.time,k.auth_level,x.user_id, x.user_aim, x.user_yahoo, x.user_msn, x.user_xmpp, x.user_homepage, x.user_location, x.user_job, x.user_hobbies, x.email_public;');
+                             . '  GROUP BY u.user_id,u.username,u.password,u.email,u.real_name,u.user_level,u.theme,u.style,u.signature,u.reg_time,u.account_active,u.activation_key,u.user_lang,u.user_timezone,k.source_ip,k.time,k.auth_level,x.user_id, x.user_aim, x.user_yahoo, x.user_msn, x.user_xmpp, x.user_homepage, x.user_location, x.user_job, x.user_hobbies, x.email_public;');
     
     if ( !$query )
     {
--- a/install/schemas/mysql_stage2.sql	Tue Mar 11 17:09:20 2008 -0400
+++ b/install/schemas/mysql_stage2.sql	Sat Mar 15 00:08:01 2008 -0400
@@ -192,6 +192,7 @@
 
 CREATE TABLE {{TABLE_PREFIX}}search_index(
   word varchar(64) NOT NULL,
+  word_lcase varchar(64) NOT NULL,
   page_names text,
   PRIMARY KEY ( word ) 
 ) CHARACTER SET `utf8` COLLATE `utf8_bin`;
--- a/install/schemas/postgresql_stage2.sql	Tue Mar 11 17:09:20 2008 -0400
+++ b/install/schemas/postgresql_stage2.sql	Sat Mar 15 00:08:01 2008 -0400
@@ -85,7 +85,7 @@
   default_style varchar(63) NOT NULL DEFAULT '',
   enabled smallint NOT NULL DEFAULT '1',
   group_list text DEFAULT NULL,
-  group_policy varchar(5) NOT NULL DEFAULT 'allow_all',
+  group_policy varchar(9) NOT NULL DEFAULT 'allow_all',
   CHECK (group_policy IN ('allow_all', 'whitelist', 'blacklist'))
 );
 
@@ -193,6 +193,7 @@
 
 CREATE TABLE {{TABLE_PREFIX}}search_index(
   word varchar(64) NOT NULL,
+  word_lcase varchar(64) NOT NULL,
   page_names text,
   PRIMARY KEY ( word )
 );