vendredi 13 mai 2016

How to show result based on matching keywords count in descending order using asp classic

I want to show result based on highest matching keywords in descending order.

Below code shows result but not sorted in descending order.

please help me to resolve this issue as i don't want to use full text index

my code is as folows:

<%
Dim SearchWord, arrKeyWords, Cnt, tsearch, i
SearchWord = trim(request("searcha"))
SearchWord = replace(SearchWord, " and ", " ")
SearchWord = replace(SearchWord, " in ", " ")
SearchWord = replace(SearchWord, " or ", " ")
arrKeyWords = Split(SearchWord ," ") 
%>
<%
If IsArray(arrKeyWords) Then
For i = 0 To (UBound(arrKeyWords)-1)

Dim objRSsg, objCmdsg, strsg
Set objCmdsg  = Server.CreateObject("ADODB.Command")
Set objRSsg  = Server.CreateObject("ADODB.Recordset")

dim countItem, numPerPage, page, totalpages, totalRecs
countItem = 0
numPerPage = 50

objRSsg.cursorlocation = 3
if request("page") = "" then
page=1
else
page=CLng(request("page"))
end if
strsg = "select rProd_name, r_id from reseller_prod where rProd_name LIKE '%' + ? + '%' union select Prod_name, '' as r_id from product where Prod_name LIKE '%' +  ? + '%'"

With objCmdsg
.ActiveConnection = MM_connDUdirectory_STRING
.CommandText = strsg
.CommandType = adCmdText
.Parameters.Append(.CreateParameter("@sa1", adVarChar, adParamInput, 1000))
.Parameters.Append(.CreateParameter("@sa2", adVarChar, adParamInput, 1000))
.Parameters.Append(.CreateParameter("@sa3", adVarChar, adParamInput, 1000))
.Parameters.Append(.CreateParameter("@sa4", adVarChar, adParamInput, 1000))

.Parameters("@sa1").Value = arrKeyWords(i)
.Parameters("@sa2").Value = arrKeyWords(i)
.Parameters("@sa3").Value = arrKeyWords(i)
.Parameters("@sa4").Value = arrKeyWords(i) 

end with 
objRSsg.Open objCmdsg, , 1, 2
next
end if
....
....
%>

Aucun commentaire:

Enregistrer un commentaire