I have a search query that takes a phrase typed in by the user and should return a result, here is an example:
SELECT rank,[KEY] FROM CONTAINSTABLE(tblproduct, (title,subtitle,publisher_name), @search_text,15)
Where @search_text is
Set @search_text = '"my favourite word*"'
The phrase, as it stands, is an exact title match to a book in the database. However, the wildcard (*), makes it so that it doesn’t return ANY results.
When I omit the wildcard, I get an exact phrase match, however, some other phrases, like “The Imperfectionists” returns no results with or without the wildcard in place.
Why is this? What can I check?
Currently, if no result-set is generated for the wildcard, I run the query without the wildcard to see if it returns anything. If that fails too, I run a normal “like” statement.
Obviously the like statement will take forever… and I don’t want to use it on a 7.6 million-strong database for a search that’s supposed to be done with fulltext…
Any help appreciated!
Using JStead’s suggestion, I looked at the output for your string. I also found this at MSDN:
So, the word My is considered a “Noise word” by default. Adding the * causes the parser to look for any words starting with My. However, when searching the index, the word My seems to already have been removed (remember, it’s a noise word), so it doesn’t find the match.
I’m thinking about running my search string through the
sys.dm_fts_parserfunction, removing noise words, before adding the *.