Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL 2008: Turn off Stop Words for Full Text Search Query

I'm having quite a bit of difficulty finding a good solution for this:

Let's say I have a table of "Company", with a column called "Name". I have a full-text catalog on this column. If a user searched for "Very Good Company", my query would be:

SELECT     * FROM     Company WHERE     CONTAINS(Name, '"Very" AND "Good" AND "Company"') 

The problem is in this example, the word "Very" shows up in the standard list of stopwords:

SELECT     ssw.* FROM     sys.fulltext_system_stopwords ssw WHERE     ssw.language_id = 1033; 

Resulting in the query returning with no rows, even though there is a row with the name "Very Good Company".

My question is, how would I go about turning the stopwords off for my query? Or how would I go about removing them entirely?

Or is there another way I should be going about this search?

like image 838
John Avatar asked Dec 08 '11 18:12

John


People also ask

How do I remove stop words in SQL Server?

UPDATE tbl SET message = TRIM(REPLACE(CONCAT(' ', REPLACE(message, ' in ', ' in '), ' '), ' in ', '')); Edit: What you also have to consider is that stopwords in the middle of the message still have to retain the space after they're replaced, because you don't want to end up with no I in team -> no Iteam .

How do I enable full-text indexing in SQL Server?

Expand Tables, and right-click the table that you want to disable or re-enable for full-text indexing. Select Full-Text index, and then click Disable Full-Text index or Enable Full-Text index.

What are full-text stopwords?

To prevent a full-text index from becoming bloated, SQL Server has a mechanism that discards commonly occurring strings that do not help the search. These discarded strings are called stopwords. During index creation, the Full-Text Engine omits stopwords from the full-text index.


2 Answers

In case anyone else stumbles upon this problem:

It looks like there is an option to do this in 2008; it wasn't apparent to me because the database was upgraded from 2005 where I don't believe this was an option.

The first thing you need to do is set the compatibility level up to 2008:

ALTER DATABASE [MyDatabase] SET COMPATIBILITY_LEVEL = 100 

Then, when creating the full-text index through the wizard, there is a step that allows you to ignore stopwords for the index

edit: Here's the script to do it as well:

ALTER FULLTEXT INDEX ON MyTable SET STOPLIST = OFF 
like image 91
John Avatar answered Sep 21 '22 07:09

John


By default in SQL Server the stopwords are not ignored.

This is what you want to do:

sp_configure 'show advanced options', 1; RECONFIGURE; GO sp_configure 'transform noise words', 1; RECONFIGURE; GO 

REF: http://msdn.microsoft.com/en-us/library/ms187914%28v=sql.100%29.aspx

like image 36
Matt Whittingham Avatar answered Sep 19 '22 07:09

Matt Whittingham