Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Other Technologies / Full-Text Search / July 2008

Tip: Looking for answers? Try searching our database.

SQL 2000 Full Text Search with Custom Thesaurus

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dooza - 24 Jul 2008 16:26 GMT
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
Hilary Cotter - 30 Jul 2008 11:50 GMT
Can you give me an example of how this fails for you?

> Hi there,
> I am creating a stored procedure to help my users find products in our
[quoted text clipped - 69 lines]
>
> Steve
Dooza - 30 Jul 2008 13:14 GMT
> 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 :)

Kind regards,

Steve
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.