SQL Server之2:全文搜索(2)

这里主要讲全文搜索里面用到的 Contains 函数,摘录别人的文章,感觉写的好,拿来分享一下。

假设有表 students,其中的 address 是全文本检索的列。

1 . 查询住址在北京的学生
SELECT student_id,student_name
FROM students
WHERE CONTAINS ( address, ' beijing ' )
remark: beijing是一个单词,要用单引号括起来。 网管下载dl.bitscn.com

2 . 查询住址在河北省的学生
SELECT student_id,student_name
FROM students
WHERE CONTAINS ( address, ' "HEIBEI province" ' )
remark: HEBEI province是一个词组,在单引号里还要用双引号括起来。

中国网管论坛bbs.bitsCN.com


3 . 查询住址在河北省或北京的学生
SELECT student_id,student_name
FROM students
WHERE CONTAINS ( address, ' "HEIBEI province" OR beijing ' )
remark: 可以指定逻辑操作符(包括
AND AND NOT OR )。

网管下载dl.bitscn.com


4 . 查询有 ' 南京路 ' 字样的地址
SELECT student_id,student_name
FROM students
WHERE CONTAINS ( address, ' nanjing NEAR road ' )
remark: 上面的查询将返回包含
' nanjing road ' ' nanjing east road ' ' nanjing west road ' 等字样的地址。
A NEAR B,就表示条件: A 靠近 B。

网管网www.bitscn.com


5 . 查询以 ' ' 开头的地址
SELECT student_id,student_name
FROM students
WHERE CONTAINS ( address, ' "hu*" ' )
remark: 上面的查询将返回包含
' hubei ' ' hunan ' 等字样的地址。
记住是
* ,不是 %

网管论坛bbs_bitsCN_com

6 . 类似加权的查询
SELECT student_id,student_name
FROM students
WHERE CONTAINS ( address, ' ISABOUT (city weight (.8), county wright (.4)) ' )
remark: ISABOUT 是这种查询的关键字,weight 指定了一个介于
0 ~ 1之间的数,类似系数(我的理解)。表示不同条件有不同的侧重。 网管下载dl.bitscn.com

7 . 单词的多态查询
SELECT student_id,student_name
FROM students
WHERE CONTAINS ( address, ' FORMSOF (INFLECTIONAL,street) ' )
remark: 查询将返回包含
' street ' ' streets ' 等字样的地址。
对于动词将返回它的不同的时态,如:dry,将返回 dry,dried,drying 等等。

本文来自CSDN博客,转载请标明出处:http:
// blog.csdn.net / htl258 / archive / 2009 / 03 / 17 / 3996728 .aspx

 

你可能感兴趣的:(SQL Server)