Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

_Flávia

Código Busca Interna

Recommended Posts

Oi meu amores :)

 

Gostaria de pedir um help a vocês.

 

Não entendo quase nada de programação em asp mas estou com um projeto onde preciso de uma busca interna num site.

Vasculhei a net e achei esse código abaixo, funcionou perfeitamente, mas só tem um probleminha...

 

Preciso que ao clicar no resultado da pesquisa ele ebra numa janelinha popup com as dimensões que eu determinar.

 

Alguem poderia me ajudar... http://forum.imasters.com.br/public/style_emoticons/default/blush.gif

 

segue o código

 

<%

'Read in all the search words into one variable
strSearchWords = Trim(Request.QueryString("search"))

'If the site is in English then use the server HTML encode method
If blnEnglishLanguage = True Then
	'Replace any HTML tags with the HTML codes for the same characters (stops people entering HTML tags)
	strSearchWords = Server.HTMLEncode(strSearchWords)

'If the site is not english just change the script tags
Else
	'Just replace the script tag <> with HTML encoded < and >
	strSearchWords = Replace(strSearchWords, "<", "<", 1, -1, 1)
	strSearchWords = Replace(strSearchWords, ">", ">", 1, -1, 1)
End If

'Slit each word to be searched up and place in an array
sarySearchWord = Split(Trim(strSearchWords), " ")



'Read the file number to show from
intFileNum = CInt(Request.QueryString("FileNumPosition"))

'Set the number of files shown so far to the file number read in above
intNumFilesShown = intFileNum


'Create the file system object
Set fsoObject = Server.CreateObject("Scripting.FileSystemObject")


'If there is no words entered by the user to search for then dont carryout the file search routine
If NOT strSearchWords = "" Then


	'Get the path and the root folder to be searched
	Set fldObject = fsoObject.GetFolder(Server.MapPath("./"))
	
	'Read in the server path to this ASP script
	strServerPath = fldObject.Path & "\"
	
	'Set to true as this is searching the root directory
	blnIsRoot = True
		
	'Call the search sub prcedure
	Call SearchFile(fldObject)
			
	
	'Reset server variables
	Set fsoObject = Nothing
	Set fldObject = Nothing
	

	
	'Display the HTML table with the results status of the search or what type of search it is
	Response.Write vbCrLf & "	<table width=""98%"" border=""0"" cellspacing=""1"" cellpadding=""1"" align=""center"" bgcolor=""#efefef"">"
	Response.Write vbCrLf & " 	  <tr>"
	
	'Display that there where no matching records found
	If blnSearchResultsFound = False Then 
		Response.Write vbCrLf & " 		<td> Sua Busca:<b>" & strSearchWords & "</b>.	Desculpe, nenhum resultado.</td>"   
	
	'Else Search went OK so display how many records found
	Else	
		Response.Write vbCrLf & " 		<td> Busca: <b>" & strSearchWords & "</b>.	Resultados: " & intFileNum + 1 & " - " & intNumFilesShown & " of " & intTotalFilesFound & ".</td>"		
	End If
	
	'Close the HTML table with the search status
	Response.Write vbCrLf & "	  </tr>"
	Response.Write vbCrLf & "	</table>"
	
	
	
	
	'HTML table to display the search results or an error if there are no results
	Response.Write vbCrLf & "	<table width=""95%"" border=""0"" cellspacing=""1"" cellpadding=""1"" align=""center"">"
	Response.Write vbCrLf & "	 <tr>" 
	Response.Write vbCrLf & "	  <td>"   
	
	'If no results are found then display an error message
	If blnSearchResultsFound = False Then 
	
		'Write HTML displaying the error
		Response.Write vbCrLf & "	  <br>"
		Response.Write vbCrLf & "	   Você buscou por - <b>" & strSearchWords & "</b> - mas não encontramos nada relacinado."
	   	Response.Write vbCrLf & "	   <br><br>"
	   	Response.Write vbCrLf & "	   Sugestões:"
	   	Response.Write vbCrLf & "	   <br>"
	   	Response.Write vbCrLf & "	   <ul><li>Confira se você digitou a palavra corretamente.<li>Tente outra palavra parecida.<li>Tente buscar por outras palavras.</ul>"
	
	'Else display the results
	Else
		
		'Loop round to display each result within the search results array
		For intDisplayResultsLoopCounter = 1 to (intNumFilesShown - intFileNum)
		
			Response.Write vbCrLf & "	<br>"
			Response.Write vbCrLf & "		" & sarySearchResults(intDisplayResultsLoopCounter)
			Response.Write vbCrLf & "	<br>"
		Next
	End If
	
	'Close the HTML table displaying the results
	Response.Write vbCrLf & "		</td>"
	Response.Write vbCrLf & "	  </tr>"
	Response.Write vbCrLf & "	</table>"

End If




 
'Display an HTML table with links to the other search results
If intTotalFilesFound > intRecordsPerPage then

	'Display an HTML table with links to the other search results
	Response.Write vbCrLf & "	<br>"
	Response.Write vbCrLf & "	<table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""0"" align=""center"">"
	Response.Write vbCrLf & " 	  <tr>"
	Response.Write vbCrLf & " 		<td>"
	Response.Write vbCrLf & "		<table width=""100%"" border=""0"" cellpadding=""0"" cellspacing=""0"">"
	Response.Write vbCrLf & "		  <tr>"
	Response.Write vbCrLf & "			<td width=""50%"" align=""center"">"
	
	Response.Write vbCrLf & "		Results Page:  "
	
		
	'If the page number is higher than page 1 then display a back link		
	If intNumFilesShown > intRecordsPerPage Then 
		Response.Write vbCrLf & "		 <a href=""site_search.asp?FileNumPosition=" &  intFileNum - intRecordsPerPage  & "&search=" & Replace(strSearchWords, " ", "+") & "&mode=" & Request.QueryString("mode") & """ target=""_blank""><< Prev</a> "   		 	
	End If	 	
	
	
	'If there are more pages to display then display links to all the search results pages
	If intTotalFilesFound > intRecordsPerPage Then 
		
		'Loop to diplay a hyper-link to each page in the search results		
		For intPageLinkLoopCounter = 1 to CInt((intTotalFilesFound / intRecordsPerPage) + 0.5)
			
			'If the page to be linked to is the page displayed then don't make it a hyper-link
			If intFileNum = (intPageLinkLoopCounter * intRecordsPerPage) - intRecordsPerPage Then
				Response.Write vbCrLf & "			 " & intPageLinkLoopCounter
			Else
			
				Response.Write vbCrLf & "			  <a href=""site_search.asp?FileNumPosition=" &  (intPageLinkLoopCounter * intRecordsPerPage) - intRecordsPerPage & "&search=" & Replace(strSearchWords, " ", "+") & "&mode=" & Request.QueryString("mode") & """ target=""_blank"">" & intPageLinkLoopCounter & "</a>  "			
			End If
		Next
	End If
	
	
	'If it is Not the last of the search results than display a next link	 	
	If intTotalFilesFound > intNumFilesShown then   	
		Response.Write vbCrLf & "		 <a href=""site_search.asp?FileNumPosition=" &  intNumFilesShown  & "&search=" & Replace(strSearchWords, " ", "+") & "&mode=" & Request.QueryString("mode") & """ target=""_blank"">Next >></a>"	   	
	End If		  
	
	
	'Finsh HTML the table		  
	Response.Write vbCrLf & "			</td>"		  
	Response.Write vbCrLf & "		  </tr>"
	Response.Write vbCrLf & "		</table>"		
	Response.Write vbCrLf & "		</td>"
	Response.Write vbCrLf & "	  </tr>"
	Response.Write vbCrLf & "	</table>"
	
 
End If 

%>										</td>
									  </tr>
									</table>
									<span class="style35"><br>
									</span> </td>
								  </tr>
							  </table></td>
				  </tr>
				</table></td>
			  </tr>
			</table>
					<table width="100%" height="12" border="0" cellpadding="0" cellspacing="0">
					  <tr>
						<td height="12" bgcolor="#efefef"><div align="center" class="style32"><span class="style16">site - Todos os direitos reservados -<span class="style17"><span class="style27"> Design.Studio.com</span></span></span> </div></td>
					  </tr>
				  </table></td>
		  </tr>
		</table></td>
	  </tr>
	</table></td>
  </tr>
</table>
<map name="Map" id="Map">
  <area shape="rect" coords="12,4,60,55" href="../index.asp" />
  <area shape="rect" coords="77,6,129,54" href="#" />
  <area shape="rect" coords="142,8,195,55" href="../anuncie.asp" />
  <area shape="rect" coords="207,9,254,53" href="../buscainterna/site_search.asp" />
  <area shape="rect" coords="264,7,319,56" href="../faleconosco.asp" />
  <area shape="rect" coords="331,9,382,55" href="../faq.asp" />
</map>
</body>
</html>
<%



'Sub procedure to do the search
Public Sub SearchFile(fldObject)

	'Dimension local variabales
	Dim filObject				'File object
	Dim tsObject				'Text stream object
	Dim subFldObject			'Sub folder object
	Dim RegExpObject			'RegExp Object
	Dim strFileContents			'Holds the contents of the file being searched	
	Dim strPageTitle			'Holds the title of the page
	Dim intTitleStartPositionInFile		'Holds the start postion in the file being searched of the title
	Dim intTitleEndPositionInFile		'Holds the end postion in the file being searched of the title
	Dim strPageDescription			'Holds the description of the page
	Dim intDescriptionStartPositionInFile	'Holds the start postion in the file being searched of the description
	Dim intDescriptionEndPositionInFile	'Holds the end postion in the file being searched of the description
	Dim intSearchLoopCounter		'Loop counter to search all the words in the array
	Dim blnSearchFound			'Set to true if the search words are found	
	
	'Error handler
	On Error Resume Next
	
	
	'Loop to search each file in the folder
	For Each filObject in fldObject.Files
		
				
		'Check the file extension to make sure the file is of the extension type to be searched
		If InStr(1, strFilesTypesToSearch, fsoObject.GetExtensionName(filObject.Name), vbTextCompare) > 0 Then
		
			  'Check to make sure the file about to be searched is not a barred file if it is don't search the file
			If NOT InStr(1, strBarredFiles, filObject.Name, vbTextCompare) > 0 Then
			  
			  
				  'Open the file for searching
					Set tsObject = filObject.OpenAsTextStream
			
				'Read in the contents of the file
			   	strFileContents = tsObject.ReadAll
			 		
			 	'Initalise the search found variable to flase
			 	blnSearchFound = False
			 	
			 	
			 	'If the user has choosen to search by phrase 
			 	If Request.QueryString("mode") = "phrase" Then
			 		
			 		'Search the file for the phrase
			 		If InStr(1, LCase(strFileContents), LCase(strSearchWords), 1) then
			 		
			 			'If the search is found then set the search found variable to true
			 			blnSearchFound = True
			 		End If
			 	
			 	
			 	'Else the search is either by all or any words
			 	Else
			 			 	
			 		'If the search is by all words then initialise the search found variable to true
				 	If Request.QueryString("mode") = "allwords" then blnSearchFound = True
				 	
				 	
				 	'Loop round to search for each word to be searched
				 	For intSearchLoopCounter = 0 to UBound(sarySearchWord)
				 				
							'Search the file for the search words
							If InStr(1, LCase(strFileContents), LCase(sarySearchWord(intSearchLoopCounter)), 1) Then
						
								'If the search word is found and the search is for any words then set the search found variable to true
								If Request.QueryString("mode") = "anywords" then blnSearchFound = True
								
							Else
								'If the search word is not found and the search is for all words then set the search found variable back to false as one of the words has not been found
								If Request.QueryString("mode") = "allwords" then blnSearchFound = False
								
							End If
						Next
					End If
					
					
					
					'Calculate the total files searched
					intTotalFilesSearched = intTotalFilesSearched + 1
								
									
					
					'If the search found variable is true then display the results
					If blnSearchFound = True Then
									
														
					'Calculate the total files found 
					intTotalFilesFound = intTotalFilesFound + 1
										
					
						
					'Check that the file shown is between the the files shown so far and the maximum files to show per page
					If  intNumFilesShown < (intRecordsPerPage + intFileNum) and intTotalFilesFound > intNumFilesShown Then
	
						'Calculate the number of results shown
						intNumFilesShown = intNumFilesShown + 1
						
		
							'Read in the title of the file
						strPageTitle = GetFileMetaTag("<title>","</title>", strFileContents)
								
						'Read in the description meta tag of the file
						strPageDescription = GetFileMetaTag("<meta name=""description"" content=""",""">", strFileContents)
			 	
			 			'If the page contains no title then Page Title variable the appropriate message to display
							If strPageTitle = "" Then strPageTitle = ""
							
							'If the page contains no title then Page Description variable the appropriate message to display
							If strPageDescription = "" Then strPageDescription = ""
					   		
					   		'Place the search results into the saerch results array
					   		'Calculate the array position of the results array
					   		intResultsArrayPosition = intResultsArrayPosition + 1
					   		
					   		
					   		'Set the search results found boolean to true
					   		blnSearchResultsFound = True
					   						   		
						'If the file is in the root directory then
						If blnIsRoot = True Then
						
							'Place the search results into the search results array
							sarySearchResults(intResultsArrayPosition) = "<a href=""./" &  filObject.Name & """ target=""_blank"">" & strPageTitle & "</a><br>" & vbCrLf & "		" & strPageDescription
																	   		
					   		'Else it is not in the root directiory
					   		Else
					   			'Place the search results into the search results array
					   			sarySearchResults(intResultsArrayPosition) = "<a href=""./" & strFileURL  & fldObject.Name & "/" & filObject.Name & """ target=""_blank "">" & strPageTitle & "</a><br>" & vbCrLf & "		  " & strPageDescription			   			   								
						End If	
									
					End If				  
					  End If
							
				'Close the text stream object
					tsObject.Close
			End If
		End If
	Next



	'Loop to search through the sub folders within the site
	For Each subFldObject In FldObject.SubFolders
										
		'Check to make sure the folder about to be searched is not a barred folder if it is then don't search
		If NOT InStr(1, strBarredFolders, subFldObject.Name, vbTextCompare) > 0 Then
			
			'Set to false as we are searching sub directories
			blnIsRoot = False		
					
			'Get the server path to the file
			strFileURL = fldObject.Path & "\"
			
			'Turn the server path to the file into a URL path to the file
			strFileURL = Replace(strFileURL, strServerPath, "")
			
			'Replace the NT backslash with the internet forward slash in the URL to the file
			strFileURL = Replace(strFileURL, "\", "/")
			
			'Encode the file name and path into the URL code method
			strFileURL = Server.URLEncode(strFileURL)
			
			'Just incase it's encoded any backslashes
			strFileURL = Replace(strFileURL, "%2F", "/")
			
							
			'Call the search sub prcedure to search the web site
			Call SearchFile(subFldObject)
		End If
	Next



	'Reset server variables
	Set filObject = Nothing
	Set tsObject = Nothing
	Set subFldObject = Nothing


End Sub



'Function to read in the files meta tags
Private Function GetFileMetaTag(ByRef strStartValue, ByRef strEndValue, ByVal strFileContents)

	'Dimension Variables
	Dim intStartPositionInFile	'Holds the start position in the file
	Dim intEndPositionInFile	'Holds the end position in the file
	
	
	'Get the start position in the file of the meta tag
	intStartPositionInFile = InStr(1, LCase(strFileContents), strStartValue, 1)
	
	
	'If no description or keywords are found then you may be using http-equiv= instead of name= in your meta tags
	If intStartPositionInFile = 0 And InStr(strStartValue, "name=") Then
		
		'Swap name= for http-equiv= 
		strStartValue = Replace(strStartValue, "name=", "http-equiv=")
		
		'Check again for keywords or description
		intStartPositionInFile = InStr(1, LCase(strFileContents), strStartValue, 1)		
	End If
	
						
	'If there is a description then the position in file will be over 0
	If NOT intStartPositionInFile = 0 Then
					
		'Get the end position of the HTML meta tag
		intStartPositionInFile = intStartPositionInFile + Len(strStartValue)
						
		'Get the position in file of the closing tag for the meta tag
		intEndPositionInFile = InStr(intStartPositionInFile, LCase(strFileContents), strEndValue, 1)
	
		'Read in the meta tag from the file for the function to return
		GetFileMetaTag = Trim(Mid(strFileContents, intStartPositionInFile, (intEndPositionInFile - intStartPositionInFile)))
					
	'If the is no meta tag then the GetFileMetaTag function returns a null value
	Else
		GetFileMetaTag = ""
			   		
	End If

End Function
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Isso seria javascript, mas segue a funcao:

 

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);

para chamar faça assim:

 

<a href="#" onClick="MM_openBrWindow('pagina.asp','NomePopup','scrollbars=no,resizable=yes,width=1015,height=650')">lalalala</a>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Coloka isso onde você exibe sua busca

<a href="pagina.asp?nomedasuaação=<%=tab("campodobancodedados")%>" " onClick="MM_openBrWindow('pagina.asp','NomePopup','scrollbars=no,resizable=yes,width=1015,height=650')">ResultadoBusca</a>

Na pagina.asp

 

você resgata a ação assim:

<% id1=request.QueryString("acao") 

'compara na sua linha sql

sql = "SELECT * FROM tabela WHERE campo = '" & id1 & "' "
set tab = cnn.execute(sql)%>

Assim sempre vai exibir a o resultado da busca

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.