展会信息港展会大全

MS SQL Server的中文分词探索(3)
来源:互联网   发布日期:2011-09-09 17:17:27   浏览:17771次  

导读: 现在需要这样的一个效果,根据产品名,做模糊查询,得到其产品名相似的产品。 但是越精确的越靠前。 原本我的方式是: alterfunction f_splitIncrease ( @strSourcenvarchar(2000), @strSplitStrnvarchar(100) ) returns@tempTabletable(idintidentityprimar...

现在需要这样的一个效果,根据产品名,做模糊查询,得到其产品名相似的产品。
但是越精确的越靠前。
原本我的方式是:
alterfunction f_splitIncrease
(
@strSourcenvarchar(2000),
@strSplitStrnvarchar(100)
)
returns@tempTabletable(idintidentityprimarykey,onenvarchar(1000))
as begin declare@tempStrnvarchar(1000);
declare@startIndexint;
set@startIndex=1;
set@strSource=@strSource @strSplitStr;
while(@startIndex 0)
begin set@startIndex=charindex(@strSplitstr,@strSource,@startIndex 1);
if(@startIndex 0)
begin set@tempStr=left(@strSource,@startIndex-1);
if(@tempStr'')
begin insertinto@tempTablevalues(@tempStr);
end end end return end
调用select*from dbo.f_splitIncrease('the office seasons')
会得到
the the office the office seasons
这样三条记录,
再根据这个去做搜索,代码如下:
alterproc Proc_Product_Related
(
@namenvarchar(2000),
@splitStrnvarchar(100)=''
)
as begin declare@tempTabletable(
idintidentity(1,1)primarykey,
ProductIDint,
[Name]nvarchar(255),
ProductNonvarchar(50),
MemberPricemoney,
ThumbnailImgnvarchar(255),
ProductImgnvarchar(255)
)
if(@splitStrisNull)
begin set@splitStr='';
end begintransaction insertinto@tempTable selectdistinct ProductID,[Name],ProductNo,MemberPrice,ThumbnailImg,ProductImgfrom product p,(select*from dbo.f_splitIncrease(@name,@splitStr))f where p.namelike f.one 'br />if(@error 0)
begin rollbacktransaction end select*from@tempTable if@error 0
rollback else committransaction end
于是最精确的排在最下面。
但是由于模糊搜索the office时,已经包含了the office seasons,会出现记录重复。
现在要解决记录重复,如果使用distinct关键字的话,他的结果集就不是最精确的排在最下面。没有达到原本想要的效果。
这里该如何处理呀?
 

赞助本站

人工智能实验室

相关热词: Server 中文分 词探

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港