VB icon

Simple Search

Submitted on: 1/5/2015 6:23:00 AM
By: Jorge Cisneros (from psc cd)  
Level: Advanced
User Rating: By 5 Users
Compatibility: ASP (Active Server Pages)
Views: 373
     Search in the site for any word
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
' Name: Simple Search
' Description:Search in the site for any word
' By: Jorge Cisneros (from psc cd)
' Returns:The pages that containt the especific word

<% if Request("SearchText") <> "" then
		response.write "<TITLE>Buscando Resultados para"& Request("SearchText")& "</TITLE>"
		response.write "<TITLE>Página de busqueda </TITLE>"
end if %>
<form method="post" action="search.asp">
 <div align="center"></div>
 <div align="center">
<table bgcolor="#0033CC" border="0" bordercolorlight="#00FFFF" bordercolordark="#000000">
<td> <font color="#CCCCCC"> <font color="#FFFFFF">Buscar</font> 
 <input type="text" name="SearchText" size="40">
 </font> </td>
<td> <font color="#CCCCCC"> 
 <input type="submit" name="Submit2" value="Buscar">
<td height="32"> <font color="#CCCCCC"> <font color="#FFFFFF">Mostrar 
 <select name="rLength" >
<option value="200" SELECTED>Descripción Larga 
<option value="100">Descripción Corta 
<option value="0">Solo Url 
 <select name="rResults">
<option value="10" SELECTED>10 
<option value="25">25 
<option value="50">50 
 </font> </td>
<td height="32"> <font color="#CCCCCC"> 
 <input type="reset" name="Reset" value="Borrar">
<p><% if Request("SearchText") <> "" then %> </p>
<p><B>Buscando Resultados para '<%=Request("SearchText")%>'</B><BR>
' Buscador Simple. Autor Jorge Cisneros jorgeci@hotmail.com
Const fsoForReading = 1
Dim objFile, objFolder, objSubFolder, objTextStream 
Dim bolCase, bolFileFound
dim strDeTag, Ext, strFile, strContent, strRoot, strTag, strText, strTitle, strTitleL 
Dim reqLength, reqNumber, count
strFile = ".asp .htm .html .js .txt .css"
strRoot = "/"
strText = Request("SearchText")
If Request("Case") = "on" Then bolCase = 0 Else bolCase = 1
If Request("rResults") = "10" Then reqNumber = 10
If Request("rResults") = "25" Then reqNumber = 25
If Request("rResults") = "50" Then reqNumber = 50
reqLength = Request("rLength")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath(strRoot))
CurURL= "http://" & Request.serverVariables("SERVER_NAME") 
CurPath = objFolder
For Each objSubFolder in objFolder.SubFolders
If Not bolFileFound then Response.Write "La busqueda no encontro nada.."
If bolFileFound then Response.Write "<B>Fin de la busqueda</B>"
Set objTextStream = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
Sub schSubFol(objFolder)
	For Each objFile in objFolder.Files
		If Count + 1 > reqNumber or strText = "" Then Exit Sub
		If Response.IsClientConnected Then
			'Abrir solo si es archivo conocido
			strext = right(objFile.Name,3)
			if instr(1,strFile,strext) > 0 then
 				Set objTextStream = objFSO.OpenTextFile(objFile.Path,fsoForReading)
				strContent = objTextStream.ReadAll
				If InStr(1,strContent,strtext) > 0 Then
				postitle = InStr(1, strContent, "<TITLE>",1)
				If postitle > 0 Then
					strTitle = Mid(strContent, postitle + 7, InStr(1, strContent, "</TITLE>", 1) - (postitle + 7)) 
					strTitle = "Sin Titulo"
				end if
				Count = Count + 1
				Response.Write "<DL><DT><B><I>"& Count &"</I></B> - <A HREF="&Obt_Url(objFile.path) & ">" & strTitle & "</A></DT><BR><DD>"
				strTitleL = InStr(1, strContent, "</TITLE>", 1) - InStr(1, strContent, "<TITLE>", 1) + 7
				strDeTag = ""
				bolTagFound = False
				Do While InStr(strContent, "<")
					bolTagFound = True
					strDeTag = strDeTag & " " & Left(strContent, InStr(strContent, "<") - 1)
					strContent = MID(strContent, InStr(strContent, ">") + 1)
				strDeTag = strDeTag & strContent
				If Not bolTagFound Then strDeTag = strContent
					If reqLength = "0" Then
						Response.Write obt_url(objFile.Path) & "</DD></DL>"
						Response.Write Mid(strDeTag, strTitleL, reqLength) & "...<BR><I><FONT SIZE='2'>URL: " & obt_url(objFile.Path) & " - Ultima modificación: " & objFile.DateLastModified & " - " & FormatNumber(objFile.Size / 1024) & "Kbytes</FONT></I></DD></DL>"
					end if
					bolFileFound = True
				End If
			End If
		End If
End Sub
Function Obt_Url (nompath)
	obt_url = CurUrl +"/"+ right(nompath,len(nompath) - len(curpath)-1)
end function
<% end if %>

Other 1 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.