I have a table that has a list of restaurant names and links to another table that holds the cuisine type.
I want to provide a search box on my web page that when typing, each word is searched for in the database and results returned. I was looking for a solution that doesn't involve setting up sql full text search as I want to be able to test this using Linq to SQL.
From my old code I have a function which creates a query filter given the input text and returns all the results based on that.
Private Function SetupQuery(ByVal searchText As String) As String
Dim searchFields As New List(Of String)
searchFields.Add("Name")
searchFields.Add("Postcode")
searchFields.Add("Cuisine")
Dim firstCol As Boolean = True
Dim a() As String
Dim j As Integer
a = searchText.Trim.Split(" ")
Dim filter As String = ""
Dim compareString As String
For Each col As String In searchFields
For j = 0 To a.GetUpperBound(0)
compareString = a(j).ToUpper()
compareString = compareString.Trim()
If firstCol Then
filter = filter & col & " LIKE '" & compareString & "%' "
firstCol = False
Else
filter = filter & " or " & col & " LIKE '" & compareString & "%' "
End If
Next
Next
Return filter
End Function
This has the search fields hard coded and then loops through each one and each word in the search text to construct an OR LIKE filter.
I'm sure I could then use this in my LINQ code but it doesn't seem like an elegant solution especially since the columns are hard coded and not used how LINQ uses them.
Could anyone recomend a better way to do this or some tips in what direction to go with this?
Thanks