views:

992

answers:

3

I would like to run a search with MSSQL Full text engine where given the following user input: "Hollywood square"

I want the results to have both Hollywood and square[s] in them.

I can create a method on the web server (C#, ASP.NET) to dynamically produce a sql statement like this:

SELECT TITLE
FROM MOVIES
WHERE CONTAINS(TITLE,'"hollywood*"')
AND CONTAINS(TITLE, '"square*"')

Easy enough. HOWEVER, I would like this in a stored procedure for added speed benefit and security for adding parameters.

Can I have my cake and eat it too?

A: 

The last time I had to do this (with MSSQL Server 2005) I ended up moving the whole search functionality over to Lucene (the Java version, though Lucene.Net now exists I believe). I had high hopes of the full text search but this specific problem annoyed me so much I gave up.

Jamie Love
I went with Google FTS because the google search language is so ubiquitous, it just seemed natural. The speed isn't too bad either.
Dave
A: 

Have you tried using the AND logical operator in your string? I pass in a raw string to my sproc and stuff 'AND' between the words.

http://msdn.microsoft.com/en-us/library/ms187787.aspx

JazzHands
A: 

I agreed with above, look into AND clauses

SELECT TITLE
FROM MOVIES
WHERE CONTAINS(TITLE,'"hollywood*" AND "square*"')

However you shouldn't have to split the input sentences, you can use variable

SELECT TITLE
FROM MOVIES
WHERE CONTAINS(TITLE,@parameter)

by the way search for the exact term (contains) search for any term in the phrase (freetext)

jerryhung
I used GoogleFTS (http://www.sqlservercentral.com/articles/Full-Text+Search+(2008)/64248/) [you may need to sign up]. It takes your search terms and formats the '@parameter' to behave like google, but using SQL server T-SQL commands.Thanks to everyone for their time.
Dave