Guys, does any one know how to perform a multiple key word search in asp.
My search only works if I type in one word, but if someone types in two words that it doesnt return anything. even if one word matches.
Guest
Best Answer
Here is an example
Code:
If Len(Request.Form) > 0 Then
term = Trim(Request.Form("search"))
term = Replace(term,"'","''")
If InStr(term," ") > 0 Then
term = Split(term," ")
For x=0 to Ubound(term)
If x > 0 Then
clause = clause & " AND"
End If
clause = clause & " location LIKE '%" & term(x) & "%'"
Next
Else
clause = " location LIKE '%" & term & "%'"
End If
sql = " WHERE " & clause
'sql = "SELECT * FROM location WHERE" & clause
'Response.Write sql
End If
I'd google around the internet for "asp search functions". You're trying to reinvent a wheel that's been created about a billion times. Don't do that. Go see how others did it.
One solution is to split your keywords string into separate words (eg, with a do..loop separating words by spaces, commas, etc) then create a sql query looking for each keyword (using something like multiple field LIKE '%" & keyword & "%' with AND if you want all keywords or OR if any one will do).
If you need samples of the above I will see what I can find.
Hi Doug... I tried to split the keyword and do the multiple keyword search but I am not getting the correct result. Can you please help me with the code? Below mentioned is the full code of my ASP page. I will really appreciate all your help on this.
If nLen > 0 And Len(Highlight) > 0 Then
nPos = InStr(1, Highlight, strFind, 1)
Do While nPos > 0
Highlight = Left(Highlight, nPos - 1) & _
strBefore & Mid(Highlight, nPos, nLen) & strAfter & _
Mid(Highlight, nPos + nLen)
nPos = InStr(nPos + nLenAll, Highlight, strFind, 1)
Loop
End If
End Function
'login ="select * from job where (resume LIKE '%"&loca1&"%' OR desire LIKE '%"&loca1&"%' OR email LIKE '%"&loca1&"%' OR name LIKE '%"&loca1&"%') AND (state
Like '%"&state&"%') AND (country Like '%"&country&"%') AND (visa Like '%"&visa&"%') AND status='Jobseeker' ORDER BY date1 DESC"
' login1="select * from files where uid='"&s1&"' "
' login2="select * from job where uid='"&t1&"' "
RS.Open login, Con
' RS1.Open login1,Con
' RS2.Open login2,Con