Implement Phonetic ("Sounds-like") Name Searches with Double Metaphone Part III: VBScript and ASP & Database Solutions By Adam Nelson
[三] 就一筆帶過了:因為VB只是類型化的變數,而指令碼語言是無類型的.所以COM必須為指令碼語言單獨實現一個版本,然後在指令碼語言VBcript,JScript,以及ASP裡面的VBcript就可以調用了.
Implement Phonetic ("Sounds-like") Name Searches with Double Metaphone Part IV: SQL Server and Advanced Database Topics By Adam Nelson
[四] 還蠻有意思的.作為資料庫開發人員出身的作者(作者語),推介了預存程序的種種好處,並展示了用Sql Server的提示.
[使用預存程序]
SQL Server的擴充預存程序是用 Win32 DLL的. 安裝只需把DLL複製到SQL Server 安裝目錄的Binn 的目錄下,然後在master資料庫運行sp_addextendedproc,如
use master
exec sp_addextendedproc ‘xp_metaphone’, ‘XPMetaphone.dll’
預存程序只做了採用unsigned short 的最佳化版本.預先把key都算出來存起來,就可以使用select語句來查詢了.
[建立集簇索引]
一個表只能建立一個集簇索引列,讓實體儲存體上按該列排序,在資料規模很大時肯定要使用的.如果是把語音key和應用程式其他資訊存在一張表裡,key往往沒有重要到建集簇索引的份.
[減少與現有程式資料表的耦合]
把語音key單獨存個表,至少就可以有個集簇索引列了,這種建立資料庫的方法減少耦合,當然是好的.
[用觸發器更新key]
演算法可能會變,新詞來了也需要插入key.使用更新和插入時的觸發器來維護單詞的相應key
[在select裡給匹配打分]
(譯者:這種case平時我都忽略了,久了不用簡直都遺忘了)select
word,
(
case
when key1 = @primaryKey then
1--Strong match
when key2 = @primaryKey then
2--Normal match
when key1 = @alternateKey then
2--Normal match
when key2 = @alternateKey then
3--Minimal match
else
4--No match
end
) as matchScore
from Words
where
key1 = @primaryKey
or
key2 = @primaryKey
or
key1 = @alternateKey
or
key2 = @alternateKey
order by word
go
[把搜尋邏輯也封裝在預存程序中]
這下徹底了,應用程式只需簡單調用一條預存程序,不用再拼sql語句什麼的了,代碼重用又一招.