Pessoal este codigo ele funciona mais estou com um problema e quando faço uma consulta com a palavra "SÁBADO" ele traz
tambem a palavra "sábados"
ele tem que destacar somente a palavra que foi digitada
exemplo: se eu pesquisar a palavra "sábados" ele não pode
trazer a palavra "sábado" somente a "sábados".
<%
Function destacaPalavras(StrTexto,StrPalavras)
dim arrayPalavras
on error resume next
StrPalavras = replace(trim(StrPalavras),"+",",")
StrPalavras = replace(trim(StrPalavras),"-",",")
arrayPalavras = split(StrPalavras,",")
for j=0 to ubound(arrayPalavras)
StrTexto=Replace(StrTexto, UCase(MID(arrayPalavras(j),1,1))
& LCase(MID(arrayPalavras(j),2,Len(arrayPalavras(j)))),"<font color='blue'><b>"&trim((arrayPalavras(j))) &"</b></font>",1,-1,1)
next
destacaPalavras = StrTexto
if err.number <>0 then
response.write("ERRO ao destacar palavras")
end if
End function
chamando a função
response.write(destacaPalavras("<DIV align=justify><b>"&uf&" - "&rs("cap")&":"&rs("ver")&"</b> "&(rs("versiculo"))&"</div><br>",""&s&""))
Publicidade
|
|
Page 1 of 1
Destacar palavra de busca
#1
Posted 25 September 2010 - 12:00 AM
#2
Posted 25 September 2010 - 03:10 PM
tenta este
<%
Dim strContent
strContent = "Asa Dotzler recomendou que os usuários do Firefox usem o Bing em lugar do Google.<br>Primeiro SP para o SQL Server 2008 Express Edition já está disponível."
if NOT IsEmpty(Request.Form("fldSearch")) and NOT trim(Request.Form("fldSearch")) = "" then
set regX = New RegExp
src = Request.Form("fldSearch")
regX.Pattern = src
regX.IgnoreCase = true
regX.Global = true
set theString = regX.Execute(strContent)
For each matchFound in theString
strContent = Replace(strContent, matchFound.Value, "<span class=""nbgylw"">" & matchFound.Value & "</span>")
Next
set regX = nothing
set theString = nothing
end if
%>
<HTML>
<HEAD>
<TITLE> Highlighting </TITLE>
<style>
body {font-family: Arial, Verdana, Helvetica, sans-serif; background-color: #FFFFFF;}
.nbgylw {font-family: Arial, Verdana, Helvetica, sans-serif; background-color: #FFFFCC;}
</style>
</HEAD>
<body>
<table cellpadding="0" cellspacing="5" width="100%" border="0">
<tr><td>
<form action="highlight.asp" method="post">
<input type="text" name="fldSearch"> <input type="submit" value="Pesquisar">
</form>
</td></tr>
<tr><td>
<%=strContent%>
</td></tr>
</table>
</BODY>
</HTML>
%>
#3
Posted 25 September 2010 - 07:09 PM
Continua do mesmo jeito do 1º código eu tenho que resolver este impasse alguem tem uma ideia?
#4
Posted 26 September 2010 - 01:32 PM
use o operador LIKE do SQL, e você pode fazer a consulta direto no bd
#5
Posted 26 September 2010 - 11:01 PM
estou fazendo a consulta no banco e estou usando assim LIKE '%"&s&"%' mais não dar certo.
#6
Posted 27 September 2010 - 09:33 AM
dá um response.wrote na sua string SQL, para ver o que esta sendo passado, tem um exemplo que coloquei no site, onde você pode escolher entre palavra exata, frase ou termo, dá uma pesquisada que vai te ajudar
#8
Posted 01 October 2010 - 03:49 PM
olha este exemplo
'------------- SEARCH
'******************************************************
'******************************************************
On Error Resume Next
PAGE_SIZE = 20 ' visualização do número de resultados
strURL = Request.ServerVariables("URL") ' the URL or Query string
'------------- q = input textO
strSearch = Request.QueryString("q") ' the input text
If strSearch = "" Then
Server.htmlencode(Trim(Request.Form("q")))
End If
strSearch = Replace(strSearch, "'", "''")
'----------- p =RESULTADO PAGINAÇÃO
IF isnumeric(Request.QueryString("p")) = True OR Request.QueryString("p") = "" THEN
' Retrieve page to show or default to the first
If Request.QueryString("p") = "" OR Request.QueryString("p") < 1 Then
iPageCurrent = 1
Else
iPageCurrent = CInt(Request.QueryString("p"))
End If
ELSE
iPageCurrent = 1
END IF
p = iPageCurrent
'----------------- t =SELECIONANDO TABELA
IF isnumeric(Request.QueryString("t")) = True OR Request.QueryString("t") = "" THEN
If Request.QueryString("t") = "" OR Request.QueryString("t") < 1 Then
searchTable = 1 '1
Else
searchTable = 1 'CInt(Request.QueryString("t"))
End If
ELSE
searchTable = 2 '1
END IF
'------------------- m = SEARCH METHOD
IF isnumeric(Request.QueryString("m")) = True OR Request.QueryString("m") = "" THEN
' Retrieve m
If Request.QueryString("m") = "" OR Request.QueryString("m") < 1 Then
strMethod = 2
Else
strMethod = CInt(Request.QueryString("m"))
End If
ELSE
strMethod = 2
END IF
'---------------O FORM
%>
<form method="get" action="<%= strURL %>">
<p>
<input type="radio" name="m" value="1" <% IF strMethod = 1 THEN response.write "checked=""checked""" END IF%> />
E
<input type="radio" name="m" value="2" <% IF strMethod = 2 OR strMethod = "" THEN response.write "checked=""checked""" END IF%> />
OU
<input type="radio" name="m" value="3" <% IF strMethod = 3 THEN response.write "checked=""checked""" END IF%> />
Exato</p>
<p><input type="text" class="input3" name="q" value="<%= Trim(strSearch) %>" /></p>
<p><input type="submit" value="Procura" />
<br /><br /></p>
</form>
<%
If strSearch <> "" Then
Session("strSearch") = strSearch
IF isnumeric(Request.QueryString("t")) = True OR Request.QueryString("t") = "" THEN
If Request.QueryString("t") = "" OR Request.QueryString("t") < 1 Then
searchTable = 1 '1
Else
searchTable = 1 'CInt(Request.QueryString("t"))
End If
ELSE
searchTable = 1' 1
END IF
' A TABELA
Select Case searchTable
Case CInt("1")
dbTable = "tMessages"
'strDBPath = Server.MapPath("/blogg/blog.mdb")
Case CInt("2")
'dbTable = "events"
'strDBPath = Server.MapPath("")
Case Else
dbTable = "tMessages"
'strDBPath = Server.MapPath("")
End Select
'------------------ SQL
'SPLIT STRING INTO ARRAYS
'FOR and AND or CLAUSE SQL
'----------------- SQL tMessages table
IF searchTable = "1" THEN
IF strMethod < 3 THEN
If strMethod = 1 Then
strSplit = Replace(strSearch," "," and ")
Else
strSplit = Replace(strSearch," "," or ")
End If
colTerms = split(strSplit," and ",-1,1)
iUpperTerms = UBound(colTerms)
strWhereClause = ""
'FIELD CLAUSES
nr = 0
Do while nr <= 5
nr = nr + 1
searchField = CInt(nr)
Select Case searchField
Case CInt("1")
strTableInClause = "fDate"
Case CInt("2")
strTableInClause = "fHeadline"
Case CInt("3")
strTableInClause = "fMessage"
Case CInt("4")
strTableInClause = "fAuthor"
Case CInt("5")
strTableInClause = "fnota"
'Case Else
End Select
For iLoop = LBound(colTerms) to iUpperTerms
orTerms = split(colTerms(iLoop)," or ",-1,1)
iUpperOrTerms = UBound(orTerms)
strWhereClause = strWhereClause & ""
for iOrLoop = LBound(orTerms) to iUpperOrTerms
strWhereClause = strWhereClause & strTableInClause & " LIKE '%" & Trim(orTerms(iOrLoop)) & "%' "
if iOrLoop < iUpperOrTerms then
strWhereClause = strWhereClause & " OR "
end if
next
strWhereClause = strWhereClause & ""
if iLoop < iUpperTerms then
strWhereClause = strWhereClause & " AND "
end If
Next
if nr <= 4 then
strWhereClause = strWhereClause & " OR "
end if
Loop
ELSE
'MÉTODO 3 FRASE exatA
strWhereClause = "fDate LIKE '%" & strSearch & "%' OR fHeadline LIKE '%" & strSearch & "%' OR fMessage LIKE '%" & strSearch & "%' OR fAuthor LIKE '%" & strSearch & "%' OR fnota LIKE '%" & strSearch & "%'"
END IF
strWhereClause2 = "WHERE (" & strWhereClause & ") AND (online = CBool(-1))"
' ORDER BY
strOrderClause = "ORDER BY fdate DESC"
IF strMethod = 3 THEN
strSQL = "SELECT * FROM "& dbTable &" "& strWhereClause2 &" "& strOrderClause &";"
ELSE
strSQL = "SELECT * FROM "& dbTable &" "& strWhereClause2 &" "& strOrderClause &";"
END IF
END IF
Response.write strSQL
'---------- END SQL tMessages
'--------- CONEXAO OPEN & EXE SQL
Set myRecSet = Server.CreateObject("ADODB.Recordset")
myRecSet.PageSize = PAGE_SIZE
myRecSet.CacheSize = PAGE_SIZE
' constants
adOpenStatic = 3
adLockReadOnly = 1
adCmdText = &H0001
myRecSet.Open strSQL, sConn, adOpenStatic, adLockReadOnly, adCmdText
iRecordCount = myRecSet.RecordCount
iPageCount = myRecSet.PageCount
' RESULTADO COUNTER
strCountRecord = iRecordCount
If iPageCurrent = 1 Then
strCount = strCountRecord - iRecordCount + 1
Else
strCount = iPageCurrent * PAGE_SIZE - PAGE_SIZE + 1
'strCountRecord - + * iPageCurrent
End If
If iRecordCount = 0 Then
%> <p>Desculpa, sua busca não retornou resultados.<br />
Sua Busca por - <b><%=strSearch%></b> - não retornou documentos.</p>
<%
Else
myRecSet.AbsolutePage = iPageCurrent
If iRecordCount <= PAGE_SIZE then
toRecord = iRecordCount
else
toRecord = strCount + PAGE_SIZE - 1
End if
If toRecord => iRecordCount then
toRecord= iRecordCount
End if
%>
<p>Mostrando resultado <%=strCount%> - <%=toRecord%> de <%=iRecordCount %>. Paginas <%= iPageCurrent %> / <%= iPageCount %>. </p>
<br /><p>
<%
If iPageCurrent > 1 Then
%>
<a href="<%= strURL %>?m=<%= Server.URLEncode(strMethod) %>&t=<%= Server.URLEncode(searchTable) %>&q=<%= Server.URLEncode(strSearch) %>&p=<%= iPageCurrent - 1 %>" title="Previous">
‹‹</a>
<%
End If
For I = 1 To iPageCount
If I = iPageCurrent Then
%>
<%= I %>
<%
Else
%>
<a href="<%= strURL %>?m=<%= Server.URLEncode(strMethod) %>&t=<%= Server.URLEncode(searchTable) %>&q=<%= Server.URLEncode(strSearch) %>&p=<%= I %>" title="<%= I %>"><%= I %></a>
<%
End If
Next
If iPageCurrent < iPageCount Then
%>
<a href="<%= strURL %>?m=<%= Server.URLEncode(strMethod) %>&t=<%= Server.URLEncode(searchTable) %>&q=<%= Server.URLEncode(strSearch) %>&p=<%= iPageCurrent + 1 %>" title="Next"> ››</a>
<%
End If
%></p>
<%
'----------------RESULTADO LOOP
Do While Not myRecSet.EOF And myRecSet.AbsolutePage = iPageCurrent
intNumMatches = 0
allregText = ""
regWriteOut = ""
If strSearch = " " then
strSearch = ""
End if
Set objRegExp = New RegExp
objRegExp.Global = True
objRegExp.IgnoreCase = True
If dbTable = "tMessages" then
allregText = myRecSet.Fields("fDate").Value & " " & myRecSet.Fields("fHeadline").Value & " " & myRecSet.Fields("fMessage").Value & " " & myRecSet.Fields("fAuthor").Value
End If
allregText = Replace(allregText, "<", "", 1, -1, 1)
allregText = Replace(allregText, ">", "", 1, -1, 1)
allregText = UTFtoISO(allregText)
If strMethod = 3 then
objRegExp.Pattern = strSearch
Set objMatches = objRegExp.Execute(allregText)
intNumMatches = objMatches.Count
End if
If strMethod < 3 then
sarySearchWord = Split(strSearch, " ")
For intSearchLoopCounter = 0 to UBound(sarySearchWord)
objRegExp.Pattern = "" & sarySearchWord(intSearchLoopCounter) & ""
Set objMatches = objRegExp.Execute(allregText)
intNumMatches = intNumMatches + objMatches.Count
Next
End if
If intNumMatches => 1 Then
If intNumMatches > 1 then
regWriteOut = "" & intNumMatches & " hits."
Else
regWriteOut = "" & intNumMatches & " hit."
End If
End If
Set objRegExp = Nothing
%>
<% IF dbTable = "tMessages" THEN %>
<p><br /><br />
<%=strCount%>. <a href="default.asp?id=<%= myRecSet.Fields("id").Value %>" title="<%=myRecSet.Fields("fHeadline").Value%>"><%= myRecSet.Fields("fHeadline").Value %></a>
<br /><%= RemoveHTML(Left(myRecSet.Fields("fMessage").Value,instrrev(Left(myRecSet.Fields("fMessage").Value,280),"")))%>
<br />
Postado: <%= year(myRecSet.Fields("fdate").Value) & "-" & right("00" & cstr(month(myRecSet.Fields("fdate").Value)),2) & "-" & right("00" & cstr(day(myRecSet.Fields("fdate").Value)),2) & ". " & regWriteOut%>
</p>
<% END IF%>
<%
strCount = strCount + 1
myRecSet.MoveNext
Loop
'---------------- RESULTADO LOOP END
%>
<br /><br /><p>
<%
If iPageCurrent > 1 Then
%>
<a href="<%= strURL %>?m=<%= Server.URLEncode(strMethod) %>&t=<%= Server.URLEncode(searchTable) %>&q=<%= Server.URLEncode(Session("strSearch")) %>&p=<%= iPageCurrent - 1 %>" title="Previous">‹‹</a>
<%
End If
For I = 1 To iPageCount
If I = iPageCurrent Then
%>
<%= I %>
<%
Else
%>
<a href="<%= strURL %>?m=<%= Server.URLEncode(strMethod) %>&t=<%= Server.URLEncode(searchTable) %>&q=<%= Server.URLEncode(Session("strSearch")) %>&p=<%= I %>" title="<%= I %>"><%= I %></a>
<%
End If
Next
If iPageCurrent < iPageCount Then
%>
<a href="<%= strURL %>?m=<%= Server.URLEncode(strMethod) %>&t=<%= Server.URLEncode(searchTable) %>&q=<%= Server.URLEncode(Session("strSearch")) %>&p=<%= iPageCurrent + 1 %>" title="Next">››</a>
<%
End If
%>
<%
End If
%></p>
<%
' CLOSE & DISPOSE
myRecSet.Close
Set myRecSet = Nothing
End If
'---------------- SEARCH END
'******************************************************
'******************************************************
%>
Share this topic:
Page 1 of 1
Similar Topics
| Topic | Forum | Started By | Stats | Last Post Info | |
|---|---|---|---|---|---|
|
Integração Flash + Asp
Como o flash buscar informações no Asp. |
Flash & ActionScript |
Blackened
|
|
|
|
Mercado chinês de busca cresce 38% no 3o trimestre
|
Notícias |
Notícias
|
|
|
|
jogo palavras cruzadas
|
Flash & ActionScript |
gabior
|
|
|
|
Britney Spears e Paris Hilton estão entre as mais buscadas na web
|
Notícias |
Notícias
|
|
|
|
Ajuda com busca em PHP
|
PHP |
ernestorp
|
|
|
|
Bing e Google ampliam participação nas buscas em novembro dos EUA
|
Notícias |
Notícias
|
|
|
|
Em Frankfurt, livreiros buscam sinais de esperança na Internet
|
Notícias |
Notícias
|
|
|
|
Site de buscas pode lançar celular próprio neste mês
|
Notícias |
Notícias
|
|
Publicidade
|
|

Help













