Results 1 to 4 of 4

Thread: highlighting an array of keywords

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    highlighting an array of keywords

    Code:
    <%
    strFind = Keyword '"jeSus christ joseph begat"
    strText = rs("text_data")'"And Jacob begat Joseph the husband of Mary, of whom was born Jesus, who is called Christ."
    response.write Highlight(strText, strFind)
    %>
    <SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
    Function Highlight(strText, strFind)
     '// Check that at least one search term has been submitted
     If Len(strFind) < 1 Then
      '// no search term entered. Exit the function
      Highlight = "No search term entered"
      Exit Function
     End If
     
     '// define the colours to be used to highlight search results
     Dim strColors : strColors = "#FF0000" ',#008000,#0000FF
     '// and split them into an array
     Dim arrColors : arrColors = Split(strColors,",")
     
     '// split the search terms into an array
     Dim arrFind : arrFind = Split(strFind," ")
     
     '// Initialize the regular expression object to perfom the search
     Dim oRegExp, oMatches, sMatch
     Set oRegExp = New RegExp
     oRegExp.Global = True '// returns all matches to the search term
     oRegExp.IgnoreCase = True '// Case insensitive
     
     '// loop through the array of search terms to find matches
     Dim i, strHighlight
     For i = 0 to UBound(arrFind)
      oRegExp.Pattern = arrFind(i) '// sets the search pattern string
      Set oMatches = oRegExp.Execute(strText) '// performs the search 
      for each match in oMatches
      '// build the code to be used to highlight results
      strHighlight = "<font color='red'><b>" & match.value & "</b></font>" '" & arrColors(i) & "
      next
      '// then replace matches from the search with the above code
      strText = oRegExp.Replace(strText, strHighlight)
     Next
     '// release the RegExp object
     Set oRegExp = Nothing
     '// and return the result
     Highlight = strText
    End Function
    </SCRIPT>
    SO I made the changes but whenever I insert the Keyword and rs("text_data")

    I get this error:
    Microsoft VBScript runtime error '800a01c2'

    Wrong number of arguments or invalid property assignment: 'Highlight'

    /wheelofgod/highlightingz.asp, line 4
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    Addicted Member
    Join Date
    Jul 2004
    Location
    Mumbai
    Posts
    236

    Re: highlighting an array of keywords

    everything is working fine in the code. the only thing i could not find is what is the value of rs("text_data"). i think the problem will be there. so try printing the rs("text_data").

    Code:
    strFind = Keyword '"jeSus christ joseph begat"
    Response.write(rs("text_data"))
    strText = rs("text_data")'"And Jacob begat Joseph the husband of Mary, of whom was born Jesus, who is called Christ."
    response.write Highlight(strText, strFind)
    Last edited by kishore.kr; Jul 21st, 2005 at 11:32 PM.
    --Kishore...

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    Re: highlighting an array of keywords

    Ok.
    I was trying this:highlightingz.asp
    Here is what was interfering:<%'<!--#include file="highlight3.asp"-->%>
    Code:
    <%Dim strText, strFind%>
    
    <%If Keyword <> "" Then%>
    <!--#include file="highlightingz.asp"-->
    <%'<!--#include file="lafinboy.asp"-->%>
    <%'<!--#include file="highlight1.asp"-->%>
    <%'<!--#include file="lafinboyaltered.asp"-->%>
    <%'<!--#include file="highlight.asp"-->%>
    
    <%End If%>
    <%'If Keywordb <> "" Then%>
    <%'<!--#include file="highlight2a.asp"-->%>
    <%'End If%>
    <%If Keywordc <> "" OR Keywordd <> "" OR Keyworde <> "" OR Keywordf <> "" or spoke <> "" or number <> "" or recordType <> "" Then%>
    <%'<!--#include file="highlight3.asp"-->%>
    <%End If%>
    When I blocked it worked. But I still don't understand why that was heppenning?
    Compare bible texts (and other tools):
    TheWheelofGod

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    Re: highlighting an array of keywords

    Here's what I'm aiming at
    WHat I have are 6 textboxes:
    Keyword
    Keywordb
    Keywordc
    Keywordd
    Keyworde
    Keywordf

    Each textbox is meant for a special type of search:
    Keyword is for an array of words like Lord AND Jesus AND Christ

    Keywordb is also an array of words but Lord OR Jesus OR Christ

    Keywordc - Keywordf are specific phrases

    I find that if one fails to accomplish my search another type of search will help.

    For Keyword I used:
    <%
    strFind = Keyword '"jeSus christ joseph begat"
    strText = rs("text_data")'"And Jacob begat Joseph the husband of Mary, of whom was born Jesus, who is called Christ."
    response.write Highlight(strText, strFind)
    %>
    <SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
    Function Highlight(strText, strFind)
    '// Check that at least one search term has been submitted
    If Len(strFind) < 1 Then
    '// no search term entered. Exit the function
    Highlight = "No search term entered"
    Exit Function
    End If

    '// define the colours to be used to highlight search results
    Dim strColors : strColors = "#FF0000" ',#008000,#0000FF
    '// and split them into an array
    Dim arrColors : arrColors = Split(strColors,",")

    '// split the search terms into an array
    Dim arrFind : arrFind = Split(strFind," ")

    '// Initialize the regular expression object to perfom the search
    Dim oRegExp, oMatches, sMatch
    Set oRegExp = New RegExp
    oRegExp.Global = True '// returns all matches to the search term
    oRegExp.IgnoreCase = True '// Case insensitive

    '// loop through the array of search terms to find matches
    Dim i, strHighlight
    For i = 0 to UBound(arrFind)
    oRegExp.Pattern = arrFind(i) '// sets the search pattern string
    Set oMatches = oRegExp.Execute(strText) '// performs the search
    for each match in oMatches
    '// build the code to be used to highlight results
    strHighlight = "<font color='red'><b>" & match.value & "</b></font>" '" & arrColors(i) & "
    next
    '// then replace matches from the search with the above code
    strText = oRegExp.Replace(strText, strHighlight)
    Next
    '// release the RegExp object
    Set oRegExp = Nothing
    '// and return the result
    Highlight = strText
    End Function
    </SCRIPT>
    But I don't know how to make the adjustment to include the rest of the keywords. I find that even some things within this code are extra.
    Compare bible texts (and other tools):
    TheWheelofGod

Posting Permissions

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



Click Here to Expand Forum to Full Width