SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2005
    0 Post(s)
    0 Thread(s)

    Search result text highlighting issue

    i am developing a search engine(ASP with SQL SERVER) for my project . My objective is to search for a data and it should display the result and highlighting the search text in different color. But when i use the search text with more than one word, the result is highlighting only the last word of the search text.

    Example - If i search for "Opal" , the search result highlighting all the words with "opal", But when is search "Opal Service", the search result is highlighting only the "service".

    Here the "Opal" and "service" are different identities, i will search these two words with AND condition .

    Iam using the following function to highlight the text.

    Function Definition
    Function Highlight(strText, strFind, strBefore, strAfter)
    ' my_output = strBefore& strFind & strAfter
    ' Highlight = replace(, strFind, my_output)
    Dim nPos
    Dim nLen
    Dim nLenAll

    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)
    End If
    End Function
    Function Call
    text= Highlight(objRecordset.Fields("Branche_3").value,words(j), "<font color='#FF6600'>", "</font>")

  2. #2
    SitePoint Guru asterix's Avatar
    Join Date
    Jun 2003
    0 Post(s)
    0 Thread(s)
    hehe you don't understand that code do you? the answer is staring you in the face:
     Function Highlight(strText, strFind, strBefore, strAfter) 
     dim strReplace
      strReplace = strBefore& strFind & strAfter 
      Highlight = replace(strText, strFind, strReplace )
    End Function

  3. #3
    SitePoint Zealot jrickards's Avatar
    Join Date
    May 2003
    0 Post(s)
    0 Thread(s)
    I have used the replace function for highlighting purposes but it seems that if the search word and word in text are of different cases, such as "ascii" and "ASCII", replace doesn't find it. I tried the compare switch (1=text) but it doesn't work.

    Any ideas?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts