22,209
社区成员
发帖
与我相关
我的任务
分享
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')
--使用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 等
*/
select count(1)
from tb5
where contains(descr,'"35*"')
select count(1)
from tb5
where descr like '%35%'
--试试这样行不行?
select count(1)
from tb5
where contains(descr,'"35*"')