ASPCMS多条件匹配搜索

时间:2022-05-22 05:38:42

比如后台新增一个字段叫做产品类型,文本字段,P_leixing

在根目录下找到search.asp,在加以下代码

<!--#include file="inc/AspCms_SettingClass.asp" -->
<%
echoContent()
Sub echoContent()
dim page,keys,leixing
page=filterPara(getForm("page","both"))
keys=filterPara(getForm("keys","both"))
leixing=filterPara(getForm("leixing","both"))
'if isNul(keys) then alertMsgAndGo "请输入关键词","-1"
if isNul(page) then page=1
if isNum(page) then page=clng(page) else echoMsgAndGo "页面不存在",3 end if

dim templateobj,channelTemplatePath : set templateobj=new TemplateClass
dim typeIds,rsObj,rsObjtid,Tid,rsObjSmalltype,rsObjBigtype
Dim templatePath,tempStr
templatePath=sitePath&"/"&"templates/"&setting.defaultTemplate&"/"&setting.htmlFilePath&"/search.html"
'die templatePath
if not CheckTemplateFile(templatePath) then echo "search.html"&err_16

with templateObj
.content=loadFile(templatePath)
.parseHtml()
.parseCommon()
.parseList 0,page,"searchlist",keys,leixing,"searchlist"
echo .content
end with
set templateobj =nothing : terminateAllObjects
End Sub
%>

修改模版文件search.html

产品类型:<input type="text" name="leixing" value=""/> 

然后修改执行的文件 inc\AspCms_MainClass.asp

1394行左右

Public Function parseList(typeIds,currentPage,pageListType,keys,leixing,showType)
1412行左右

'修改这里哦亲
if not "0"=searchType then typeStr=" and a.SortID in (select {prefix}Sort.sortid from {prefix}Sort where sortType="&searchType&") "
sql="select ContentID,a.SortID,a.GroupID,a.Exclusive,Title,P_leixing,Title2,TitleColor,IsOutLink,OutLink,Author,ContentSource,ContentTag,Content,ContentStatus,IsTop,Isrecommend,IsImageNews,IsHeadline,IsFeatured,ContentOrder,IsGenerated,Visits,a.AddTime,a.[ImagePath],a.IndexImage,a.DownURL,a.PageFileName,a.PageDesc,SortType,SortURL,SortFolder,SortFileName,SortName,ContentFolder,ContentFileName,b.GroupID "&sperStr&" from {prefix}Content as a,{prefix}Sort as b where a.LanguageID="&setting.languageID&"and a.SortID=b.SortID and ContentStatus=1 and TimeStatus=0 and a.SortID in ("&getSubSort(typeIds, 1)&") and P_leixing like '%" &leixing& "%' and Title like '%"&keys&"%'"&typeStr&orderStr
'response.Write("- -")

修改后能筛选了但是分页不知道是否好使,再就是只能模糊匹配且无法在提交时文本框中显示当前关键字

同行的建议和意见

1.找到inc\aspcms_mainclass.asp

约1360行 找到


'dim searchType
' searchType=filterPara(getForm("searchType","get"))
' if isnul(searchType) then searchType="0"
' if not "0"=searchType then typeStr=" and a.SortID in (select AspCms_Sort.sortid from AspCms_Sort where sortType="&searchType&") "
' sql="select ContentID,a.SortID,a.GroupID,a.Exclusive,Title,Title2,TitleColor,IsOutLink,OutLink,Author,ContentSource,ContentTag,Content,ContentStatus,IsTop,Isrecommend,IsImageNews,IsHeadline,IsFeatured,ContentOrder,IsGenerated,Visits,a.AddTime,a.[ImagePath],a.IndexImage,a.DownURL,a.PageFileName,a.PageDesc,SortType,SortURL,SortFolder,SortFileName,SortName,ContentFolder,ContentFileName,b.GroupID "&sperStr&" from AspCms_Content as a,AspCms_Sort as b where a.LanguageID="&setting.languageID&"and a.SortID=b.SortID and ContentStatus=1 and TimeStatus=0 and a.SortID in ("&getSubSort(typeIds, 1)&") and Title like '%"&keys&"%'"&typeStr&orderStr
' end if

修改成:

dim searchType,keyname,keyvalue
searchType=filterPara(getForm("searchType","get"))
if isnul(searchType) then searchType="0"
if not "0"=searchType then typeStr=" and a.SortID in (select AspCms_Sort.sortid from AspCms_Sort where sortType="&searchType&") "
keyname=filterPara(getForm("keyname","get"))
keyvalue=filterPara(getForm("keyvalue","get"))
if isnul(keyname) or isnul(keyvalue) then
sql="select ContentID,a.SortID,a.GroupID,a.Exclusive,Title,Title2,TitleColor,IsOutLink,OutLink,Author,ContentSource,ContentTag,Content,ContentStatus,IsTop,Isrecommend,IsImageNews,IsHeadline,IsFeatured,ContentOrder,IsGenerated,Visits,a.AddTime,a.[ImagePath],a.IndexImage,a.DownURL,a.PageFileName,a.PageDesc,SortType,SortURL,SortFolder,SortFileName,SortName,ContentFolder,ContentFileName,b.GroupID "&sperStr&" from AspCms_Content as a,AspCms_Sort as b where a.LanguageID="&setting.languageID&"and a.SortID=b.SortID and ContentStatus=1 and TimeStatus=0 and a.SortID in ("&getSubSort(typeIds, 1)&") and Title like '%"&keys&"%'"&typeStr&orderStr
else
if keys="all" then
sql="select ContentID,a.SortID,a.GroupID,a.Exclusive,Title,Title2,TitleColor,IsOutLink,OutLink,Author,ContentSource,ContentTag,Content,ContentStatus,IsTop,Isrecommend,IsImageNews,IsHeadline,IsFeatured,ContentOrder,IsGenerated,Visits,a.AddTime,a.[ImagePath],a.IndexImage,a.DownURL,a.PageFileName,a.PageDesc,SortType,SortURL,SortFolder,SortFileName,SortName,ContentFolder,ContentFileName,b.GroupID "&sperStr&" from AspCms_Content as a,AspCms_Sort as b where a.LanguageID="&setting.languageID&"and a.SortID=b.SortID and ContentStatus=1 and TimeStatus=0 and a.SortID in ("&getSubSort(typeIds, 1)&") and "&keyname&"='"&keyvalue&"'"&typeStr&orderStr
else
sql="select ContentID,a.SortID,a.GroupID,a.Exclusive,Title,Title2,TitleColor,IsOutLink,OutLink,Author,Conte

还有个
修改成:

dim searchType,keyname,keyvalue
searchType=filterPara(getForm("searchType","get"))
if isnul(searchType) then searchType="0"
if not "0"=searchType then typeStr=" and a.SortID in (select AspCms_Sort.sortid from AspCms_Sort where sortType="&searchType&") "
keyname=filterPara(getForm("keyname","get"))
keyvalue=filterPara(getForm("keyvalue","get"))
if isnul(keyname) or isnul(keyvalue) then
sql="select ContentID,a.SortID,a.GroupID,a.Exclusive,Title,Title2,TitleColor,IsOutLink,OutLink,Author,ContentSource,ContentTag,Content,ContentStatus,IsTop,Isrecommend,IsImageNews,IsHeadline,IsFeatured,ContentOrder,IsGenerated,Visits,a.AddTime,a.[ImagePath],a.IndexImage,a.DownURL,a.PageFileName,a.PageDesc,SortType,SortURL,SortFolder,SortFileName,SortName,ContentFolder,ContentFileName,b.GroupID "&sperStr&" from AspCms_Content as a,AspCms_Sort as b where a.LanguageID="&setting.languageID&"and a.SortID=b.SortID and ContentStatus=1 and TimeStatus=0 and a.SortID in ("&getSubSort(typeIds, 1)&") and Title like '%"&keys&"%'"&typeStr&orderStr
else
if keys="all" then
sql="select ContentID,a.SortID,a.GroupID,a.Exclusive,Title,Title2,TitleColor,IsOutLink,OutLink,Author,ContentSource,ContentTag,Content,ContentStatus,IsTop,Isrecommend,IsImageNews,IsHeadline,IsFeatured,ContentOrder,IsGenerated,Visits,a.AddTime,a.[ImagePath],a.IndexImage,a.DownURL,a.PageFileName,a.PageDesc,SortType,SortURL,SortFolder,SortFileName,SortName,ContentFolder,ContentFileName,b.GroupID "&sperStr&" from AspCms_Content as a,AspCms_Sort as b where a.LanguageID="&setting.languageID&"and a.SortID=b.SortID and ContentStatus=1 and TimeStatus=0 and a.SortID in ("&getSubSort(typeIds, 1)&") and "&keyname&"='"&keyvalue&"'"&typeStr&orderStr
else
sql="select ContentID,a.SortID,a.GroupID,a.Exclusive,Title,Title2,TitleColor,IsOutLink,OutLink,Author,ContentSource,ContentTag,Content,ContentStatus,IsTop,Isrecommend,IsImageNews,IsHeadline,IsFeatured,ContentOrder,IsGenerated,Visits,a.AddTime,a.[ImagePath],a.IndexImage,a.DownURL,a.PageFileName,a.PageDesc,SortType,SortURL,SortFolder,SortFileName,SortName,ContentFolder,ContentFileName,b.GroupID "&sperStr&" from AspCms_Content as a,AspCms_Sort as b where a.LanguageID="&setting.languageID&"and a.SortID=b.SortID and ContentStatus=1 and TimeStatus=0 and a.SortID in ("&getSubSort(typeIds, 1)&") and Title like '%"&keys&"%' and "&keyname&"='"&keyvalue&"'"&typeStr&orderStr
end if
end if
end if
你所提到的分页
设计到搜索结果分页,所以还要修改inc\aspc_commonFun.asp页面

约700行
strPageNumber=strPageNumber&""&pagenumber&""
修改成
keyname=filterPara(getForm("keyname","get"))
keyvalue=filterPara(getForm("keyvalue","get"))
if isnul(keyname) or isnul(keyvalue) then
strPageNumber=strPageNumber&""&pagenumber&""
else
strPageNumber=strPageNumber&""&pagenumber&""
end if
kin_wt(12:45:22):修改后搜索页的使用方法:例search.asp?searchtype=3&keys=all&keyname=P_lvyouys&keyvalue=1-300
说明keyname=列明&keyvalue=值
我之前有实现过单一价格的检索
这个参数多了 检索起来就老报错 




------------------------------------------------------------2015-12-22--------------------------------------------------------------

ASPCMS多条件搜索导致列表报错的处理方法
多条件根据上篇文章搞定后可能会出现列表报错的问题,接下来是解决方法待测试。
打开/inc/AspCms_templateFun.asp我用的是258版本、
找到645行
templateObj.parseList sortID,page,"list","",sortFolder&sortFileName&fileExt
这里注意你增加了几个字段这里就要增加几个 ,""
如我增加了俩字段那这里应该就是
templateObj.parseList sortID,page,"list","","","",sortFolder&sortFileName&fileExt


上一篇文章中替换List循环标签中我们增加的字段,这里也要有