mysql如何按行数匹配_mysql – 是否可以使用MATCH AGAINST计算每行匹配的单词数

更新我移动了我的原始答案

我有一个奇怪的建议

您可能需要使用名为myisam_ftdump的mysql实用程序

这是我原始答案中的示例中的FULLTEXT转储

C:\MySQL_5.5.12\data\sandro>myisam_ftdump -vc txtdata 1

2 0.4054651 everyhing

2 0.4054651 impossible

1 1.3862944 knew

3 -0.4054651 know

2 0.4054651 nothing

1 1.3862944 people

2 0.4054651 possible

1 1.3862944 probable

1 1.3862944 something

如果您可以将其生成为文本文件,则可以让PHP为您要查找的单词进行解析.

原始答案

无论有没有BOOLEAN MODE,答案都是否定的.

但是,您可以根据单词出现次数和整体字符串长度显示排名,如下所示:

样本数据

DROP DATABASE sandro;

CREATE DATABASE sandro;

use sandro

CREATE TABLE txtdata

(

id int not null auto_increment,

txt VARCHAR(255),

primary key (id),

FULLTEXT (txt)

) ENGINE=MyISAM;

INSERT INTO txtdata (txt) VALUES

('I know Nothing is possible'),

('We know nothing is impossible'),

('I knew everyhing is possible'),

('We know everyhing is possible'),

('For may people something is probable');

这是各种搜索排名的结果

mysql> SELECT *,MATCH(txt) AGAINST ('possible knew') as score FROM txtdata;

+----+--------------------------------------+--------------------+

| id | txt | score |

+----+--------------------------------------+--------------------+

| 1 | I know Nothing is possible | 0.3919430673122406 |

| 2 | We know nothing is impossible | 0 |

| 3 | I knew everyhing is possible | 1.73200523853302 |

| 4 | We know everyhing is impossible | 0 |

| 5 | For may people something is probable | 0 |

+----+--------------------------------------+--------------------+

5 rows in set (0.00 sec)

mysql> SELECT *,MATCH(txt) AGAINST ('possible know') as score FROM txtdata;

+----+--------------------------------------+--------------------+

| id | txt | score |

+----+--------------------------------------+--------------------+

| 1 | I know Nothing is possible | 0.3919430673122406 |

| 2 | We know nothing is impossible | 0 |

| 3 | I knew everyhing is possible | 0.3919430673122406 |

| 4 | We know everyhing is impossible | 0 |

| 5 | For may people something is probable | 0 |

+----+--------------------------------------+--------------------+

5 rows in set (0.00 sec)

mysql> SELECT *,MATCH(txt) AGAINST ('impossible knew') as score FROM txtdata;

+----+--------------------------------------+--------------------+

| id | txt | score |

+----+--------------------------------------+--------------------+

| 1 | I know Nothing is possible | 0 |

| 2 | We know nothing is impossible | 0.3919430673122406 |

| 3 | I knew everyhing is possible | 1.340062141418457 |

| 4 | We know everyhing is impossible | 0.3919430673122406 |

| 5 | For may people something is probable | 0 |

+----+--------------------------------------+--------------------+

5 rows in set (0.00 sec)

mysql> SELECT *,MATCH(txt) AGAINST ('impossible know') as score FROM txtdata;

+----+--------------------------------------+--------------------+

| id | txt | score |

+----+--------------------------------------+--------------------+

| 1 | I know Nothing is possible | 0 |

| 2 | We know nothing is impossible | 0.3919430673122406 |

| 3 | I knew everyhing is possible | 0 |

| 4 | We know everyhing is impossible | 0.3919430673122406 |

| 5 | For may people something is probable | 0 |

+----+--------------------------------------+--------------------+

5 rows in set (0.00 sec)

mysql>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值