|
|
#2 (permalink) |
|
Üyelik Tarihi: 13.07.2000
Yer: LND
Mesaj: 4,284
|
site içi aramada mı sorun var yoksa Sonuçlarda kelimelerin altını çizili göstermede mi ?
Sorununu biraz daha anlaşılır bir şekilde açıklarsan sanırım yardımcı olabiliriz.
__________________
FERRUH.MAVİTUNA - İnanmıyorum, yeni site! |
|
|
|
|
|
#4 (permalink) |
|
Üyelik Tarihi: 29.11.2000
Yer: istanbul
Yaş: 28
Mesaj: 1,189
|
programmersresource.com/default.asp
burayı incelersen mantığı anlarsın..
Kod:
High-Lighting Key Words in Search Results By Jeremy Ramos A few things one should understand before attempting to understand this code. An understanding of the Basic string functions would help out a bit. This search uses a basic Access Database to query through. So lets begin the code. Here is the basic form to submit to your search page. <form method="post" action="/template.ASP"> Search our site and find the information you need! Use and, or, and the space to search for multiple words. <Input type="text" value="" name="keyword" size="30"> <input type="Submit" value="Search the site"> <Input type="hidden" value="yes" name="srch"> </form> This search will look for Boolean expressions like “and” and “or” as well as blanks like “visual basic”. Now for the ASP code to get the results from the search. <% if request("srch") = "yes" then dim count,nWord,spWord,andWord,orWord ‘ set up variables word=replace(trim(request("keyword")),"'", "''") ‘ trim spaces and replace the single quote if instr(word,"and") then ‘ check Boolean of and andW = true Word = split(word,"and") ‘now get all the words separated by and into an array for i = 0 to ubound(andWord) if i <> ubound(andWord) then kW = "'%" & andWord(i) & "%'" ‘set up SQL statement elseif i = ubound(andWord) then ‘ when it hits the end kW = kW &"'%" & andWord(i) & "%' and " ‘ add the last SQL statement end if next elseif instr(word,"or") then orW = true orWord = split(word,"or") for i = 0 to ubound(orWord) if i <> ubound(orWord) then kW = "'%" & orWord(i) & "%' and " elseif i = ubound(orWord) then kW = kW & "'%" & orWord(i) & "%'" end if next elseif instr(word," ") then spW = true spWord = split(word," ") for i = 0 to ubound(spWord) if i <> ubound(spWord) then kW = "'%" & spWord(i) & "%' or " elseif i = ubound(spWord) then kW = kW & "'%" & spWord(i) & "%'" end if next else ‘There is no Boolean value or Blank in the search word kW = "'%" & word & "%'" end if set conn = server.createobject("adodb.connection") conn.open ("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & _ server.MapPath("\your.mdb")) set rs = server.createobject("adodb.recordset") SQL = "select * from content where pageBody like " & kW Now you have your connection set and SQL built for the database search, all that’s left is to open the recordset and highlight. with rs .open SQL,conn,3,3 if not .eof then do while not .eof pageBody = rs("pageBody") ‘ pass the field value to a local variable if andW then ‘this is from above when we checked for a Boolean value of AND for i = 0 to ubound(andWord) ‘go through the search word array pos = instr(pageBody,andWord(i)) ‘find the position of the word in the field. strW = trim(left(andWord(i),pos)) ‘ now pass the word found to local variable. newStr = "<strong>" & strW & "</strong>" ‘ and highlight the found word with bold HTML tags. pageBody = replace(pageBody,strW,newStr) ‘ now put back the word into pageBody variable. If we didn’t pass the rs(“pageBody”) first it would overwrite the variable every time it goes through the loop. Next ‘Now just set up two more for loops for “OR” and for BLANKS ‘The last one will be no Boolean values or blanks. else pos = instr(pageBody,word) strW = trim(left(word,pos)) newStr = "<strong>" & strW & "</strong>" pageBody = replace(pageBody,strW,newStr) end if ‘Now write out the results from the query with the highlighted words in there. response.write pageBody & "<hr><br>" .movenext loop else response.write "<br>No matching records<br>" end if end with end if %>
__________________
Since 2k - CG | U.K. |
|
|
|
|
|
#5 (permalink) |
|
Üyelik Tarihi: 13.07.2000
Yer: LND
Mesaj: 4,284
|
Şöyle yazdığım bir fonksiyon vardı. Kısa sade ve işine yarar herhalde.
alletxt = text arama sonucu word = ise arama kelimen Request.Querystring("search") gibi Eğer birden azla kelimeyi de "," virgül ile ayırıp verirsen hepsini Google gibi farklı renkler ile çiziyor. Örn. Kullanımı : Response.Write fm_hilite(strCode,"Kelime1,Kelime2,Kelime3") Kod:
Function fm_hilite(byval alltext,byval word)
Dim Arrword, i, ArrColorList(15), Color, xx
Arrword = Split(word,",") '// Make an array from wordlist
Dim ArrNewCList, ArrListi
ArrNewCList = Array ("DF0","DFC","9F0","FCF","9FF","FF0","FF9")
For i = 0 to Ubound(Arrword)
word = Trim(Arrword(i))
If Instr(alltext,word) > 0 Then
alltext = Replace(alltext,word,"<span style=""background-color:#" & ArrNewClist(ArrListi mod Ubound(ArrNewCList)) & "; font-weight:bold"">" & word & "</span>")
ArrListi = ArrListi + 1
End If
Next
fm_hilite = alltext
End Function
__________________
FERRUH.MAVİTUNA - İnanmıyorum, yeni site! |
|
|
|
Zoque'a hoşgeldiniz!