您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

mysql全文索引—CONTAINS语法

2024/11/13 0:55:00发布18次查看
全文索引——contains 语法
我们通常在 where 子句中使用 contains ,就象这样:
select * from table_name where contains(fulltext_column,'search contents')。
相关mysql视频教程推荐:《mysql教程》
我们通过例子来学习,假设有表 students,其中的 address 是全文本检索的列。
1.查询住址在北京的学生
select student_id,student_namefrom studentswhere contains( address, 'beijing' )
remark: beijing是一个单词,要用单引号括起来。
2. 查询住址在河北省的学生
select student_id,student_namefrom studentswhere contains( address, '"heibei province"' )
remark: hebei province是一个词组,在单引号里还要用双引号括起来。
3. 查询住址在河北省或北京的学生
select student_id,student_namefrom studentswhere contains( address, '"heibei province" or beijing' )
remark: 可以指定逻辑操作符(包括 and ,and not,or )。
4. 查询有 '南京路' 字样的地址
select student_id,student_namefrom studentswhere contains( address, 'nanjing near road' )
remark: 上面的查询将返回包含 'nanjing road','nanjing east road','nanjing west road' 等字样的地址。
a near b,就表示条件: a 靠近 b。
5. 查询以 '湖' 开头的地址
select student_id,student_namefrom studentswhere contains( address, '"hu*"' )
remark: 上面的查询将返回包含 'hubei','hunan' 等字样的地址。
记住是 *,不是 %。
6. 类似加权的查询
select student_id,student_namefrom studentswhere contains( address, 'isabout (city weight (.8), county wright (.4))' )
remark: isabout 是这种查询的关键字,weight 指定了一个介于 0~1之间的数,类似系数(我的理解)。表示不同条件有不同的侧重。
7. 单词的多态查询
select student_id,student_namefrom studentswhere contains( address, 'formsof (inflectional,street)' )
remark: 查询将返回包含 'street','streets'等字样的地址。
对于动词将返回它的不同的时态,如:dry,将返回 dry,dried,drying 等等。
以上例子都使用英文,不使用中文是因为有的查询方式中文不支持,而且我的计算机是英文系统。
推荐手册:mysql开发手册
推荐视频:mysql权威开发指南(教程)
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product