Ultimate Tag Warrior 3.14159265 的 Search 功能


Ultimate Tag Warrior 3.14159265 出了, 看來主要是 bug fix, 不過不知道有沒有人注意過, 裝了 UTW 之後, 在執行 search 功能 (Wordpress 內建的那個, 不是 tag search) 時, 對於一些沒有 tag 的舊文章, 反而會找不到. 昨天在官方的討論區裡面找了一下, 果然找到了. 看來是程式的問題, 在做 SQL select 時, 應該用 outer join, 但是 UTW 用的是 inner join, 結果就是在 wp_post2tag 裡面沒有記錄的舊文章, 就被過濾掉了..

需要的人請直接修改 ultimate-tag-warrior-actions.php, 把 849 行的 INNER 改成 LEFT 即可, 如下:

//$join .= " LEFT JOIN $tablepost2tag p2t on $wpdb->posts.ID = p2t.post_id INNER JOIN $tabletags on p2t.tag_id = $tabletags.tag_id ";
$join .= " LEFT JOIN $tablepost2tag p2t on $wpdb->posts.ID = p2t.post_id LEFT JOIN $tabletags on p2t.tag_id = $tabletags.tag_id ";

原文連結:
http://www.neato.co.nz/forum/comments.php?DiscussionID=1560&page=1

又, 上面那篇文章的後面還有提到一段程式修改, 看起來是要把 search 的字串中的空白, 雙引號, 單引號給代換掉. hyphen 的部份, 我想是因為 UTW 在 wp-tags 裡面, 會把空白存成 hyphen. 至於引號的部份就不清楚了, 不過我想應該是差不多的原因了.

 
function ultimate_search_where($where)
...<snip>
$searchInput = $wp_query->query_vars['s'];
$searchInput = str_replace(' ', '-', $searchInput);
$searchInput = str_replace('"', '', $searchInput);
$searchInput = str_replace("'", '', $searchInput);
$where .= " OR $tabletags.tag like '%" . $searchInput . "%'";

還有就是, 提到 search, Wordpress 的 search 看來應該是直接用 %字串% 去找的, 所以打 apple, 結果會連 applet 也出來. 最近有在試這個 Advanced Search Plugin for Wordpress, 他用到 MySQLfulltext search, 感覺這樣的搜尋結果是比較合理, 只是他的 UI 搞得有點複雜, 如果能弄個 Widget 放在首頁就很棒了.


Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Textual smileys will be replaced with graphical ones.
  • You can enable syntax highlighting of source code with the following tags: <code>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • You may link to Gallery2 items on this site using a special syntax.
  • Insert Flickr images: [flickr-photo:id=230452326,size=s] or [flickr-photoset:id=72157594262419167,size=m].
  • You may insert videos with [video:URL]

More information about formatting options