<%
'=======================================================
' 欢迎使用《阿赛大型门户网站系统V3.0》，简称“AsaiMHV3”
' 技术支持、商业版咨询、官方唯一指定联系QQ“4941172”
' 官方网站：http://77ya.com      程序负责人：阿赛
'=======================================================

Class Cls_Search
	Public sKeyWord						'关键字
	Public Inc_Url						'链接
	Public Inc_SQL						'组装SQL
	Private Inc_Tmp						'临时
	Private sTypes						'搜索类型
	Private sTerm						
	'//* 类初始化 *//
	Private Sub Class_Initialize()
		sKeyWord=""
		sTypes=""
		sTerm=""
		Inc_Url="?"
		Inc_Tmp=""
	End Sub

	Public Property Get KeyWord
		KeyWord=sKeyWord
	End Property

	Public Sub Format_Search(stype_1,fsTypes,sqlt,st,vt)
		sKeyWord=Cls.Code_Query("keyword")
		If sKeyWord<>"" Then
			sTypes=Cls.Code_Query("sea_type")
			sTerm=Cls.Code_Query("sea_term")
			if ChannelIDs=4 then
				If InStr(","&fsTypes&",",","&sTypes&",")<1 then sTypes=stype_1
			else
				If InStr(","&fsTypes&",",",A."&sTypes&",")<1 then sTypes=stype_1
			End If
			if sTerm<>"all" then sTerm="only"
			Inc_Tmp=sql_key(keyword,sTypes,sqlt,sTerm)
			If Inc_Tmp<>"" Then Inc_Url=Inc_Url&"sea_type="&sTypes&"&sea_term="&sTerm&"&keyword="&server.urlencode(sKeyWord)&"&"
		End If
		if st=1 and Inc_Tmp<>"" then
			if Inc_SQL="" then
				'Inc_SQL=" where "&Inc_Tmp
				Inc_SQL=Inc_Tmp
			else
				Inc_SQL=Inc_SQL&" and "&Inc_Tmp
			End If
		End If
	End Sub

	Public Function SQL_Key(keyes,fields,kt,kterm)
		If Cls.Is_Null(keyes)="" Or Cls.Is_Null(fields)="" Then
			SQL_Key=""
			Exit Function
		End If
		dim ddim,dnum,di,spvar,termvar
		spvar=","
		termvar="or"
		if kt=2 then spvar=" "
		if kterm="all" then termvar="and"

		'修正搜索错误 
		'由于通配符的缘故 
		'导致我们查询特殊字符“%”、“_”、“[”的语句无法正常实现 
		'而把特殊字符用“[ ]”括起便可正常查询。build by likai-20090308 

		keyes=replace(keyes,"[","[[]") '此句一定要在最前 
		keyes=replace(keyes,"_","[_]") 
		keyes=replace(keyes,"%","[%]") 
		keyes=replace(keyes,"'","") 

		ddim=split(keyes,spvar)
		dnum=ubound(ddim)
		SQL_Key="("&fields&" like '%"&ddim(0)&"%'"
		for di=1 to dnum
			SQL_Key=SQL_Key&" "&termvar&" "&fields&" like '%"&ddim(di)&"%'"
		next
		erase ddim
		SQL_Key=SQL_Key&")"
	End Function
End Class
%>