您好,欢迎访问一九零五行业门户网

全文本检索的应用(2)

contains 语法
我们通常在 where 子句中使用 contains ,就象这样:select * from table_name where contains(fulltext_column,'search contents')。
我们通过例子来学习,假设有表 students,其中的 address 是全文本检索的列。
1. 查询住址在北京的学生
select student_id,student_name
from students
where contains( address, 'beijing' )
remark: beijing是一个单词,要用单引号括起来。
2. 查询住址在河北省的学生
select student_id,student_name
from students
where contains( address, 'heibei province' )
remark: hebei province是一个词组,在单引号里还要用双引号括起来。
3. 查询住址在河北省或北京的学生
select student_id,student_name
from students
where contains( address, 'heibei province or beijing' )
remark: 可以指定逻辑操作符(包括 and ,and not,or )。
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。
5. 查询以 '湖' 开头的地址
select student_id,student_name
from students
where contains( address, 'hu*' )
remark: 上面的查询将返回包含 'hubei','hunan' 等字样的地址。
          记住是 *,不是 %。
6. 类似加权的查询
select student_id,student_name
from students
where contains( address, 'isabout (city weight (.8), county wright (.4))' )
remark: isabout 是这种查询的关键字,weight 指定了一个介于 0~1之间的数,类似系数(我的理解)。表示不同条件有不同的侧重。
7. 单词的多态查询
select student_id,student_name
from students
where contains( address, 'formsof (inflectional,street)' )
remark: 查询将返回包含 'street','streets'等字样的地址。
         对于动词将返回它的不同的时态,如:dry,将返回 dry,dried,drying 等等。
以上例子都使用英文,不使用中文是因为有的查询方式中文不支持,而且我的计算机是英文系统。
以上就是全文本检索的应用(2)的内容。
其它类似信息

推荐信息