我會嘗試基於失效鏈接的評論來回答我的問題(感謝您對本):
你摘取語句由1至3個字從你的文檔數據庫。在這些extraced短語有下面的語句:
對於每個短語,你帶所有的特殊字符和空格,使字符串小寫:
$ phrase ='混血王子'; $ phrase = preg_replace('/ [^ a-z]/i','',$ phrase); $ phrase = strtolower($ phrase); //結果是 「halfbloodprince」
當你做到了這一點,所有的3個階段(見上文)有一個共同的拼寫:
- 混血王子=> halfbloodprince
- 混血王子=> halfbloodprince
- 混血王子=> halfbloodprince
所以 「halfbloodprince」 是父短語。將兩者都插入數據庫,正常短語和父語句。
要顯示一個「熱門話題聯繫」 Twitter之類的,你做到以下幾點:
// first select the top 10 parent phrases
$sql1 = "SELECT parentPhrase, COUNT(*) as cnt FROM phrases GROUP BY parentPhrase ORDER BY cnt DESC LIMIT 0, 10";
$sql2 = mysql_query($sql1);
while ($sql3 = mysql_fetch_assoc($sql2)) {
$parentPhrase = $sql3['parentPhrase'];
$childPhrases = array(); // set up an array for the child phrases
$fifthPart = round($sql3['cnt']*0.2);
// now select all child phrases which make 20% of the parent phrase or more
$sql4 = "SELECT phrase FROM phrases WHERE parentPhrase = '".$sql3['parentPhrase']."' GROUP BY phrase HAVING COUNT(*) >= ".$fifthPart;
$sql5 = mysql_query($sql4);
while ($sql6 = mysql_fetch_assoc($sql5)) {
$childPhrases[] = $sql3['phrase'];
}
// now you have the parent phrase which is on the left side of the arrow in $parentPhrase
// and all child phrases which are on the right side of the arrow in $childPhrases
}
這是你想,斷開鏈路的什麼?這會工作嗎?
來源
2009-08-06 23:09:43
caw
只需刪除搜索字詞中的所有特殊字符+空格並將其鏈接即可! 「search term」=「search-term」=「Search + term」任何事情都會導致搜索「searchterm」 我知道太聰明:) – 2009-07-29 22:59:16
不,不是那麼簡單。 「音樂是你」是這個話題的唯一拼寫。但是「混血王子」有兩種不同的拼寫... – caw 2009-07-30 22:42:26
如果你移除像Broken Link這樣的所有特殊字符,實際上並沒有兩個混血王子的拼寫。在刪除特殊字符和空格之後,最後都是「halfbloodprince」 – 2009-08-06 02:44:08