如果您真的对此感兴趣,我会说您应该将文本(非sql)解析为一个名为 word_list 的表,例如
create table phrases (word1 varchar, word2 varchar, word3 varchar, cnt int);
和代码:
$q = query("select comment from comments");
while ($row = array_read_line($q)){
$words = preg_split('/\s/', $row['comment']);
$previous1 = false;
$previous2 = false;
foreach($words as $word){
if($previous1 and $previous2){
.. here comes quoting, security, mysql-injection-safety, min length
query("update relations set cnt = cnt+1 "
. " where word1 = '$previous1', word2 = '$previous2', word3='$word'" )
if (rows_afected == 0){
query("insert into relations "
. " set cnt = 1, word1 = '$previous1', "
. " word2 = '$previous2', word3='$word'" )
}
}
previous1 = $previous2;
$previous2 = $word;
}
}
然后按count desc排序。