ntext搜索关键字

2024-01-18 05:58
文章标签 搜索 关键字 ntext

本文主要是介绍ntext搜索关键字,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

/*--ntext搜索

 按 tb 表中的 keyword 在 ta 中查找 content
 列出每个 keyword 在 content 中的具体位置
--邹建 2004.07(引用请保留此信息)--*/

--测试数据
create table ta(id int identity(1,1),content ntext)
insert ta select '我是中国人我是中国人'
union all select '中国人民爱中国 中国人民爱中国 中国人民爱中国 中国人民爱中国'

create table tb(keyword nvarchar(100))
insert tb select '中'
union all select '中国'
go

/*=================处理========================*/
if exists (select * from dbo.sysobjects where id = object_id(N'[序数表]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [序数表]
GO

--为了效率,所以要一个辅助表配合
select top 4000 id=identity(int,1,1) into 序数表
from syscolumns a,syscolumns b
alter table 序数表 add constraint pk_id_序数表 primary key(id)
go

--创建处理的存储过程
create proc p_search
as
create table #t(id int,keyword nvarchar(100),position int)

declare @s Nvarchar(4000),@keyword nvarchar(100)
declare @id int,@i int,@ilen int

declare tb cursor local for
select a.id,b.keyword,position=charindex(b.keyword,a.content)-1,ilen=4000-len(b.keyword)
from ta a,tb b
where charindex(b.keyword,a.content)>0

open tb
fetch tb into @id,@keyword,@i,@ilen
while @@fetch_status=0
begin
 select @s=substring(content,@i+1,4000)
 from ta where id=@id
 while @s<>''
 begin
  insert #t(id,keyword,position)
  select @id,@keyword,id+@i
  from 序数表
  where charindex(@keyword,@s,id)=id

  select @i=@i+@ilen,@s=substring(content,@i+1,4000)
  from ta where id=@id
 end
 
 fetch tb into @id,@keyword,@i,@ilen
end
close tb
deallocate tb
select * from #t
go

--调用示例
exec p_search
go

--删除测试
drop table 序数表,ta,tb
drop proc p_search

/*--测试结果

id          keyword   position 
----------- --------- ----------
1           中        3
1           中        8
1           中国      3
1           中国      8
2           中        1
2           中        6
2           中        9
2           中        14
2           中        17
2           中        22
2           中        25
2           中        30
2           中国      1
2           中国      6
2           中国      9
2           中国      14
2           中国      17
2           中国      22
2           中国      25
2           中国      30

(所影响的行数为 20 行)
--*/



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=42711


这篇关于ntext搜索关键字的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/618216

相关文章

认识、理解、分类——acm之搜索

普通搜索方法有两种:1、广度优先搜索;2、深度优先搜索; 更多搜索方法: 3、双向广度优先搜索; 4、启发式搜索(包括A*算法等); 搜索通常会用到的知识点:状态压缩(位压缩,利用hash思想压缩)。

hdu1240、hdu1253(三维搜索题)

1、从后往前输入,(x,y,z); 2、从下往上输入,(y , z, x); 3、从左往右输入,(z,x,y); hdu1240代码如下: #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#inc

hdu 4517 floyd+记忆化搜索

题意: 有n(100)个景点,m(1000)条路,时间限制为t(300),起点s,终点e。 访问每个景点需要时间cost_i,每个景点的访问价值为value_i。 点与点之间行走需要花费的时间为g[ i ] [ j ] 。注意点间可能有多条边。 走到一个点时可以选择访问或者不访问,并且当前点的访问价值应该严格大于前一个访问的点。 现在求,从起点出发,到达终点,在时间限制内,能得到的最大

AI基础 L9 Local Search II 局部搜索

Local Beam search 对于当前的所有k个状态,生成它们的所有可能后继状态。 检查生成的后继状态中是否有任何状态是解决方案。 如果所有后继状态都不是解决方案,则从所有后继状态中选择k个最佳状态。 当达到预设的迭代次数或满足某个终止条件时,算法停止。 — Choose k successors randomly, biased towards good ones — Close

hdu4277搜索

给你n个有长度的线段,问如果用上所有的线段来拼1个三角形,最多能拼出多少种不同的? import java.io.BufferedInputStream;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;

Oracle Start With关键字

Oracle Start With关键字 前言 旨在记录一些Oracle使用中遇到的各种各样的问题. 同时希望能帮到和我遇到同样问题的人. Start With (树查询) 问题描述: 在数据库中, 有一种比较常见得 设计模式, 层级结构 设计模式, 具体到 Oracle table中, 字段特点如下: ID, DSC, PID; 三个字段, 分别表示 当前标识的 ID(主键), DSC 当

关键字synchronized、volatile的比较

关键字volatile是线程同步的轻量级实现,所以volatile性能肯定比synchronized要好,并且volatile只能修饰于变量,而synchronized可以修饰方法,以及代码块。随着JDK新版本的发布,synchronized关键字的执行效率上得到很大提升,在开发中使用synchronized关键字的比率还是比较大的。多线程访问volatile不会发生阻塞,而synchronize

浙大数据结构:04-树7 二叉搜索树的操作集

这道题答案都在PPT上,所以先学会再写的话并不难。 1、BinTree Insert( BinTree BST, ElementType X ) 递归实现,小就进左子树,大就进右子树。 为空就新建结点插入。 BinTree Insert( BinTree BST, ElementType X ){if(!BST){BST=(BinTree)malloc(sizeof(struct TNo

JavaScript 根据关键字匹配数组项

要在JavaScript数组中根据关键字匹配项,可以使用filter方法结合一个测试函数。以下是一个示例代码,定义了一个函数findByKeyword,该函数接受一个数组和一个关键字,然后返回一个新数组,其中包含与关键字匹配的所有项。 function findByKeyword(array, keyword) {return array.filter(item => {// 假设要匹配的是对象

【python计算机视觉编程——7.图像搜索】

python计算机视觉编程——7.图像搜索 7.图像搜索7.1 基于内容的图像检索(CBIR)从文本挖掘中获取灵感——矢量空间模型(BOW表示模型)7.2 视觉单词**思想****特征提取**: 创建词汇7.3 图像索引7.3.1 建立数据库7.3.2 添加图像 7.4 在数据库中搜索图像7.4.1 利用索引获取获选图像7.4.2 用一幅图像进行查询7.4.3 确定对比基准并绘制结果 7.