Universal CSS Navigation Menu Support Product Page

This topic was archived

search feature

Asked 09 Dec 2009 17:56:20
1
has this question
09 Dec 2009 17:56:20 Michael Need posted:
Does anyone have an ASP script for the search box feature?

Replies

Replied 09 Dec 2009 20:08:22
09 Dec 2009 20:08:22 Frank Cavalier replied:
Hi Mike,

Have you checked out www.atomz.com? Free. I've used it in the past and it's fairly easy to implement.

--Frank
Replied 09 Dec 2009 21:37:13
09 Dec 2009 21:37:13 Frank Cavalier replied:
Mike,

There's also a free extension right here on dmxzone.

--Frank
Replied 10 Dec 2009 08:11:47
10 Dec 2009 08:11:47 Patrick Julicher replied:
Hi Mike

Are you using a database to get your website content from? If so, then there are other ways to search. Just let me know and I'll tell you how it's done.

Kind regards, Patrick
Replied 10 Dec 2009 17:23:50
10 Dec 2009 17:23:50 Michael Need replied:
QuoteMike,

There's also a free extension right here on dmxzone.

--Frank


What is it called and how do I find it?
Replied 11 Dec 2009 15:59:41
11 Dec 2009 15:59:41 Miroslav Zografski replied:
Replied 11 Dec 2009 17:00:46
11 Dec 2009 17:00:46 Michael Need replied:
Quotewww.dmxzone.com/go?3710


Thanks very much!
Replied 11 Dec 2009 19:51:14
11 Dec 2009 19:51:14 Patrick Julicher replied:
Hi Michael,

Good luck with it. If this does not work for you, you can always try the following if your page's content comes from a database:

Post the search form to a page called something like results. On this page, get the URL or Form parameter and use it to filter a recordset. This recordset gets all the records from the content table where the content field contains the parameter.

Kind regards, Patrick
Replied 14 Dec 2009 17:53:13
14 Dec 2009 17:53:13 Michael Need replied:
What tool would be good to index and search static text in pages? ASP is preferred. Thanks.
Replied 14 Dec 2009 21:25:37
14 Dec 2009 21:25:37 Michael Need replied:
OK... So I have now an ASP search script. HOWEVER! None of the menus show up with the search box showing when I have that feature turned on.
Replied 14 Dec 2009 21:48:52
14 Dec 2009 21:48:52 Michael Need replied:
Nevermind. Good on all counts here. Search box works and shows up.
Replied 15 Dec 2009 08:11:34
15 Dec 2009 08:11:34 Patrick Julicher replied:
Hi Michael,

Care to share your solution with other users?

Kind regards, Patrick
Replied 16 Dec 2009 16:26:34
16 Dec 2009 16:26:34 Michael Need replied:
Sure. I'll post the ASP file. I DO build dynamic sites for clients, but this one is mine and I maintain my own stuff right in DW. Thus I needed a file that would index and search through static pages instead of data-driven. Here is the code to do this. The easiest way to integrate this with a DMX Zone CSS Menu search box is to place the file in your root directory and change the form code in the search box's action to the same in the file, and change "method" from "get" to "post". You can place your own logo, menu, whatever at the very top of the file. Anyways, here ya go:



<!--

  Windows Server is the best match for this type of ASP file

-->
<
%If Request.QueryString("Mode") = "Search" Then
%>
	<!-- Search Results -->
	<html>
	<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #FFFFFF;
	background-image: url(images/grad.jpg);
	background-repeat: repeat-x;
}
body,td,th {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.style1 {
	color: #FFFF00;
	font-weight: bold;
}
.style2 {font-size: 16px}
-->
    </style>
	<body>
	<div align="center">
	  <table width="800" border="0" bgcolor="#FFFFFF">
        <tr>
          <td height="292" valign="top"><div align="center" class="style1">
            <p>&nbsp;</p>
            <table border=0 align="center">
              <tr>
                <td class="text">[b]Site Search Results:[/b]
                    <p>
                      <%	
	
	'CONSTANTS
	Const	fsoForReading = 1
	
	'DECLARATIONS    
	Dim		objFile 			'OBJECT: File Object 
	Dim		objFolder			'OBJECT: Folder Object
	Dim		objSubFolder 		'OBJECT: Sub-Folder Object
	Dim		objTextStream		'OBJECT: Text Stream Object
				
	Dim		bolFileFound		'BOOLEAN: Checks if File found
				
	Dim		strFile				'STRING: Holds filename extensions
	Dim		strContent			'STRING: Search Content
	Dim		strRoot				'STRING: Root of search
	Dim		strTag				'STRING: HTML TAGS
	Dim		strText				'STRING: Search Text
	Dim		strTitle			'STRING: For HTML Title
	Dim		strTitleL			'STRING: For HTML Title
			
	Dim		Count				'INTEGER: Count of Hits
	    
	    
	
	'Set file extension for files to include in search
	strFile			= ".asp .aspx .htm .html .txt"
	
	'Set the root directory
	strRoot			= "/"
	
	'Get the Search Text
	strText			= Request("SearchText")

	'Set the current URL	
	CurURL			= "http://" & Request.serverVariables("SERVER_NAME") 

	'Create and set file and folder objects
	Set objFSO		= Server.CreateObject("Scripting.FileSystemObject")
	Set objFolder	= objFSO.GetFolder(Server.MapPath(strRoot))

	'Set the current path to the Object Folder
	CurPath			= objFolder
	    
	'Call search routine for current folder
	search(objFolder)
	
	'Call search routine to recurse folders
	For Each objSubFolder in objFolder.SubFolders
		search(objSubFolder)
	Next
	    
	'If files not found then tell user    
	If Not bolFileFound then 
		Response.Write "There are no files matching your search. Please try again."
	End If
		
	'Reset objets
	Set objTextStream = Nothing
	Set objFolder = Nothing
	Set objFSO = Nothing
	    
	    
	'SUBROUTINE: search()
	'
	'ABSTRACT:
	'	This routine searches a specific folder for HTML/WEB files containing
	'   specified text. When found, a link of the file is presented along with
	'	timestamp and URL. 
	'
	'
	'PARAMETERS:
	'	objFolder - Folder Object
	'
	'RETURN:
	'	This function displays an HTML listing of found files containing specified 
	'	search text. It also sets bolFileFound if files are found.
	'
	Sub search(objFolder)   

		Dim strext			'STRING: The currect files extension

		'Select each file within the folder
		For Each objFile in objFolder.Files
			
			'Check to ensure the client is still connected	    
			If Response.IsClientConnected Then
				
				'Get the extension of the file		
				strext = right(objFile.Name,3)
				
				'If it is a file with a valid extension		
				If instr(1,strFile,strext) > 0 AND InStr(1, "sitesearch.asp", objFile.Name) = 0 Then
					
					'Create the Text Stream	
					Set objTextStream = objFSO.OpenTextFile(objFile.Path,fsoForReading)
					
					'Read all contents		
					strContent = objTextStream.ReadAll
					
					'If the searched text is contained within the text file		
					If InStr(1,strContent,strtext) > 0 Then
						
						'If there is a title within the HTML page then use the title as rthe link
						'Otherwise show the link as specified
						postitle = InStr(1, strContent, "<TITLE>",1)								
						If postitle > 0 Then
							strTitle = Mid(strContent, postitle + 7, InStr(1, strContent, "</TITLE>", 1) - (postitle + 7)) 
						Else
							strTitle = "Static File"
						end if
						
						'Set the count of search items rturned		
						Count = Count + 1
						
						'List the link in the results page
						Response.Write "<DL><DT>[b][i]" & Count & "[/i][/b] - <A HREF=" & CurURL & UnMappath(objFile.Path) & ">" & strTitle & "</A></DT>[br]<DD>"
						Response.Write "[i]<FONT SIZE='2'>URL: "& CurURL & UnMappath(objFile.Path) & "[br]Last Modification: " & objFile.DateLastModified & " - " & FormatNumber(objFile.Size / 1024) & "Kbytes</FONT>[/i]</DD></DL>" & vbcrlf & vbcrlf
							
						'Set the bolFileFound flag	
						bolFileFound = True

					End If
					
					'Close the stream
					objTextStream.Close
				End If
			End If
		Next
	End Sub
	
	'FUNCTION: UnMappath()
	'
	'ABSTRACT:
	'	This function returns the WEB path from the SYSTEM path from the root
	'
	'
	'PARAMETERS:
	'	pathname - string of the path
	'
	'RETURN:
	'	The WEB path
	'
	Function UnMappath(ByVal pathname)
		Dim		tmp				'STRING: tmp string 
		DIM		strRoot			'STRING: for Web Path
		
		'Get the WEB root
		strRoot = Server.MapPath("/")
		
		'Change the path structure to represent the WEB path
		tmp = Replace(LCase(pathname), LCase(strRoot), "")
		tmp = Replace(tmp, "\", "/")
		
		'Return the WEB path
		UnMappath = tmp
	End Function

%>
                              </td>
              </tr>
            </table>
            <p>&nbsp;</p>
          </div></td>
        </tr>
      </table>
	</div>
	<div align="center"></div>
	</body>
	</html>
<
%Else
%>
	<!-- Search Form -->
	<html>
	<body>
	<form name="search" action="sitesearch.asp?Mode=Search" method="post" >
	<input type="text" name="SearchText" size="15" value=""><input type="submit" name="submit" value="submit">
	</form>
	</body>
	</html>

<
%End If
%>




Replied 16 Dec 2009 17:01:11
16 Dec 2009 17:01:11 Michael Need replied:
Just a tip. I noticed that the DMX Zone forum added smileys to the code I contributed. Where ever there is a smiley there should be right braket. )
Replied 16 Dec 2009 20:53:43
16 Dec 2009 20:53:43 Patrick Julicher replied:
Hi Michael,

Thank you for your contribution. I will have a look at it, try it, and maybe turn it into an FAQ so other users can also benefit from it. When you paste code in a Forum post, you can use the Code button to make the code look good, without smileys! I already did this for your post.

Kind regards, Patrick

Reply to this topic