Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

SQL 2000 Full Text Search with Custom Thesaurus

 
   Database Help (Home) -> Full Text RSS
Next:  comprimes de acheter valium en France bon marche ..  
Author Message
Dooza

External


Since: Jan 10, 2008
Posts: 43



(Msg. 1) Posted: Thu Jul 24, 2008 4:26 pm
Post subject: SQL 2000 Full Text Search with Custom Thesaurus
Archived from groups: microsoft>public>sqlserver>fulltext (more info?)

Hi there,
I am creating a stored procedure to help my users find products in our
webshop. When they enter there search term, they can search for ALL the
words, ANY of the words, or the EXACT search term.

This is what I have so far:

CREATE PROCEDURE [dbo].[advancedSearch]
@search nvarchar(500) = NULL,
@p int = 1
AS
BEGIN

DECLARE @term nvarchar(500)

SET NOCOUNT ON;

-- @p = 0 means ANY words
-- @p = 1 means ALL words
-- @p = 2 means EXACT match

IF @p = 0 -- ANY
BEGIN
SELECT @term = '"' + @search + '"'

SELECT @term
SELECT R.RANK, I.prd_item, I.prd_wdesc, I.prd_wnotes
FROM tblProducts2 AS I JOIN FREETEXTTABLE(tblProducts2,prd_wdesc,@term)
AS R ON I.prd_item = R.[KEY]
ORDER BY R.RANK DESC
END

IF @p = 1 -- ALL
BEGIN
SELECT @term = @search
SELECT @term = REPLACE(@search, ' ',' AND ')
SELECT @term = '"' + @term + '"'

SELECT @term
SELECT R.RANK, I.prd_item, I.prd_wdesc, I.prd_wnotes
FROM tblProducts2 AS I JOIN CONTAINSTABLE(tblProducts2,prd_wdesc,
@term) AS R ON I.prd_item = R.[KEY]
ORDER BY R.RANK DESC
END

IF @p = 2 -- EXACT
BEGIN
SELECT @term = '"' + @search + '"'

SELECT @term
SELECT R.RANK, I.prd_item, I.prd_wdesc, I.prd_wnotes
FROM tblProducts2 AS I JOIN CONTAINSTABLE(tblProducts2,prd_wdesc,
@term) AS R ON I.prd_item = R.[KEY]
ORDER BY R.RANK DESC
END
END

I want to use a custom thesaurus using terms that are specific to the
products we sell. For instance, someone may type in bulbs when they mean
lamps, or gel when they mean filter, or gaffer when they mean gaffa.

We record all searches that product no results, so we can see what
people are looking for and failing to find.

I have played with Hilary's method:
http://www.indexserverfaq.com/thesaurus.htm but have found that it
ignores the first word, or requires a space at the beginning.

I may be doing this completely wrong, so any advice would be really
welcome at this stage.

Thanks in advance!

Steve

 >> Stay informed about: SQL 2000 Full Text Search with Custom Thesaurus 
Back to top
Login to vote
Hilary Cotter

External


Since: Jan 16, 2008
Posts: 133



(Msg. 2) Posted: Wed Jul 30, 2008 3:50 am
Post subject: Re: SQL 2000 Full Text Search with Custom Thesaurus [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Can you give me an example of how this fails for you?

On Jul 24, 11:26 am, Dooza <stev....TakeThisOut@SPAM.dooza.tv> wrote:
> Hi there,
> I am creating a stored procedure to help my users find products in our
> webshop. When they enter there search term, they can search for ALL the
> words, ANY of the words, or the EXACT search term.
>
> This is what I have so far:
>
> CREATE PROCEDURE [dbo].[advancedSearch]
>         @search nvarchar(500) = NULL,
>         @p int = 1
> AS
> BEGIN
>
> DECLARE @term nvarchar(500)
>
>         SET NOCOUNT ON;
>
> -- @p = 0 means ANY words
> -- @p = 1 means ALL words
> -- @p = 2 means EXACT match
>
> IF @p = 0 -- ANY
> BEGIN
>         SELECT @term = '"' + @search + '"'
>
>         SELECT @term
>         SELECT R.RANK, I.prd_item, I.prd_wdesc, I.prd_wnotes
>         FROM tblProducts2 AS I JOIN FREETEXTTABLE(tblProducts2,prd_wdesc,@term)
> AS R ON I.prd_item = R.[KEY]
>         ORDER BY R.RANK DESC
> END    
>
> IF @p = 1 -- ALL
> BEGIN
>         SELECT @term = @search
>         SELECT @term = REPLACE(@search, ' ',' AND ')
>         SELECT @term = '"' + @term + '"'
>
>         SELECT @term
>         SELECT R.RANK, I.prd_item, I.prd_wdesc, I.prd_wnotes
>         FROM tblProducts2 AS I JOIN CONTAINSTABLE(tblProducts2,prd_wdesc,
> @term) AS R ON I.prd_item = R.[KEY]
>         ORDER BY R.RANK DESC
> END
>
> IF @p = 2 -- EXACT
> BEGIN
>         SELECT @term = '"' + @search + '"'
>
>         SELECT @term
>         SELECT R.RANK, I.prd_item, I.prd_wdesc, I.prd_wnotes
>         FROM tblProducts2 AS I JOIN CONTAINSTABLE(tblProducts2,prd_wdesc,
> @term) AS R ON I.prd_item = R.[KEY]
>         ORDER BY R.RANK DESC
> END
> END
>
> I want to use a custom thesaurus using terms that are specific to the
> products we sell. For instance, someone may type in bulbs when they mean
> lamps, or gel when they mean filter, or gaffer when they mean gaffa.
>
> We record all searches that product no results, so we can see what
> people are looking for and failing to find.
>
> I have played with Hilary's method:http://www.indexserverfaq.com/thesaurus.htmbut have found that it
> ignores the first word, or requires a space at the beginning.
>
> I may be doing this completely wrong, so any advice would be really
> welcome at this stage.
>
> Thanks in advance!
>
> Steve

 >> Stay informed about: SQL 2000 Full Text Search with Custom Thesaurus 
Back to top
Login to vote
Dooza

External


Since: Jan 10, 2008
Posts: 43



(Msg. 3) Posted: Wed Jul 30, 2008 1:14 pm
Post subject: Re: SQL 2000 Full Text Search with Custom Thesaurus [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hilary Cotter wrote:
> Can you give me an example of how this fails for you?

Hi Hilary, I was hoping you would reply, as you seem to the name I see
most during my hunt for full text solutions.

I have changed tack slightly, and have created this function to remove
noise words:

CREATE function [dbo].[fn_noise](@str varchar(200))
returns varchar(200) as begin

declare @txt varchar(200) declare
@t table(word varchar(50))

--Split search text into words - space separator
insert @t(word) select value from
dbo.fn_Split(@str,' ')

--remove noise words by joining to noise table
delete from @t from @t t join
tblNoise s (nolock) on t.word=s.noiseword

--reassemble string
SELECT @txt = COALESCE(@txt +' ','') + word FROM @t SELECT @txt
=@txt

return @txt end

I have also created a thesaurus function, but I don't use it directly in
my search, I just offer the alternatives like Google does, as some of my
thesaurus words are actual products:

ALTER function [dbo].[fn_thesaurus2](@str varchar(200))
returns varchar(200) as begin

declare @txt varchar(200) declare
@t table(word varchar(50))

--Split search text into words - space separator
insert @t(word) select value from
dbo.fn_Split(@str,' ')

--insert thesaurus words
insert @t(word) select synonyms from tblThesaurus inner join @t on word
= tblThesaurus.product_name

--remove original word that matached the thesaurus word
delete from @t from @t t join
tblThesaurus s (nolock) on t.word = s.product_name

--remove noise words by joining to noise table
delete from @t from @t t join
tblNoise s (nolock) on t.word=s.noiseword

--reassemble string
SELECT @txt = COALESCE(@txt +' ','') + word FROM @t SELECT @txt
=@txt

return @txt end

If/when I do run into more problems I now know where to find you Smile

Kind regards,

Steve
 >> Stay informed about: SQL 2000 Full Text Search with Custom Thesaurus 
Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> Full Text All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]