Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - ASP Replace function in search results
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

ASP Replace function in search results

 Post Reply Post Reply
Author
webbasterd View Drop Down
Groupie
Groupie


Joined: 21 November 2002
Location: Netherlands
Status: Offline
Points: 37
Post Options Post Options   Thanks (0) Thanks(0)   Quote webbasterd Quote  Post ReplyReply Direct Link To This Post Topic: ASP Replace function in search results
    Posted: 16 February 2005 at 3:50pm
Hi all,
 
I've just made my first search engine that search trough an MySQL database on a corporate portal. Everyting works fine except for one thing. When I retrieve a database record based on a search word, I use the REPLACE function to make the search word in the recordset

Highlighted. I used the source from WWF as an example.

The problem is that when I use upercase words as a search words, the lowercase words in the dataset are replaced by upercase words. e.g. "HeLo WoRlD" as the search criteria will replace "Hello world" in my search results by "HeLo WoRlD".

The same problem occurs in the search function of WWF 7.9. (I've noticed that this problem is solved in WWF 8.0 A) Does anyone knows how I can solve this for my Search engine? (i've search the forum but didn't find a workarround)
 
Thanks in advance.
 
--
Alexander


Edited by webbasterd - 16 February 2005 at 5:04pm
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 16 February 2005 at 9:43pm
Below is the code i use for an application, it may be possible to do simpler but works well for me. I use the code in .net so you cannot use the searchoption enum like that, you can actually take it out if you want, but basically I want to highlight all words if I do an OR search, but only a specific sentence for for a phrase search (even if some of the words exist somewhere else)

Public Enum SearchOption

_OR

_PHRASE

End Enum

Private Function Highlight(ByVal strText As String, ByVal strFind As String) As String

Dim nPos

Dim nLen

Dim nLenAll

Dim strBefore, strAfter As String

strBefore = "<span style='background:yellow'>"

strAfter = "</span>"

nLen = Len(strFind)

nLenAll = nLen + Len(strBefore) + Len(strAfter) + 1

Highlight = strText

If nLen > 0 And Len(Highlight) > 0 Then

nPos = InStr(1, Highlight, strFind, 1)

Do While nPos > 0

Highlight = Left(Highlight, nPos - 1) & _

strBefore & Mid(Highlight, nPos, nLen) & strAfter & _

Mid(Highlight, nPos + nLen)

nPos = InStr(nPos + nLenAll, Highlight, strFind, 1)

Loop

End If

End Function

Public Function DOHighLight(ByVal strText As String, ByVal strFind As String, ByVal Opt As SearchOption) As String

Select Case Opt

Case SearchOption._OR

Dim sterm As Object = Split(strFind, " ")

Dim mterm As Object = UBound(sterm)

Dim counter As Integer

For counter = 0 To mterm

strText = Highlight(strText, sterm(counter))

Next

Case SearchOption._PHRASE

strText = Highlight(strText, strFind)

End Select

Return strText

End Function



Edited by michael - 16 February 2005 at 9:46pm
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 16 February 2005 at 9:47pm
forgot to mention, strText is the whole text and strFind is the keyword(s) you want to replace.
Back to Top
webbasterd View Drop Down
Groupie
Groupie


Joined: 21 November 2002
Location: Netherlands
Status: Offline
Points: 37
Post Options Post Options   Thanks (0) Thanks(0)   Quote webbasterd Quote  Post ReplyReply Direct Link To This Post Posted: 20 February 2005 at 5:26pm
Thanks... I will try this out
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.