473,696 Members | 2,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The Ultimate HTML Search Script. But.......!

A year or two back I needed a search script to scan thru HTML files
on a client site. Usual sorta thing. A quick search turned up a
neat script that provided great search results. It was fast,
returned the hyperlinked page title, filename, and the body txt (30
preceding and following words) in context with the search word
highlighted. Excellent.!

See it working at: http://www.ipt.co.za
Just search for "firearm"

I now need to use it on a different site but I've run into two
limitations which made it unsuitable. It will only search the root
folder of a domain and won't cascade the search down through sub-
folders. Hmmmm. Pity. Checked the code but couldn't modify it
successfully. Aah well, look elsewhere.....

After hours and hours of scouring through the script sites I began to
realise what a lucky find that original script was. Almost
everything new that seemed promising either had major limitations,
presented poor results or just would not work properly. And, most
importantly, none of them offered that *excellent* feature where the
search term was displayed embedded in the context.

I now believe that this is a great script that needs two
modifications:

1. The ability to be pointed to a sub-folder of a domain as the
starting point for the search. But, as a compromise, this could also
be achieved as the folder in which the script itself is lying.

2. The ability for the search to cascade on through sub-folders
lying below the folder in which the search is initiated.

It would also be great if the original casing for the page title and
context could be preserved but that really isn't a critical issue.

Maybe one could even specify the file extensions for searching to
speed things up. Suggestions would be greatfully received.!

Please can somebody out there help with some ideas as to where this
script can be modified to provide these functions. I'm sure this
would an excellent resource for the ASP community and it certainly
fits my requirements.

Here's hoping ...... code follows below.!

TIA

.les.
Durban
South Africa
------------< clip: code to launch results.asp starts >------------

<FORM NAME="frmSearch " METHOD="GET" ACTION="results .asp">
<table border=1 width=175 bordercolor="#3 36633" cellspacing=0>< tr><td
align=center background="gre en.gif" bgcolor="#00990 0"><div
align=center>
<font color="#FFFFFF" ><b> search IPT
</b></font></div></td></tr><tr><td align=center ><div
align=center><b r><img src="clear.gif" width=1 height=4>
<INPUT NAME="boolean" TYPE="hidden" VALUE="AND">
<INPUT NAME="selSearch Where" TYPE="hidden" value="">
<INPUT NAME="terms" TYPE="TEXT" VALUE=" Search IPT Here" SIZE="14"
onFocus=clearfi eld() TITLE="Enter the keyword to search on here!">
<INPUT TYPE="SUBMIT" VALUE="find"></div><img src="clear.gif" width=1
height=4>
</td></tr></table>
</FORM>

------------< /clip: code to launch results.asp ends >------------

------------< file: results.asp starts >------------

<%@ Language=VBScri pt %>
<% Option Explicit %>
<html>
<head>
<TITLE>Search IPT</TITLE>
<SCRIPT LANGUAGE="javas cript" src="jAvAsCrIpT s.js"></SCRIPT>
<link rel="stylesheet " href="ipt.css">
<title>http://www.ipt.co.za</title>
</head>
<body background="bg. jpg" bgcolor="#FFFFF F" link="#006600"
alink="#006600" vlink="#006600" marginwidth=0 marginheight=0
topmargin=0 leftmargin=0 bottommargin=0 rightmargin=0>

<%
Dim myCounter
If Request.QuerySt ring("myCounter ") <> "" Then
myCounter = Request.QuerySt ring("myCounter ")
Else
myCounter = 1
End If
%>
<%
Function FormatURL(strPa th)
'Cut off everything before wwwroot and replace all \
with /
Dim iPos
iPos = InStr(1,strPath ,"wwwroot",1 )
Dim str
str = Mid(strPath,iPo s+7,Len(strPath ))
FormatURL = Replace(str,"\" ,"/")
End Function

Function RemoveHTML( strDesc )
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = "<[^>]*>"
RegEx.Global = True
strDesc = Replace(LCase(s trDesc), "<br>", chr(10))
RemoveHTML = RegEx.Replace(s trDesc, "")
End Function

Function GetFiles(objFol der, aLookFor, strLF,
bolLFFound,bolA nd, iCount)
If Left(objFolder. Name,1) = "_" then exit function
Const iListPerPage = 9

if iCount > iListPerPage then Exit Function

'Now, loop through each file
Dim objFile, objTextStream, objFSO, strContents,
iUBound, iLoop, bolValid
Dim strTitle, iPos, strDesc
iUBound = UBound(aLookFor )

For Each objFile in objFolder.Files
on error resume next
'What file to search, if u change the .htm
remember to cahange 4 to correpond
If (Right(objFile. Name,4)) = ".htm" then
'If Ucase(Right(obj File.Name,6)) = ".SHTML" or
Ucase(right(obj File.Name,4)) = ".ASP" then

If bolLFFound then
if objFile.Size > 0 then
Set objFSO =
Server.CreateOb ject("Scripting .FileSystemObje ct")
Set objTextStream =
objFSO.OpenText File(objFile.Pa th,1)
strContents =
objTextStream.R eadAll
strContents =
LCase(strConten ts)

'get the page title
then remove all HTML tags
iPos =
InStr(1,strCont ents,"<title>")
Dim iWhere, iLength,
DescPosition, DescLast
If iPos = 0
then

strTitle = "Untitled (" & objFile.Name & ")"
Else

strTitle =
Mid(strContents ,iPos+7,InStr(i Pos,strContents ,"</title>")-iPos-7)
End If
strContents=Rem oveHTML( strContents )
objTextStream.C lose
Set objFSO = Nothing

if bolAnd then
bolValid = True else bolValid = False
For iLoop = 0 to
iUBound
If
InStr(1,strCont ents,aLookFor(i Loop),1) then
if Not
bolAnd then bolValid = True
Else
If
bolAnd then bolValid = False
End If
Next

If bolValid then

iWhere =
InStr(strConten ts,strKeywords)
iLength = 200
if iWhere > 0
then
if iWhere <
200 then iLength = iWhere-1

strDesc = mid(strContents ,iWhere-iLength,iLength ) &
mid(strContents ,iWhere,200)

'strDesc = mid(strContents ,iWhere-iLength,iLength ) &
mid(strContents ,iWhere,200+len (strKeywords))

strDesc=Replace (strDesc, "<", "&lt;")

strDesc=Replace (strDesc, ">", "&gt;")

strDesc=Trim(st rDesc)

strDesc = Mid( strDesc, InStr(strDesc," ") + 1 )

strDesc = Left( strDesc, InStrRev(strDes c," ") - 1 )

strDesc=Replace (strDesc, strKeywords, "<font
class=highlight ><b>"&strKeywor ds&"</b></font>")
end if

Response.Write
"<font size=-1><b>" & myCounter & ". <a href=""" & objFile.Name &
""">" & _

strTitle & "</b></a><font size=1>&nbsp; (" & objFile.Name &
")</font><br>" & vbCrLf
Response.Write
"<div class=results>< font size=-1>" & strDesc
Response.Write
"</font></div><br>" & vbCrLf
strDesc = ""
strTitle = ""

myCounter =
myCounter + 1
iCount =
iCount + 1
End if
If iCount >
iListPerPage then
strLF =
FormatURL(objFi le.Path)
exit function
End If
End If
Elseif FormatURL(objFi le.Path) = strLF
then
bolLFFound = True
End If
End if
Next

'Dim objSubFolder
'For Each objSubFolder in objFolder.SubFo lders
' GetFiles
objSubFolder,aL ookFor,strLF,bo lLFFound,bolAnd ,iCount
'Next
End Function

'Search the site get keywords and take the first word!
Dim strKeywords
strKeywords = Request("terms" )
strKeywords = LCase(strKeywor ds)
strKeywords = trim(strKeyword s)
do while InStr(1,strKeyw ords," ")
If InStr(1,strKeyw ords," ") Then
strKeywords = Left( strKeywords, InStrRev(strKey words," ") - 1
)
End If
loop

'Split the terms on spaces
Dim termsArray
termsArray = split(strKeywor ds," ")

'Set the boolean search option
Dim bolAnd
If Request("boolea n") = "AND" then bolAnd = True else bolAnd =
False

Dim section
section = Request("selSea rchWhere")

'Get the dirs to search
If section = "ipt" then
section = Server.MapPath( "/")
else
section = Server.MapPath( "/")
end if

'What page are we on?
Dim strLastFile
strLastFile=Req uest("lf")

Dim objFSO, objFolder
Set objFSO = Server.CreateOb ject("Scripting .FileSystemObje ct")

Set objFolder = objFSO.GetFolde r(section)
Set objFSO = Nothing
%>

<blockquote>
<table width="550" ><tr><td>
<br>
<center><font size=+2><b>
IPT Search Results For "<% =strKeywords %>"
</b></font><br><form name="frmSearch " method="GET"
action="results .asp">
New Search:
<input name="boolean" type="hidden" size="20" value="AND">
<input name="selSearch Where" type="hidden" size="20" value="">
<input name="terms" type="text" size="20" title="Enter the keyword to
search on here!">
<input name="submit" type="button" value="Search!" >
</form>
</center>
<p>
<center>
<a href="index.htm " >home</a> |
<a href="schools.h tm" >schools</a> |
<a href="police.ht m" >police</a> |
<a href="Governmen t.htm" >government</a> |
<a href="hiv_aids. htm" >HIV/Aids</a> |
<a href="public.ht m" >publications </a> |
<a href="staff.htm " >staff</a> |
<a href="services. htm" >services</a> |
<a href="links.htm " >links</a> |
<a href="contact.h tm" >contact</a>
</center>
<hr><p>
Below are the results of your search in no particular order...
<p>
<p>

<%
Dim iResults
iResults = 0

'Now, recurse the directories
If Len(strLastFile ) = 0 then
GetFiles
objFolder,terms Array,strLastFi le,True,bolAnd, iResults
Else
GetFiles
objFolder,terms Array,strLastFi le,False,bolAnd ,iResults
End If

Set objFolder = Nothing

If iResults = 10 then
'Show next page link
%>
<center>
<p><hr><p><b>
<a
href="results.a sp?terms=<%=Ser ver.URLEncode(s trKeywords)%>&b oolean=<%=Reque st("boolean")%> &selSearchWhere =<%=Request("se lSearchWhere")% >&lf=<%=Server. URLEncode(strLa stFile)%>&myCou nter=<%=myCount er%>">
Next 10 results...</b>
</a></center>
<p>
<% Elseif iResults = 0 then %>
<b>No results found!</b><br>

<% Elseif iResults < 10 then %>

<center>
<p><hr><p>
<b><form name="frmSearch " method="GET" action="results .asp">
New Search:
<input name="boolean" type="hidden" size="20" value="AND">
<input name="selSearch Where" type="hidden" size="20" value="">
<input name="terms" type="text" size="20" title="Enter the keyword to
search on here!">
<input name="submit" type="button" value="Search!" >
</form>
</center>
<% End IF %>
<hr><p>
<center>
<a href="index.htm " >home</a> |
<a href="schools.h tm" >schools</a> |
<a href="police.ht m" >police</a> |
<a href="Governmen t.htm" >government</a> |
<a href="hiv_aids. htm" >HIV/Aids</a> |
<a href="public.ht m" >publications </a> |
<a href="staff.htm " >staff</a> |
<a href="services. htm" >services</a> |
<a href="links.htm " >links</a> |
<a href="contact.h tm" >contact</a>
</center>
<div align="right">
<p><font size=1>All material © Copyright Independent Projects Trust
1990-2002</font></p>
</div>
</tr></td></table>
</blockquote>

</body>
</html>

------------< /file: results.asp ends >------------

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Les Juby
Webpro Internet / Prosoft Microsystems
Durban, KwaZulu-Natal, South Africa
we****@webpro.c o.za
Tel: +27 (31) 563-8344 Fax: +27 (31) 563-1684
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o
Les Juby le*****@anti-spam.iafrica.co m
Webpro Internet - - - Prosoft Microsystems
Durban, KwaZulu-Natal, South Africa
P.O.Box 35243, Northway 4065, South Africa
Tel: +27 31 563-8344 Fax: +27 31 564-4928
o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o
(you *do* know to take "anti-spam" out the address....?
Jul 19 '05 #1
1 8722
OK - Not one response from you lot.! Sigh.! But then a post with
over 400 lines is a bit daunting. Can't see myself ever responding to
something like that.

So there was not option but to roll up ones slleves and get to it.
And, surprisingly, it only took a couple of hours and we'd solved all
the glitches.

This is a GREAT search text, beats anything I've seen in the script
archives at about eight ASP sites that we cruised thru. And we tried
out five of the best scripts.

If anyone would like a copy then mail me at we****@webpro.c o.za and
I'll be happy to send you the (improved) ASP file. The only proviso
is that if you have any ideas on how to improve it, then let me know.
I'm even prepared to put up a discussion board for it if there's
enough interest.!

.les.

On Fri, 18 Jul 2003 06:38:25 GMT, we****@webpro.c o.za (Les Juby)
wrote:
A year or two back I needed a search script to scan thru HTML files
on a client site. Usual sorta thing. A quick search turned up a
neat script that provided great search results. It was fast,
returned the hyperlinked page title, filename, and the body txt (30
preceding and following words) in context with the search word
highlighted. Excellent.!

See it working at: http://www.ipt.co.za
Just search for "firearm"

I now need to use it on a different site but I've run into two
limitations which made it unsuitable. It will only search the root
folder of a domain and won't cascade the search down through sub-
folders. Hmmmm. Pity. Checked the code but couldn't modify it
successfully . Aah well, look elsewhere.....

After hours and hours of scouring through the script sites I began to
realise what a lucky find that original script was. Almost
everything new that seemed promising either had major limitations,
presented poor results or just would not work properly. And, most
importantly, none of them offered that *excellent* feature where the
search term was displayed embedded in the context.

I now believe that this is a great script that needs two
modification s:

1. The ability to be pointed to a sub-folder of a domain as the
starting point for the search. But, as a compromise, this could also
be achieved as the folder in which the script itself is lying.
(fixed)
2. The ability for the search to cascade on through sub-folders
lying below the folder in which the search is initiated.
(fixed)
It would also be great if the original casing for the page title and
context could be preserved but that really isn't a critical issue.
(on the Wish List)
Maybe one could even specify the file extensions for searching to
speed things up. Suggestions would be greatfully received.!
(fixed)
Please can somebody out there help with some ideas as to where this
script can be modified to provide these functions. I'm sure this
would an excellent resource for the ASP community and it certainly
fits my requirements.

Here's hoping ...... code follows below.!

TIA

.les.
Durban
South Africa
------------< clip: code to launch results.asp starts >------------

Lotsa blah, blah code all snipped out............ ............

------------< /file: results.asp ends >------------

o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o
Les Juby le*****@anti-spam.iafrica.co m
Webpro Internet - - - Prosoft Microsystems
Durban, KwaZulu-Natal, South Africa
P.O.Box 35243, Northway 4065, South Africa
Tel: +27 31 563-8344 Fax: +27 31 564-4928
o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o
(you *do* know to take "anti-spam" out the address....?
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

50
5493
by: Edward K. Ream | last post by:
I would like to say a few (actually more than a few) words here about some recent discoveries I have made concerning the interaction of Leo and Python. If you don't want to hear an inventor enthuse about his work, please feel free not to read further :-) There are at least three, no four, no five, no six, no seven reasons why Leo and Python work so well together. Most are new (in my mind) with the 4.1 release of Leo. The first several...
24
5449
by: omlet | last post by:
omlet v4) wrote in message Dear DBA, You are cordially invited to test and review our windows native and 100% pure Java Oracle 9i/8i Monitoring Application (OMLET). OMLET is the Ultimate Visual Real Time Oracle Monitoring Tool. As the leading expert in your field, your opinion is highly valued and your feedback is very appreciated. We would like to encourage you to distribute copies of OMLET to your associates and fellow DBAs. Omlet can...
0
1584
by: Mirek Fidler | last post by:
Ultimate++ is the new generation C++ Windows/Linux open-source development platform. By utilizing of new ideas Ultimate++ achieves significant reduction of code complexity for most applications when compared to other development platforms. Ultimate++ based application sources tend to be significantly shorter (often more than 50%) than sources of equivalent applications developed using any other C++ platform (see comparison with Qt:
38
7137
by: | last post by:
I have a script... ----- <SCRIPT language="JavaScript" type="text/javascript"> <!-- function makeArray() { for (i = 0; i<makeArray.arguments.length; i++) this = makeArray.arguments; } function makeArray0() {
13
1916
by: Ray Muforosky | last post by:
Hello all: Task: I want to do file search, using the "conatining text" option from a web page. How do I search for a file on my local drive containing a certain string, from a web page. That is, how do run the windows search program from a web page. Any help will be appreciated.
4
2113
by: zakhirn | last post by:
Hello, I have an extremely new user to XML and XSL, and I would like to know how to search XML data via a input form in HTML, and have the results displayed in HTML. If anyone has code that can do that, could you please post the relevant files. I have searched the internet for a while now, and have been completely unsuccessful. I would like to do it using javascript in my XSL file if possible, or using CGI script to search the XML...
17
2528
by: =?Utf-8?B?Y2F0aGFyaW51cyB2YW4gZGVyIHdlcmY=?= | last post by:
Hello, I have build a website with approximately 30 html-pages. When I search this website in Google, I see the index.html or home.html on this website, but also other html-pages on this website. When I click in Google on one of these pages (not index.html or home.html), I am only linked to that one html-page and not to the website itself. Does anyone know how to fix this. Is there for example a metatag? Thanks
1
1301
by: snow | last post by:
The Ultimate Keyword Optimization Guide for Search Engine Positioning http://www.163as.com/news/Router%20Commands.html
1
16966
by: since | last post by:
I figured I would post my solution to the following. Resizable column tables. Search and replace values in a table. (IE only) Scrollable tables. Sortable tables. It is based on a lot examples I found on the web. Works in IE and mozilla. http://www.imaputz.com/cssStuff/bigFourVersion.html
0
8661
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8875
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7699
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5855
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3030
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2313
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1989
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.