<%@ Language=VBScript%>
<%
'Sample Search page to demonstrate the ability of the
'Index Server Companion to retrieve content from remote
'websites.
'By entering a word or words into the search box
'it is possible to search articles written by our consultant
'from ASPAlliance.com, ASPToday and Ariadne.ac.uk.
'See this sample working at
'http://www.winnershtriangle.com/w/Products.IndexServerCompanion.SampleSearch.asp
Option Explicit
On Error Resume Next
'Initialise variables
Dim sSearchString
Dim oQuery
Dim sDocumentTitle
Dim sDocumentURL
Dim DocumentInformation
Dim iRanking
Dim sSpacer
Dim sArticleSite
Dim oRS
Dim iNumberOfSearchResults
'Retrieve search string from QueryString
sSearchString = Request.QueryString("query")
'Call the function to cleanup the search string
sSearchString = CleanupQuery(sSearchString)
'The path to the files to be searched
'remember to append a wildcard * to the end or beginning of this constant as appropriate
Const DOCUMENTS_PATH = "*ASPArticles\SampleContent*"
'The name of the Index Server search catalog
Const SEARCH_CATALOG = "www.brettb.com"
%>
<html>
<head>
<title>Winnersh Triangle Web Solutions Limited - Index Server Companion Sample Search</title>
<meta name="Microsoft Border" content="none">
</head>
<body>
<!--BEGIN SEARCH FORM-->
<%
'No search term was specified, so show the search form
If sSearchString = "" Then
%>
<font face="Courier New" size="4">Index
Server Companion: Sample Search</font><p><font face="Courier New" size="2">This search
facility demonstrates the ability of the Index Server Companion to allow Index Server to
index content from remote websites. By entering a word or words into the search box below
it is possible to search articles written by our consultant from ASPAlliance.com, ASPToday
and Ariadne.ac.uk:</font></p>
<form method="GET" name="frmSearch" action="Search.asp">
<p><input
type="text" name="query" size="20" value="index server">
<input name="Go"
alt="Continue" align="absmiddle" type="submit"></p>
</form>
<!--END SEARCH FORM-->
<%
End If
%>
<!--BEGIN SEARCH RESULTS-->
<%
'A search term was specified, so show the search results
If sSearchString <> "" Then
Set oQuery = Server.CreateObject("IXSSO.Query")
oQuery.Catalog = SEARCH_CATALOG
'Build the search query
oQuery.Query = "@all " & sSearchString & " AND #path " & DOCUMENTS_PATH & " AND NOT #path *_vti*"
'Limit the number of search results returned
oQuery.MaxRecords = 15
'Sort the results by rank
oQuery.SortBy = "rank[d]"
'Specify which columns are returned
oQuery.Columns = "doctitle, FileName, Path, Write, Size, Rank"
'Create the results RecordSet
Set oRS = oQuery.CreateRecordSet("nonsequential")
iNumberOfSearchResults = 0
'Count the number of results returned
If Err.Number = 0 Then
If Not oRS.EOF Then
Do While Not oRS.EOF
iNumberOfSearchResults = iNumberOfSearchResults + 1
oRS.MoveNext
Loop
oRS.MoveFirst
End If
End If
If iNumberOfSearchResults > 0 Then
Response.write("<font face=""Courier New"" size=""3"">")
Response.write(iNumberOfSearchResults & " document(s) were found matching the query '" & sSearchString & "'<p>")
Response.write("</font>")
Do While Not oRS.EOF
'Extract the document's URL and title
If Instr(oRS("doctitle"), "ISC_URL") > 0 Then
'Split the doctitle at a tab character
DocumentInformation = Split(oRS("doctitle"), chr(9))
'The document's URL is the first item in the array
sDocumentURL = DocumentInformation(0)
'Remove the "ISC_URL=" text in the document URL
sDocumentURL = Replace(sDocumentURL, "ISC_URL=", "")
'The document's title is the second item in the array
sDocumentTitle = DocumentInformation(1)
Else
sDocumentTitle = oRS("doctitle")
sDocumentURL = "http://www.winnershtriangle.com/w/"
End If
iRanking = oRS("Rank")
iRanking = Int(iRanking/10)
sSpacer = ""
'Add some space so the document rank is right justified
If iRanking < 100 Then sSpacer = " "
If iRanking < 10 Then sSpacer = " " & sSpacer
'Determine which website the particular document originated
If Instr(sDocumentURL, "ariadne.ac.uk") > 0 Then sArticleSite = " Ariadne"
If Instr(sDocumentURL, "aspalliance.com") > 0 Then sArticleSite = "ASPAlliance"
If Instr(sDocumentURL, "asptoday.com") > 0 Then sArticleSite = " ASPToday"
Response.write("<font face=""Courier New"" size=""1"">")
Response.write(sSpacer & iRanking & "% ")
Response.write(sArticleSite & " ")
Response.write "<a href=""" & sDocumentURL & """ title=""" & sDocumentTitle & """>" & sDocumentTitle & "</a><br>" & vbCRLF
Response.write("</font>")
oRS.MoveNext
Loop
Response.write("<font face=""Courier New"" size=""2"">")
Response.write("<p><a href=""Search.asp"" title=""Try another search"">Try another search</a> ")
Response.write("</font>")
Else
'The search did not return any results
If err.Number = 0 Then
Response.write("<font face=""Courier New"" size=""3"">")
Response.write("No document(s) were found matching the query '" & sSearchString & "'<p>")
Response.write("</font>")
Response.write("<font face=""Courier New"" size=""2"">")
Response.write("<p><a href=""Search.asp"" title=""Try another search"">Try another search</a>")
Response.write("</font>")
'The search did not return any results and there was an error
Else
Response.write("<font face=""Courier New"" size=""3"">")
Response.write("Search Error<p>")
Response.write("</font>")
Response.write("<font face=""Courier New"" size=""2"">")
Response.write("The search gave the following error: ")
Response.write(err.number & ": " & err.description & "")
Response.write("</font>")
Response.write("<font face=""Courier New"" size=""2"">")
Response.write("<p><a href=""Search.asp"" title=""Try another search"">Try another search</a>")
Response.write("</font>")
End If
End If
Set oQuery = nothing
End If
%>
<!--END SEARCH RESULTS-->
</body>
</html>
<%
'This function is used to cleanup the search query
'SearchString = Search string
'Return = cleaned query
Function CleanupQuery(SearchString)
If Instr(1, SearchString, " ") > 0 Then 'if a query has a space then put in ANDs
If Instr(1, SearchString, " and ", 1) = 0 Then
SearchString = Replace(SearchString, " ", " AND ")
End If
End If
CleanupQuery = SearchString
End Function
%>