使用
FULLTEXT
搜索:
CREATE TABLE t_ft (id INT NOT NULL PRIMARY KEY, words VARCHAR(255) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET='utf8';
CREATE FULLTEXT INDEX fx_ft_words ON t_ft (words);
INSERT
INTO t_ft (id, words)
VALUES (1, 'some text with some text provding the user most likely no interesting info');
INSERT
INTO t_ft (id, words)
VALUES (2, 'some other text');
INSERT
INTO t_ft (id, words)
VALUES (3, 'some third text saying some other crap');
INSERT
INTO t_ft
SELECT id + 3, 'complete nonsense'
FROM t_source
LIMIT 1000;
SELECT *, MATCH(words) AGAINST('"some text"') AS relevance
FROM t_ft
WHERE MATCH(words) AGAINST('"some text"')
ORDER BY
relevance DESC;
MATCH
将返回你可以使用的等级
ORDER BY
.