中文搜索问题解决办法
1. 把 search 模块修改一下。
drupal中不能搜索中文的原因是因为drupal不能判断中文的词语,所以中文字联在一起的时候就会看成是一个词,导致不能搜索。
解决的方法就是在搜索的词汇前后默认加上*号,让drupal搜索“含有”搜索汉字的词语,这样就可以了。
具体方法:
在search.modules里查找:
$keys = str_replace("*", "%", $keys);
把它变成
$keys = '%'.str_replace("*", "%", $keys).'%';
就可以了。
2. 修改各个模块的 do_search 函数
用下面的内容替代modules里的对应内容:
node.module:
$find = do_search(array("keys" => $keys, "type" => "node", "select" => "SELECT n.nid AS lno, n.title AS title, n.created AS created, u.uid AS uid, u.name AS name, 1 AS count FROM node n LEFT JOIN users u ON n.uid = u.uid WHERE ( n.title LIKE BINARY '%' OR n.teaser LIKE BINARY '%' OR n.body LIKE BINARY '%') AND n.status = 1"));
comment.module:
$find = do_search(array("keys" => $keys, "type" => "comment", "select" => "SELECT c.cid as lno, c.nid as nid, c.subject as title, c.timestamp AS created, u.uid AS uid, u.name AS name, 1 AS count FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE (c.comment LIKE BINARY '%') AND c.status = 0;"));