Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Computed Column + Full-Text = Fail

Author  Topic 

AdamKosecki
Starting Member

18 Posts

Posted - 2008-05-30 : 17:16:10
I'm trying to figure to figure out the best way to query our database for

One of our developers is implementing a "global search" feature on our intranet. The idea is that a single search string will query multiple columns in a table. For example, searching for "mike fedex" would return the following records:

company | firstname | lastname | notes
FedEx | Mike | Smith | this guy is cool
Paint World | Mike | Anderson | Used to work for FedEx

but not:
Bodum | Mike | Easton | I like apples

because it does not contain all of the search terms.

I tried to create a computed column on our "contacts" table that simply concatenated all of the fields I wanted to search. The idea was to then use CONTAINS or CONTAINSTABLE on the computed column like this: SELECT... WHERE CONTAINS(computed_column, 'word1 AND word1 AND word3'). That would work great, until I realized you can't add a computed column to your full-text index.

Pain.

Any suggestions?

EDIT: The magic sauce needs to be able to search multiple terms across multiple columns with no concern for the order of the words in the search term. For example, searching for "Please Help" and "Help Please" would return the same results. Using LIKE '%Please%Help' and LIKE '%Help%Please' would return very different results.

AdamKosecki
Starting Member

18 Posts

Posted - 2008-06-02 : 12:41:07
Really? No one has any suggestions? Please?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-02 : 12:50:04
Not sure if this what you're looking for but you can try something like this:-

SELECT * FROM YourTable
WHERE COALESCE(company,'') +
COALESCE(firstname,'') +
COALESCE(lastname,'') +
COALESCE(notes,'') LIKE '%' + REPLACE(@SearchParam,' ','%') + '%'
Go to Top of Page

AdamKosecki
Starting Member

18 Posts

Posted - 2008-06-02 : 17:23:14
Thanks for taking the time to respond Visakh16.

That will not work because, for example, searching for "Adam Kosecki" will return my record, but searching for "Kosecki Adam" will not. That is why I loved my initial idea of creating a computed column to use the CONTAINS keyword - order of search phrases would not matter - but... well that's all explained in my first post.

It would be nice if you could do this: SET USE_GOOGLE_SEARCHMODE ON :)

I'm so defeated right now.
Go to Top of Page

AdamKosecki
Starting Member

18 Posts

Posted - 2008-06-06 : 10:45:00
Bump... Edited original post to make things a little clearer.

Thanks,
Adam
Go to Top of Page
   

- Advertisement -