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)
 FullText searching

Author  Topic 

stuffandblah
Starting Member

1 Post

Posted - 2010-04-23 : 04:45:30
I have a search that uses fulltext searching in SQL Server 2005 which does exact matches first, then does partial matches, etc... However, the way I'm doing it seems a tad overkill...

I basically need to do an exact match against Title, keyword & a whole load of other fields (I've not included all the other fields in the examples below), but the order for search results returned is important, e.g. title matches must be before keyword matches. So I suppose you could say that the fields are weighted.

I'm doing the searches against each field and returning the results to a temporary table where I then remove any duplicates.

EXACT MATCH

SELECT ID, title, keywords FROM Products WHERE CONTAINS((Title), '"harry" AND "potter"')

SELECT ID, title, keywords FROM Products WHERE CONTAINS((keywords), '"harry" AND "potter"')

EXACT MATCH WITH WILDCARD

SELECT ID, title, keywords FROM Products WHERE CONTAINS((Title), '"harry" AND "potter*"')

SELECT ID, title, keywords FROM Products WHERE CONTAINS((keywords), '"harry" AND "potter*"')

KEYWORD SEARCH

SELECT ID, title, keywords FROM Products WHERE CONTAINS((Title), '"harry" OR "potter"')

SELECT ID, title, keywords FROM Products WHERE CONTAINS((keywords), '"harry" OR "potter"')

KEYWORD WITH WILDCARD

SELECT ID, title, keywords FROM Products WHERE CONTAINS((Title), '"harry*" OR "potter*"')

SELECT ID, title, keywords FROM Products WHERE CONTAINS((keywords), '"harry*" OR "potter*"')

Is there a better way of doing this?
   

- Advertisement -