[wp-trac] [WordPress Trac] #6410: DB_COLLATE is not used in searches

WordPress Trac wp-trac at lists.automattic.com
Thu Mar 27 05:36:31 GMT 2008


#6410: DB_COLLATE is not used in searches
-------------------------+--------------------------------------------------
 Reporter:  bertilow     |       Owner:  anonymous
     Type:  enhancement  |      Status:  new      
 Priority:  normal       |   Milestone:  2.7      
Component:  General      |     Version:           
 Severity:  normal       |    Keywords:           
-------------------------+--------------------------------------------------
 Testing WP-2.5RC1 I found that the collation set in "wp-config.php"
 (DB_COLLATE) is not being used in searches. I think it should.

 This can easily be fixed. In "wp-includes/query.php" the following part
 can be changed as indicated here:

 {{{
 // If a search pattern is specified, load the posts that match
 if ( !empty($q['s']) ) {

   // [...]

   foreach((array)$q['search_terms'] as $term) {
     $term = addslashes_gpc($term);
     // The following like has been added
     if ($wpdb->collate) $collatesql = ' COLLATE ' . $wpdb->collate;
     // The following line has been changed
     // $collatesql was inserted in two places
     $search .= "{$searchand}(($wpdb->posts.post_title LIKE
 '{$n}{$term}{$n}'$collatesql) OR ($wpdb->posts.post_content LIKE
 '{$n}{$term}{$n}'$collatesql))";
     $searchand = ' AND ';
   }

   // [...]
 }
 }}}

 There is probably a more general way to fix this, e.g. by including a
 "COLLATE" statement (using DB_COLLATE) along with "SET NAME"
 $this->query("SET NAMES '$this->charset'") in "wp-db.php", but the above
 solution should also work.

-- 
Ticket URL: <http://trac.wordpress.org/ticket/6410>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list