简体   繁体   中英

Implementing a tag system for my news system

I'm trying to build a tag system for my news system. I have finalized a table structure like this:

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));

Now I'm just wondering if it would make sense to add a full text index to the tag column in article_tags table ?

$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");

Or would I be better off with using LIKE and % wildcard characters ? If I were to use fulltext search, I'm not really sure what threshold should I use for the score ?

Try this.

SELECT *
from article_tags
WHERE tag like '%$search%'
order by tag desc

or

 SELECT *
    from article_tags
    WHERE match(tag) against ('%$search%')
    order by tag desc

also take a look to this page where they talk about full text searching: http://devzone.zend.com/26/using-mysql-full-text-searching/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM