我想做一个相关信息的查询功能
例如输入
弹开层的问题
我会在后台自动拆字
弹开|开层|层的|的问|问题
然后根据这些关键字or查询
我想结果能按匹配次数来排序有什么方法
例如输入
弹开层的问题
我会在后台自动拆字
弹开|开层|层的|的问|问题
然后根据这些关键字or查询
我想结果能按匹配次数来排序有什么方法
解决方案 »
- sqlserver 字符转码
- dbf文件导入到sql2005的问题!!!!!急急急急急急急急
- 我一个分页存储过程 一在最后加入 desc就只能显示因第一页数据
- bcp的错误!急急急急
- 这样的查询语句怎么写?
- 数据类型
- A transport-level error has occurred when sending the request to the server. (provider: Shared Memory Provider, error: 0 - No pr
- 如何取出数据库中n-1条记录?
- 断网之后 数据库连不上的原因是什么?
- 关于存储过程变量的问题
- 请教数据自动导入问题
- 字符串转换为 datetime
select 关键字,count(1) from tb where charindex(关键字,colname)>0 group by 关键字 order by count(1) desc
举个例子:KW级数据取top 10可能响应时间是3秒-5秒,加上order by可能是35-39秒。楼主想想吧。
declare @table table (col varchar(12))
insert into @table
select '中国日本韩国' union all
select '中国北京奥运' union all
select '中国北京汽车' union all
select '上海海尔'select * from @table
/*
col
------------
中国日本韩国
中国北京奥运
中国北京汽车
上海海尔
*/
--假设关键词是中国、北京、奥运select
col
from @table
order by (case charindex('中国',col) when 0 then 0 else 1 end +
case charindex('北京',col) when 0 then 0 else 1 end +
case charindex('奥运',col) when 0 then 0 else 1 end ) desc /*
中国北京奥运 --有3个关键词
中国北京汽车 --有2个关键词
中国日本韩国 --有1个关键词
上海海尔 --没有关键词
*/
set @str = '弹开层的问题';select
substring(@str,number,2) as s
into #t
from master.dbo.spt_values
where type='p'
and number>=1 and number<len(@str);select
a.col
from tb as a
join #t as b
on charindex(a.s,b.col)>0
group by a.col
order by sum(len(b.col)-len(replace(b.col,a.s,''))/len(a.s)) desc
insert @tb select 1,'这是弹开能看明白问题?'
union all select 2,'开层就是这样'
union all select 3,'小梁爱兰儿'
union all select 4,'这个问题很难,是弹开吗,还是开层的问题?'
union all select 5,'测试数据'--查询如下:declare @str varchar(100);
set @str = '弹开层的问题';select
substring(@str,number,2) as s
into #t
from master.dbo.spt_values
where type='p'
and number>=1 and number<len(@str);select
a.id,a.col
from @tb as a
join #t as b
on charindex(b.s,a.col)>0
group by a.id,a.col
order by sum(len(a.col)-len(replace(a.col,b.s,''))/len(b.s)) desc;--删除测试
drop table #t/*
id col
----------- --------------------------------------
4 这个问题很难,是弹开吗,还是开层的问题?
1 这是弹开能看明白问题?
2 开层就是这样(3 row(s) affected)
*/