I have what I think is a very basic scenario, but what I've read makes it sound like this is not easy using SQL Server Full Text catalog and indexes.
I have 2 columns, First and Last name. I want to support full-text search on them such that if someone types "John Smith" people with a match on both first and last come up first.
Although it's easy to create an index across multiple columns, and easy to search multiple columns, the scoring doesn't reflect multiple columns.
SELECT [Key], Rank
FROM CONTAINSTABLE([User], (FirstName,LastName), '<CLAUSE_HERE>')
Seems like the only solution is to autogenerate a query that runs containstable
on each field, does some math, sums the scores, etc. Does that sound right? Is there an easier way around it? My actual query has a lot more fields to it - this is a simplified example.
Use the following command syntax to create the Full Text Index. Syntax: CREATE FULLTEXT INDEX ON table_name.
What is a Full Text Index? A full-text index is a special type of index that provides index access for full-text queries against character or binary column data. A full-text index breaks the column into tokens and these tokens make up the index data.
Full-Text Engine. The Full-Text Engine in SQL Server is fully integrated with the query processor. The Full-Text Engine compiles and executes full-text queries. As part of query execution, the Full-Text Engine might receive input from the thesaurus and stoplist.
To implement a full-text search in a SQL database, you must create a full-text index on each column you want to be indexed. In MySQL, this would be done with the FULLTEXT keyword. Then you will be able to query the database using MATCH and AGAINST.
Make a computed column which mushes together the fields that you're interested in searching on (in a way that makes sense for your search formats), and full-text index that.
As far as I'm aware this is the only work around if you want to full-text in this way because of the behavior you describe in your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With