I'm looking to find or create an ASP script that will take a string, examine
it for a search term, and if it finds the search term in the string, return
the highlighted search term along with the words that surround it. In other
words, I want the search term highlighted and shown in an excerpt of the
context in which it appears.
Any suggestions or pointers? This behavior is most often seen as part of a
search engine. In my case, I want to use it as part of a content "scanner"
that utilizes a screen scraping component. 4 2588
The hard part of this problem isn't highlighting the search term, which has
been done a million times before, but rather pulling out, say, 300
characters that precede the search term and 300 characters that follow it,
so that I can show the context that a term appeared in.
"Mike" <so***@sorry.com> wrote in message
news:bh**********@geraldo.cc.utexas.edu... "Ken Fine" <ke*****@u.washington.edu> wrote in message news:bh***********@nntp6.u.washington.edu... I'm looking to find or create an ASP script that will take a string, examine it for a search term, and if it finds the search term in the string, return the highlighted search term along with the words that surround it. In other words, I want the search term highlighted and shown in an excerpt of the context in which it appears.
Any suggestions or pointers? This behavior is most often seen as part of
a search engine. In my case, I want to use it as part of a content
"scanner" that utilizes a screen scraping component.
Sounds like a job for replace...
replace(string, search-string, "<span style=""background-color:
#FF0000"">" & search-string & "</span>")
I haven't tried it, but it seems logical. The CSS might be flaky above,
you might want to verify that background-color is a valid property. :)
-- Mike
This will get you started:
Dim Pos
Dim Extract
Const BufferLen = 300
Pos = InStr (1, SourceString, SearchTerm, vbTextCompare)
If (Pos<>0) Then
' Search term found.
Extract = Mid(SourceString, Pos - BufferLen, ((2*BufferLen) +
Len(SearchTerm)))
End If
It'll need some tweaking and I haven't tested it. Make sure you don't read
past either end of SourceString. I'd be a bit worried about the efficiency
of this if you're doing it multiple times on a page - you'll have to
optimise it by storing the Pos of the last hit and starting from that
position for your next iteration. Perhpas something like this (untested):
Pos = InStr (1, SourceString, SearchTerm, vbTextCompare)
Do While Pos <> 0
' Get the extract.
Extract = Mid(SourceString, Pos - BufferLen, ((2*BufferLen) +
Len(SearchTerm)))
' Next Pos.
Pos = InStr (Pos, SourceString, SearchTerm, vbTextCompare)
Loop
Try that.
Alan
"Ken Fine" <ke*****@u.washington.edu> wrote in message
news:bh***********@nntp6.u.washington.edu... The hard part of this problem isn't highlighting the search term, which
has been done a million times before, but rather pulling out, say, 300 characters that precede the search term and 300 characters that follow it, so that I can show the context that a term appeared in.
"Mike" <so***@sorry.com> wrote in message news:bh**********@geraldo.cc.utexas.edu... "Ken Fine" <ke*****@u.washington.edu> wrote in message news:bh***********@nntp6.u.washington.edu... I'm looking to find or create an ASP script that will take a string, examine it for a search term, and if it finds the search term in the string, return the highlighted search term along with the words that surround it. In other words, I want the search term highlighted and shown in an excerpt of
the context in which it appears.
Any suggestions or pointers? This behavior is most often seen as part
of a search engine. In my case, I want to use it as part of a content "scanner" that utilizes a screen scraping component.
Sounds like a job for replace...
replace(string, search-string, "<span style=""background-color: #FF0000"">" & search-string & "</span>")
I haven't tried it, but it seems logical. The CSS might be flaky above, you might want to verify that background-color is a valid property. :)
-- Mike
Yep sorry about that. Try this line for the second search (notice the 'Pos +
1'):
Pos = InStr (Pos + 1, SourceString, SearchTerm, vbTextCompare)
See how you go.
Alan
"Ken Fine" <ke*****@u.washington.edu> wrote in message
news:bh***********@nntp6.u.washington.edu... Alan, thanks, this is great. Function #1 works just swell, with no mishaps at all. I combined it with a "clean out the HTML" function and a
"highlight search term" function to make a genuinely useful scanner.
The only part I don't have working is a mechanism by which it will loop through the remaining content. Function #2 appears to send the server into an infinite loop and I can't figure out why. It would be really great if
I could list out all of the "hits" for a given page. Do you have any ideas
for what I should be looking at?
"Alan" <SP******************@inspire.net.nz> wrote in message news:en*************@TK2MSFTNGP12.phx.gbl... This will get you started:
Dim Pos Dim Extract Const BufferLen = 300
Pos = InStr (1, SourceString, SearchTerm, vbTextCompare)
If (Pos<>0) Then
' Search term found. Extract = Mid(SourceString, Pos - BufferLen, ((2*BufferLen) + Len(SearchTerm)))
End If
It'll need some tweaking and I haven't tested it. Make sure you don't
read past either end of SourceString. I'd be a bit worried about the
efficiency of this if you're doing it multiple times on a page - you'll have to optimise it by storing the Pos of the last hit and starting from that position for your next iteration. Perhpas something like this
(untested): Pos = InStr (1, SourceString, SearchTerm, vbTextCompare) Do While Pos <> 0
' Get the extract. Extract = Mid(SourceString, Pos - BufferLen, ((2*BufferLen) + Len(SearchTerm))) ' Next Pos. Pos = InStr (Pos, SourceString, SearchTerm, vbTextCompare)
Loop
Try that.
Alan
"Ken Fine" <ke*****@u.washington.edu> wrote in message news:bh***********@nntp6.u.washington.edu... The hard part of this problem isn't highlighting the search term,
which has been done a million times before, but rather pulling out, say, 300 characters that precede the search term and 300 characters that follow it, so that I can show the context that a term appeared in.
"Mike" <so***@sorry.com> wrote in message news:bh**********@geraldo.cc.utexas.edu... > "Ken Fine" <ke*****@u.washington.edu> wrote in message > news:bh***********@nntp6.u.washington.edu... > > I'm looking to find or create an ASP script that will take a
string, > examine > > it for a search term, and if it finds the search term in the
string, > return > > the highlighted search term along with the words that surround it.
In > other > > words, I want the search term highlighted and shown in an excerpt
of the > > context in which it appears. > > > > Any suggestions or pointers? This behavior is most often seen as part of a > > search engine. In my case, I want to use it as part of a content "scanner" > > that utilizes a screen scraping component. > > Sounds like a job for replace... > > replace(string, search-string, "<span style=""background-color: #FF0000"">" > & search-string & "</span>") > > I haven't tried it, but it seems logical. The CSS might be flaky above, you > might want to verify that background-color is a valid property. :) > > -- > Mike > >
Thanks again, Alan, that did the trick! This is great. The finished code
looks like this:
<%Dim Pos
Dim Extract
Const BufferLen = 300
Searchterm=TearSearchTerm
SourceString=strRetVal5
Pos = InStr (1, SourceString, SearchTerm, vbTextCompare)
Do While Pos <> 0
' Get the extract.
Extract = Mid(SourceString, Pos - BufferLen, ((2*BufferLen) +
Len(SearchTerm)))
Response.Write "<p><font face=arial size=2><b>Location of search term
"&"<font color=red>""&Searchterm&""</font> at <a
href="&TearURL&">"&TearURL&"</a>"&":</b> char #"& Pos & "</font><br>"
FinishString=StripHTML(Extract)
Response.Write "<b>Excerpt:</b><br><font face=arial size=2> ..."&
doHighlight(FinishString, Searchterm,"hi")&" ...</font>"
' Next Pos.
Pos = InStr (Pos + 1, SourceString, SearchTerm, vbTextCompare)
Loop
%>
Interested readers can sub out the response.write business, and sub in their
own "highlight search word" function that drives the "doHighlight" widget.
(If you want this function, it's available off of planet-source-code.com; I
wrote in an extra setting to the function -- "hi" -- that highlights search
terms with a yellow background.)
StripHTML is a function to remove HTML/code from a string, you can find any
of a number of free functions that will do this for you.
A big gold star to Alan for his timely help on a not-trivial problem.
-KF
"Alan" <SP******************@inspire.net.nz> wrote in message
news:uB**************@tk2msftngp13.phx.gbl... Yep sorry about that. Try this line for the second search (notice the 'Pos
+ 1'):
Pos = InStr (Pos + 1, SourceString, SearchTerm, vbTextCompare)
See how you go.
Alan
"Ken Fine" <ke*****@u.washington.edu> wrote in message news:bh***********@nntp6.u.washington.edu... Alan, thanks, this is great. Function #1 works just swell, with no
mishaps at all. I combined it with a "clean out the HTML" function and a "highlight search term" function to make a genuinely useful scanner.
The only part I don't have working is a mechanism by which it will loop through the remaining content. Function #2 appears to send the server
into an infinite loop and I can't figure out why. It would be really great
if I could list out all of the "hits" for a given page. Do you have any ideas for what I should be looking at?
"Alan" <SP******************@inspire.net.nz> wrote in message news:en*************@TK2MSFTNGP12.phx.gbl... This will get you started:
Dim Pos Dim Extract Const BufferLen = 300
Pos = InStr (1, SourceString, SearchTerm, vbTextCompare)
If (Pos<>0) Then
' Search term found. Extract = Mid(SourceString, Pos - BufferLen, ((2*BufferLen) + Len(SearchTerm)))
End If
It'll need some tweaking and I haven't tested it. Make sure you don't read past either end of SourceString. I'd be a bit worried about the efficiency of this if you're doing it multiple times on a page - you'll have to optimise it by storing the Pos of the last hit and starting from that position for your next iteration. Perhpas something like this (untested): Pos = InStr (1, SourceString, SearchTerm, vbTextCompare) Do While Pos <> 0
' Get the extract. Extract = Mid(SourceString, Pos - BufferLen, ((2*BufferLen) + Len(SearchTerm))) ' Next Pos. Pos = InStr (Pos, SourceString, SearchTerm, vbTextCompare)
Loop
Try that.
Alan
"Ken Fine" <ke*****@u.washington.edu> wrote in message news:bh***********@nntp6.u.washington.edu... > The hard part of this problem isn't highlighting the search term, which has > been done a million times before, but rather pulling out, say, 300 > characters that precede the search term and 300 characters that
follow it, > so that I can show the context that a term appeared in. > > "Mike" <so***@sorry.com> wrote in message > news:bh**********@geraldo.cc.utexas.edu... > > "Ken Fine" <ke*****@u.washington.edu> wrote in message > > news:bh***********@nntp6.u.washington.edu... > > > I'm looking to find or create an ASP script that will take a string, > > examine > > > it for a search term, and if it finds the search term in the string, > > return > > > the highlighted search term along with the words that surround
it. In > > other > > > words, I want the search term highlighted and shown in an
excerpt of the > > > context in which it appears. > > > > > > Any suggestions or pointers? This behavior is most often seen as
part of > a > > > search engine. In my case, I want to use it as part of a content > "scanner" > > > that utilizes a screen scraping component. > > > > Sounds like a job for replace... > > > > replace(string, search-string, "<span style=""background-color: > #FF0000"">" > > & search-string & "</span>") > > > > I haven't tried it, but it seems logical. The CSS might be flaky above, > you > > might want to verify that background-color is a valid property. :) > > > > -- > > Mike > > > > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: flam |
last post by:
Hello,
I am having a hard time spliting a string into an array for use in a
search. Here is the situation. The user will input a search string.
Normally I can just split the string by "split...
|
by: Dave H |
last post by:
Hello,
I have a query regarding definition lists. Is it good practice
semantically to use the dt and dd elements to mark up questions and
answers in a frequently asked questions list, or FAQ?
...
|
by: Durgesh Sharma |
last post by:
Hi All,
Pleas help me .I am a starter as far as C Language is concerned .
How can i Right Trim all the white spaces of a very long (2000 chars)
Charecter string ( from the Right Side ) ? or how...
|
by: tshad |
last post by:
Can you do a search for more that one string in another string?
Something like:
someString.IndexOf("something1","something2","something3",0)
or would you have to do something like:
if...
|
by: Dan Schumm |
last post by:
I'm relatively new to regular expressions and was looking for some help on a
problem that I need to solve. Basically, given an HTML string, I need to
highlight certain words within the text of the...
|
by: robert maas, see http://tinyurl.com/uh3t |
last post by:
I'm working on examples of programming in several languages, all
(except PHP) running under CGI so that I can show both the source
files and the actually running of the examples online. The first...
|
by: Ron |
last post by:
I am getting an error Option strict on disallows implicit conversion
from string to long
I get it for this code
iStartPosition = InStr(iStartPosition + 1, RichTextBox1.Text, "A" Or
"a"
the...
|
by: |
last post by:
I am interested in scanning web pages for content of interest, and then
auto-classifying that content. I have tables of metadata that I can use for
the classification, e.g. : "John P. Jones" "Jane...
|
by: Bart Kastermans |
last post by:
Summary: can't verify big O claim, how to properly time this?
On Jun 15, 2:34 pm, "Terry Reedy" <tjre...@udel.eduwrote:
Thanks for the idea. I would expect the separation to lead to
somewhat...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
|
by: jack2019x |
last post by:
hello, Is there code or static lib for hook swapchain present?
I wanna hook dxgi swapchain present for dx11 and dx9.
| |