Question

I have a containstable query on SQL server 2008:

SELECT contacts.*, [Rank] FROM 
CONTAINSTABLE(Contacts, SearchName, '("department*") AND ("work*")') tmp 
JOIN contacts on contacts.contactid = tmp.[key]
WHERE contacts.deleted = 0

This returns 1 result as expected, however if the user has entered "of" in their search criteria the query returns no results:

SELECT contacts.*, [Rank] FROM 
CONTAINSTABLE(Contacts, SearchName, '("department*") AND ("of*") AND ("work*")') tmp 
JOIN contacts on contacts.contactid = tmp.[key]
WHERE contacts.deleted = 0

The full name of the contact record is "department of work and pensions".

The same happens if the user includes "and" in their search. Why are these words breaking the query and is there a way around it or do i have to strip out the words before executing the search?

Was it helpful?

Solution

You need to learn about stop words. These are explained well in the documentation.

The short explanation, though, is that all full text engines keep a list of words that are not indexed. Prominent among these words are things like "of", "the", and similar non-content containing words. Of course, you can configure the server to actually recognize these words. And this is very important in some applications: stop words happen to be very useful when trying to determine the language of a document.

In any case, the word "of" is in the stop word list. So it is not indexed and you cannot find it using CONTAINSTABLE. If you need to search for it, you can implement your own custom stop word list and rebuild the index.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top