/*
1. Net Search Extender 9.7 由於DB2 9.7在權限上更加的嚴謹,所以必須給定權限才能使用
2. 中文用同義詞辭典做 extend search 是 workable 的. 建立時的編碼要注意
*/
/* grant 權限 */
grant dbadm on database to db2admns
grant dataaccess on database to db2admns
/* 讓 NSE 對 Database ORION 做 text search */
db2text enable database for text connect to orion
/* 建立測試 Table 及資料 */
CREATE TABLE HEADLINE
(
SNO INTEGER NOT NULL PRIMARY KEY,
TXT VARCHAR(128)
);
INSERT INTO HEADLINE VALUES
(1,'首支西班牙F1車隊成立'),
(2,'西班牙車手Pedro de la Rosa很有可能加入Campos車隊'),
(3,'西班牙車手Fernando Alonso加入Ferrari車隊'),
(4,'西班牙將減少鬥牛場次'),
(5,'F1明年將禁用輪圈整流罩'),
(6,'薪資仲裁 小小郭籌碼大增'),
(7,'一級方程式賽車世界冠軍將可能於巴西站產生'),
(8,'兩屆世界冠軍阿隆索將加入法拉利車隊'),
(9,'Kalou signs new Chelsea contract'),
(10,'Spanish olive farmers hit by price falls')
/* 建立 index 在 headline 的 txt 欄位上 */
db2text create index headline_idx for text on headline(txt)
/* refresh index */
db2text update index headline_idx for text
/*
建立同義詞辭典,存放在sqllib\db2ext\下,名稱給定為 nsesamplethes.def
編碼須為UTF-8 否則在編譯時給定 -ccsid 1208之後中文查仍是有問題
*/
:WORDS
阿隆索
.RELATED_TO F1
.RELATED_TO 一級方程式賽車
.RELATED_TO 西班牙
.SYNONYM_OF Fernando Alonso
.SYNONYM_OF Alonso
:WORDS
西班牙
.SYNONYM_OF Spain
.RELATED_TO Spanish
/* 編譯同義詞辭典 */
C:\Program Files\IBM\SQLLIB\db2ext>db2extth -f nsesamplethes.def -ccsid 1208 -t thes\
同義詞辭典編譯器
CTE0001 作業順利完成。
/* 以"阿隆索"做關聯字搜尋 */
db2 => select sno,txt from headline \
db2 (續) => => where contains(txt,'THESAURUS "nsesamplethes" \
db2 (續) => => expand related term of "阿隆索"') > 0
SNO TXT
----------- --------------------------------------------------
1 首支西班牙F1車隊成立
2 西班牙車手Pedro de la Rosa很有可能加入Campos車隊
3 西班牙車手Fernando Alonso加入Ferrari車隊
4 西班牙將減少鬥牛場次
5 F1明年將禁用輪圈整流罩
7 一級方程式賽車世界冠軍將可能於巴西站產生
8 兩屆世界冠軍阿隆索將加入法拉利車隊
已選取 7 個記錄。
/* 以"阿隆索"做同義字搜尋 */
db2 => select sno,txt from headline \
db2 (續) => => where contains(txt,'THESAURUS "nsesamplethes" \
db2 (續) => => expand synonym term of "阿隆索"') > 0
SNO TXT
----------- ---------------------------------------------------
3 西班牙車手Fernando Alonso加入Ferrari車隊
8 兩屆世界冠軍阿隆索將加入法拉利車隊
已選取 2 個記錄。
/* 以"西班牙"做關聯字搜尋 */
db2 => select sno,txt from headline \
db2 (續) => => where contains(txt,'THESAURUS "nsesamplethes" \
db2 (續) => => expand related term of "西班牙"') > 0
SNO TXT
----------- ----------------------------------------------------
1 首支西班牙F1車隊成立
2 西班牙車手Pedro de la Rosa很有可能加入Campos車隊
3 西班牙車手Fernando Alonso加入Ferrari車隊
4 西班牙將減少鬥牛場次
8 兩屆世界冠軍阿隆索將加入法拉利車隊
10 Spanish olive farmers hit by price falls
已選取 6 個記錄。
/* 以"西班牙"做同義字搜尋 */
db2 => select sno,txt from headline \
db2 (續) => => where contains(txt,'THESAURUS "nsesamplethes" \
db2 (續) => => expand synonym term of "西班牙"') > 0
SNO TXT
----------- ----------------------------------------------------
1 首支西班牙F1車隊成立
2 西班牙車手Pedro de la Rosa很有可能加入Campos車隊
3 西班牙車手Fernando Alonso加入Ferrari車隊
4 西班牙將減少鬥牛場次
已選取 4 個記錄。