2012-04-06 12 views

答えて

5

UPDATE

ダウン私の元の答え私はあなたがメートルを使用する必要があります奇妙な提案

を持っていますここでmyisam_ftdump

と呼ばれるYSQLユーティリティは、テキストファイルとしてこれを生成することができる場合、あなたはPHPは、あなたが探している単語のためにそれを解析持つことができ、私のオリジナルの答え

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 

にサンプルからFULLTEXTダンプです。 BOOLEAN MODE付きまたはなし

ORIGINAL ANSWER

、答えはノーです。次のように

ただし、単語の出現と全体の文字列の長さに基づいてランキングを表示することができます:

サンプルデータを

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で私が望むことをしなければならないと思いますか? –

+0

とそのダンプファイルを使用して単語をカウントする方法は、結果の行に接続されていないことを意味します –

関連する問題