Home > ASP Development > Multiple Keyword search in asp

Multiple Keyword search in asp



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



Was this answer helpful ? Yes No   
Guest


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.

Was this answer helpful ? Yes No   
Guest


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.

Was this answer helpful ? Yes No   
Guest


Not sure if it'd work, but if you needed both to be there I THINK (stress on the think) it might work if you do following





strSearchResult = Server.HTMLEncode(Request.Form("search"))

Was this answer helpful ? Yes No   
Guest
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.

<%
dim loca1,i

'loca1 = Server.HTMLEncode(Request.Form("id"))

'loca1=Request("id")
state=Request("t8")
country=Request("t9")
visa=Request("t15")
s1=Trim(request.querystring("s1"))
't1=Trim(request.querystring("t1"))


Set Con = Server.CreateObject ("ADODB.connection")
filePath = Server.MapPath("form.mdb")
Con.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +filePath)

Set RS = Server.CreateObject ("ADODB.Recordset")
Set RS1 = Server.CreateObject ("ADODB.Recordset")
' Set RS2 = Server.CreateObject ("ADODB.Recordset")


If Len(Request.Form) > 0 Then
loca1=Trim(request.form("id"))
loca1= Replace(loca1,"'","''")


If InStr(loca1," ") > 0 Then
loca1 = Split(loca1," ")

For x=0 to Ubound(loca1)
If x > 0 Then
clause = clause & " AND"
End If
clause = clause & " resume LIKE '%" & loca1(x) & "%'"
Next

Else
clause = " resume LIKE '%" & loca1 & "%'"

End If

login = " WHERE " & clause

login = "SELECT * FROM job WHERE" & clause

Response.Write login
'End if

'loca1=Request("id")

'loca1 = "with"
'If (Request("id") <> "") Then
' loca1 = Request("id")
'End If

Function Highlight(strText, strFind, strBefore, strAfter)
Dim nPos
Dim nLen
Dim nLenAll

nLen = Len(strFind)
nLenAll = nLen + Len(strBefore) + Len(strAfter) + 1

Highlight = strText

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

%><font color="maroon" size=3 class="text">Your Search for <b><% Response.Write Highlight(""&loca1&"", ""&loca1&"", "<font color=RED size=3>", "</font>")

%></b> displyed following results. Click on the Resume Button to view the details.<br>


<%
'end if
RS.Close
'RS1.close
'RS2.Close
Set RS = Nothing
'Set RS1 = Nothing
'Set RS2 = Nothing
Con.Close

End If
%>
Was this answer helpful ? Yes No   
sweetsamy21
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2010 by Infoqu. All rights reserved