我正在尝试为我的新闻系统构建一个标签系统。我已经完成了这样的表结构:
CREATE TABLE article_tags (
id int(11) unsigned NOT NULL auto_increment,
tag varchar (255) not null,
primary key (id));
CREATE TABLE article_tags_map (
id int(11) unsigned NOT NULL auto_increment,
tag_id int(11) unsigned not null,
article_id int(11) unsigned not null,
primary key (id));
现在我只是想知道在article_tags表中为标签列添加全文索引是否有意义?
$search = $_POST['search_string'];
$search_result = mysql_query ("SELECT *, MATCH(tag) AGAINST ($search) AS score
from article_tags
WHERE MATCH (tag) AGAINST($search)
order by score desc");
或者我会更好地使用LIKE和%通配符?如果我要使用全文搜索,我不确定应该使用什么阈值来获得分数?
答案 0 :(得分:1)
试试这个。
SELECT *
from article_tags
WHERE tag like '%$search%'
order by tag desc
或
SELECT *
from article_tags
WHERE match(tag) against ('%$search%')
order by tag desc
另请参阅此页面,了解全文搜索:http://devzone.zend.com/26/using-mysql-full-text-searching/