full text index求助

唐诗三百首 2012-08-29 06:59:22
SQL2008R2, SQL Full-text服务已启动.
测试如下,为何结果总是返回0笔呢.

create database DBAP

use DBAP

create table tb5
( tsid int not null,
tsde char(8000),
descr varchar(30)
constraint pk_tb5 primary key clustered(tsid)
)

create index idx_tb5_descr on tb5(descr)


set nocount on
declare @x int=1
while @x<=100000
begin
insert into tb5(tsid,tsde,descr)
values(@x,'313ccx',rtrim(@x)+'cxccx')
select @x=@x+1
end
set nocount off


if(select databaseproperty('DBAP','isfulltextenabled'))=0
execute sp_fulltext_database 'enable'


execute sp_fulltext_catalog 'ft_pubs','create','D:\sqldata\ft'


execute sp_fulltext_table 'tb5','create','ft_pubs','pk_tb5'


execute sp_fulltext_column 'tb5','descr','add'


execute sp_fulltext_table 'tb5','activate'


execute sp_fulltext_catalog 'ft_pubs','start_full'


while fulltextcatalogproperty('ft_pubs','populateStatus')<>0
begin
waitfor delay '00:00:05'
end

--问题..为何总是返回0呢?
select count(1)
from tb5
where contains(descr,'35')
...全文
182 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
以学习为目的 2012-08-30
  • 打赏
  • 举报
回复
contains用法唐诗看看这个,希望对你有帮助。
叶子 2012-08-29
  • 打赏
  • 举报
回复

--使用contains关键字进行全文索引

--1.前缀搜索
select name from tb where contains(name,'"china*"')
/*--注意这里的* 返回结果会是 chinax chinay chinaname china
--返回前缀是china的name
--如果不用“”隔开 那么系统会都城 contains(name,'china*') 与china* 匹配*/

--2.使用派生词搜索
select name from tb where contains(name,'formsof(inflectional,"foot")')
/* 出来结果可能是 foot feet (所有动词不同形态 名词单复数形式)*/

--3.词加权搜索
select value from tb where contains(value , 'ISABOUT(performance weight(.8))')
/*全值用0-1的一个数字表示 表示每个词的重要程度*/

--4.临近词搜素
select * from tb where contains(document,'a near b')
/* 出来的结果是“a”单词与“b”单词临近的document
可以写成 contains(document,'a ~ b')
*/
--5.布尔逻辑搜素
select * from tb where contains(name,'"a" and "b"')
/*返回既包含A 又包含 B单词的行
当然 这里的AND 关键字还有换成 OR ,AND NOT 等
*/


参考:
http://www.cnblogs.com/cs_net/articles/2085465.html
叶子 2012-08-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

请问叶子,为何以下2个查询结果不一致呢.
SQL code

select count(1)
from tb5
where contains(descr,'"35*"')

select count(1)
from tb5
where descr like '%35%'
[/Quote]
因为contains不是精确的模糊查询。

参考:
http://msdn.microsoft.com/zh-cn/library/ms187787.aspx

搜索单个词和短语的精确或模糊(不太精确的)匹配项、在一定差别范围内的相近词或加权匹配项。

tanshine 2012-08-29
  • 打赏
  • 举报
回复
有意思,那么跟
select count(1)
from tb5
where descr like '35%'
结果一致吗?
唐诗三百首 2012-08-29
  • 打赏
  • 举报
回复
请问叶子,为何以下2个查询结果不一致呢.

select count(1)
from tb5
where contains(descr,'"35*"')

select count(1)
from tb5
where descr like '%35%'
叶子 2012-08-29
  • 打赏
  • 举报
回复
--试试这样行不行?
select count(1)
from tb5
where contains(descr,'"35*"')
shoppo0505 2012-08-29
  • 打赏
  • 举报
回复
contains中判断的字段要在select中出现吧。
试试:
select descr
from tb5
where contains(descr,'35')

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧