这里是不使用全文检索
使用测试聪明
DROP TABLE IF EXISTS articles_table;
CREATE TABLE articles_table
(
ARTICLE_ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
article_content TEXT
)ENGINE = MyISAM数据;
INSERT INTO articles_table(article_content)VALUES
( '帝国是帝国'),
( '帝国是在棒球的位置的名称。'),
( '帝国帝国帝国' );
SELECT * FROM articles_table;
lwdba @ localhost(DB test):: SELECT * FROM articles_table;
+ ------------ + ---------------------------------- ----------------- +
| article_id | article_content |
+ ------------ + ---------------------------------- ----------------- +
| 1 |帝国是帝国|
| 2 |帝国是棒球界的名字。 |
| 3 |帝国帝国帝国|
+ ------------ + ---------------------------------- ----------------- +
3行中集合(0.00秒)
SELECT article_content,
REPLACE(article_content, '帝国', '') newstring,
LENGTH(article_content)origlen,
LENGTH(REPLACE(article_content, '帝国', ''))newlen,
FLOOR((LENGTH(article_content) - LENGTH(REPLACE(article_content, '帝国', ')))/(LENGTH('The Empire')))得分
FROM articles_table;
+ --------------------------------------------- ------ + ----------------------------------------- + - -------- + -------- + ------- +
| article_content | newstring | origlen | newlen |分数| + ------------------------------------------------ --- + ----------------------------------------- + ---- ----- + -------- + ------- +
|帝国是帝国|是| 24 | 4 | 2 |
|帝国是棒球界的名字。 |是棒球中的位置的名称。 | 49 | 39 | 1 |
|帝国帝国帝国| | 32 | 2 | 3 |
+ ----------------------------------------------- ---- + ---------------------------------------- + ---- ----- + -------- + ------- +
得分是原始字符串的删除次数。
增广查询只显示原始文本和得分:
SELECT * FROM(SELECT article_content,FLOOR((长度(article_content) - 长(REPLACE(article_content, '帝国', '') ))/(LENGTH('The Empire')))得分FROM articles_table)AA ORDER BY得分DESC;
下面是最终产品
lwdba @本地(DB测试):: SELECT * FROM(SELECT article_content,FLOOR((长度(article_content) - 长(REPLACE(article_content, '帝国', '' ))/(LENGTH('T he Empire')))score FROM articles_table)AA ORDER BY score DESC;
+ ----------------------------------------------- ---- + ------- +
| article_content |分数|
+ ----------------------------------------------- ---- + ------- +
|帝国帝国帝国| 3 |
|帝国是帝国| 2 |
|帝国是棒球界的名字。 | 1 |
+ ----------------------------------------------- ---- + ------- +
设置3行(0.06秒)
只需在查询的两个地方插入任何所需的字符串!
试试吧!
更新:哦,我试了!
你有没有尝试过匹配?你发现了什么结果? – Pentium10 2011-03-17 17:23:37