2012-04-06 112 views

回答

5

UPDATE我移動我的原始答案down

我有一個奇怪的建議

您可能需要使用m ysql工具,叫做myisam_ftdump

下面是從樣品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解析它,你正在尋找的字。

原來的答案

帶或不帶布爾模式,答案是否定的。

但是,可以顯示基於詞出現和整個字符串長度的排名如下:

樣本數據

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

的結果問題在於分數應該標準化,對我來說這似乎是不可能的,因爲它取決於行數和其他完全動態的因素。那麼我想我必須在PHP中做我想做的事情? – 2012-04-06 18:58:28

+0

以及如何使用該轉儲文件計算單詞?我的意思是我沒有看到它連接到結果的行 – 2012-04-07 12:59:35