Reputation: 5824
I am trying to ascertain the best way of implementing a partial search on two columns within a table. The aim is to have this search perform as quickly as possible.
Our issue is that our database is hosted on SQL Azure; which does not support FullTextIndexing. This means the only native commands available to us in SQL are CHARINDEX()
and LIKE '% %'
.
The structure of the query if we were to do it in pure T-SQL would be:
DECLARE @SearchTerm VarChar(255) = 'Luke'
SELECT AU.UserID,
AU.FirstName,
AU.Surname
FROM dbo.Users AU
WHERE AU.FirstName LIKE '%'+@SearchTerm+'%'
OR AU.Surname LIKE '%'+@SearchTerm+'%'
Also available to us is the ability to use Lucene; we already have it set up on a Worker Role on Windows Azure however we would have to maintain the integrity of the data both inside the database and within Lucene.
What I want to find out is:
LIKE
search in T-SQL than what I am using abovedbo.Users
table)Upvotes: 1
Views: 413
Reputation: 5693
Adding a calculated column containing both first and last names will force the results to contain both the first and the last name, but your SQL above is for matching either the first OR the last name.
If you want to match first AND last name, a calculated column may be faster as there are tricks the database programmer can apply for you (example: Boyer-Moore fast string searching, which gets faster as the pattern size increases).
My experience with Lucene is that it is significantly faster than any database search -- I've seen nothing faster on everyday hardware. But as you say, you will have to keep the Lucene index in sync with the database.
Upvotes: 2