At 04:32 AM 1/24/2005, Ciaran Lyne wrote:
>I am looking to use Swish-E with ASP
>
>The link on 3rd party scripts page on Swish-E web site for Swish-EX no
>longer works
>
>Are there any other examples of using Swish-E with ASP pages?
Ciaran...
Here is what I currently use to get data back from the Swish Index using
ASP. This is based on ASP code that was either part of the Swish-e install
or from an example page I stumbled upon. It's been tweaked for format
changes and bugs from the original.
It needs a bit more work to have CSS embedded in the HTML output versus the
hard coding that currently exits.
Hope this helps.
-=-=--=-=--=-=--=-=--=-=--=-=--=-=--=-=--=-=--=-=--=-=--=-=-
Dim strSearchWords, intStart, intPage, intPageNum, intTemp
swisheLocation = "x:\path\to\swish-e.exe"
swisheIndex = "x:\path\to\index.swish-e"
strSearchWords = Request("SearchString")
PageName = request.ServerVariables("SCRIPT_NAME")
'This is the number of results to show on a page
intPage = 10
'This handles what result number to start at - this assists in paging
If Request("start") <> "" Then
intStart = Request("start")
Else
intStart = 1
End If
If strSearchWords <> "" Then
Dim strParam, Executor, strResult, arrResults, intHeader, strHeader, i,
arrResults2, strTemp,z, arrHeader
'' strParam = "-w """ & strSearchWords & """ -b " & intStart & " -m " &
intPage & " -x
""\<BR\><swishrank>|<swishtitle>|<swishdocpath>|<swishdescription>"" -f """
& swisheIndex & """"
strParam = "-w """ & strSearchWords & """ -b " & intStart & " -m " &
intPage & " -x ""\<BR\>%r|%t|%p|%d\n"" -f """ & swisheIndex & """"
Set Executor = Server.CreateObject("ASPExec.Execute")
Executor.Application = swisheLocation
Executor.Parameters = strParam
Executor.ShowWindow = True
strResult = Executor.ExecuteDosApp 'runs the search and returns the
results as text
if (len(strResult) > 0) then
intHeader = InStr(strResult,"<BR>") -1 'finds where the first break is
Response.Write "<table width=""690"" cellpadding=""2"">"
If intHeader = "-1" Then 'This will handle if the search did not
find any matches
Response.Write "<tr><td><b><font class=""font12pt"">There were
no matches. Please try searching again</font></b></td></tr>"
Else
strHeader = Left(strResult,intHeader) 'grabs the header
arrHeader = Split(strHeader,"#") 'splits the header into
specific fields to be used
intTemp = InStr(arrHeader(4),": ") + 2
intPageNum = Trim(Mid(arrHeader(4),intTemp))
Response.Write "<tr><td colspan=""2"">"
Response.Write "<strong>" & intPageNum & " Documents found
matching query</strong>: """ & strSearchWords & """"
Response.Write "</td></tr>"
Response.Write "<tr><td colspan=""2"" bgcolor=""#D8DFEB"">"
if (intStart+intPage)-1 < int(intPageNum) then
iShowCount = (intStart+intPage)-1
else
iShowCount = intPageNum
end if
Response.Write "<center><b>Documents " & intStart & " to " &
iShowCount & "</b><br>"
Call Paging(intStart,intPage,intPageNum) 'Will provide the
paging links if there is more than one page
Response.Write "</center></td></tr>"
strResult = Mid(strResult,intHeader) 'removes the header from
the search results
arrResults = Split(strResult,"<BR>") 'splits the results into
an array
For i = 1 to UBound(arrResults) 'loops through the one
dimensional array
strTemp = arrResults(i)
arrResults2 = Split(strTemp,"|") 'splits the single result
into specific fields to be used
Response.Write "<tr><td width=""10"" valign=""top"">" &
i+(intStart-1) & ". </td><td width=""640"" valign=""top""><a href=""" &
arrResults2(2) & """>" & arrResults2(1) & "</a><!-- <BR> (Match Rank: " &
arrResults2(0) & ") --></td></tr>"
iLoc = InStr(arrResults2(3),"Sitemap")
if iLoc > 0 then
iLoc = iLoc + 7
else
iLoc = 1
end if
Response.Write "<tr><td width=""10""
valign=""top""> </td><td>" &
mid(arrResults2(3),iLoc,Len(arrResults2(3))) & "</td></tr>"
Next
Response.Write "<tr><td colspan=""2"" bgcolor=""#D8DFEB"">"
Response.Write "<center><b>Documents " & intStart & " to " &
iShowCount & "</b><br>"
Call Paging(intStart,intPage,intPageNum) 'Will provide the
paging links if there is more than one page
Response.Write "</center></td></tr>"
End If
Response.Write "</table>"
end if
else
'' Show site map
end if
Sub Paging(start,num,theend)
'This sub will handle paging as far as setting up the links for the
result pages
Dim pages, g, newstart, nextstart
'' Response.Write "<b>Pages: </b>"
pages = theend\num 'find the number of whole pages
If theend Mod num <> 0 Then 'find out if there is a partial page
pages = (pages+1)
End If
newstart = 1 'initialize the starting point for the links
If (start - num) > 0 Then
Response.Write "<a href=""" & PageName & "?SearchString=" &
strSearchWords & "&start=" & (start - num) & """>PREV</a> "
else
Response.Write "PREV "
End If
For g = 1 to pages 'iterate through to create the links
If (g-1) <> (start\num) Then
Response.Write "<a href=""" & PageName &
"?SearchString=" & strSearchWords & "&start=" & newstart & """>" & g &
"</a> "
Else
Response.Write "<b>" & g & "</b> "
nextstart = newstart + num
End If
newstart = newstart + num
Next
If nextstart <> newstart Then
Response.Write "<a href=""" & PageName & "?SearchString=" &
strSearchWords & "&start=" & nextstart & """>NEXT</a> "
else
Response.Write "NEXT "
End If
End Sub
Received on Mon Jan 24 13:40:56 2005