Microsoft SQL Server 2000 - 8.00.760 (Intel X86) Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation Developer Edition on Windows
NT 5.0 (Build 2195: Service Pack 4)
Create FUNCTION FN_STATEMENT(@Value varchar(300))
returns varchar(350)
as
begin
declare @Statement varchar(350)
select @value = replace(@value,' of ',' ')
select @value = replace(@value,' and ',' ')
if patindex('% %' , @value) > 0
begin
select @Statement = '( ' + replace(ltrim(rtrim(replace(@value,'"',''))),'
',' near ') + ')'
select @value = replace(ltrim(rtrim(replace(@value,'"',''))) ,' ','%')
end
else
begin
select @Statement = ' FORMSOF (INFLECTIONAL,'+ @value +') '
select @value = replace(@value,' ','%')
end
return @Statement
end
/************section with stored proc**********/
select @MaxKWItmId = Max(ItmId) from @KeyWords
if @MaxKWItmId > 0
BEGIN
Select top 1 @KWItmId = ItmId, @Statement = dbo.FN_STATEMENT(Value) ,
@WordsFound = @WordsFound + ' ' + Value , @Search = Value , @SearchRank = Rank
From @KeyWords
while (@KWItmId < @MaxKWItmId)
BEGIN
select @KWItmId = @KWItmId + 1
Select @Statement =@Statement + ' and ' + dbo.FN_STATEMENT(Value),
@WordsFound = @WordsFound + ' ' + Value,@SearchRank = @SearchRank + Rank
From @KeyWords
Where ItmId = @KWItmId
END
Insert into @Table(UrlId , Search , SearchRank, Position , WordsFound )
select UrlId , rtrim(ltrim(@WordsFound)), @SearchRank , Patindex('%' +
replace(replace(@Search,'"',''),' ','%') + '%',Content) -
80,rtrim(ltrim(@WordsFound))
FROM {oj ULARL AS C
INNER JOIN
CONTAINSTABLE(ULARL,CONTENT, @Statement) AS K
ON C.UrlId = K.[KEY]}
where datediff(day , C.DateCreate,getdate()) in (select DO.DateCreate from
@DaysOldTable DO)
and C.IsArticle in (select ST.IsArticle from @IsArticlesTable ST)
Delete from @Keywords
insert into @KeyWords(Value , Rank)
select value , (case Typ when 710 then -1 else 1 end) * rank from
COCUSFEDITM Where COCUSFED_ItmId = @FedId and Inactive = 0 and IsRequired = 0
Order by Rank Desc
select @MaxKWItmId = Max(ItmId), @KWItmId = min(ItmId) from @KeyWords
while (@KWItmId <=@MaxKWItmId)
BEGIN
select @Search = Value , @SearchRank = Rank, @Statement =
dbo.FN_STATEMENT(Value) from @KeyWords where ItmId = @KWItmId
Update T
Set SearchRank = SearchRank + @SearchRank
, WordsFound = WordsFound + ' ' + @Search
FROM {oj (ULARL AS C join @Table as T on T.UrlId = C.UrlId)
INNER JOIN
CONTAINSTABLE(ULARL,CONTENT, @Statement) AS K
ON C.UrlId = K.[KEY]}
Select @KWItmId = @KWItmId + 1
END
END
/************end section with stored proc**********/
I have a list of words the client is looking for. To limit the search I
have atleast one required word. This allows the rest of the words to search
the selecte articles rather than the other 2+ million records.
I hope this helps.
Thanks