【问题标题】:Implementing a tag system for my news system为我的新闻系统实施标签系统
【发布时间】:2013-08-13 14:43:06
【问题描述】:

我正在尝试为我的新闻系统构建一个标签系统。我已经完成了一个这样的表结构:

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 和 % 通配符会更好吗?如果我要使用全文搜索,我不确定我应该为分数使用什么阈值?

【问题讨论】:

    标签: php mysql tags full-text-search


    【解决方案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/

    【讨论】:

    • 列分数未定义
    • 谢谢。但是不应该按分数排序而不是按标签排序吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多