Syntax highlighted source code generated using the ASP Documentation Tool. Note that the Indexing Service Companion also contains C# sample code for ASP.NET.

1: <%@ Language=VBScript%>
2: <%
3: 'Sample Search page to demonstrate the ability of the
4: 'Indexing Service Companion to retrieve content from remote
5: 'websites.
6: 'By entering a word or words into the search box
7: 'it is possible to search articles written by our consultant
8: 'from ASPAlliance.com, ASPToday and Ariadne.ac.uk.
9: 'See this sample working at
10: 'http://www.winnershtriangle.com/w/Products.IndexServerCompanion.SampleSearch.asp
11:
12: Option Explicit
13:
14: On Error Resume Next
15:
16: 'Initialise variables
17: Dim sSearchString
18: Dim oQuery
19: Dim sDocumentTitle
20: Dim sDocumentURL
21: Dim DocumentInformation
22: Dim iRanking
23: Dim sSpacer
24: Dim sArticleSite
25: Dim oRS
26: Dim iNumberOfSearchResults
27:
28: 'Retrieve search string from QueryString
29: sSearchString = Request.QueryString("query")
30:
31: 'Call the function to cleanup the search string
32: sSearchString = CleanupQuery(sSearchString)
33:
34: 'The path to the files to be searched
35: 'remember to append a wildcard * to the end or beginning of this constant as appropriate
36: Const DOCUMENTS_PATH = "*ASPArticles\SampleContent*"
37:
38: 'The name of the Indexing Service search catalog
39: Const SEARCH_CATALOG = "www.brettb.com"
40: %>
41: <html>
42:
43: <head>
44: <title>Winnersh Triangle Web Solutions Limited - Indexing Service Companion Sample Search</title>
45: <meta name="Microsoft Border" content="none">
46: </head>
47:
48: <body>
49: <!--BEGIN SEARCH FORM-->
50: <%
51: 'No search term was specified, so show the search form
52: If sSearchString = "" Then
53: %>
54: <font face="Courier New" size="4">Index
55: Server Companion: Sample Search</font><p><font face="Courier New" size="2">This search
56: facility demonstrates the ability of the Indexing Service Companion to allow Indexing Service to
57: index content from remote websites. By entering a word or words into the search box below
58: it is possible to search articles written by our consultant from ASPAlliance.com, ASPToday
59: and Ariadne.ac.uk:</font></p>
60: <form method="GET" name="frmSearch" action="Search.asp">
61: <p><input
62: type="text" name="query" size="20" value="index server">
63: <input name="Go"
64: alt="Continue" align="absmiddle" type="submit"></p>
65: </form>
66: <!--END SEARCH FORM-->
67: <%
68: End If
69: %>
70: <!--BEGIN SEARCH RESULTS-->
71: <%
72: 'A search term was specified, so show the search results
73: If sSearchString <> "" Then
74:     
75:     Set oQuery = Server.CreateObject("IXSSO.Query")
76:     oQuery.Catalog = SEARCH_CATALOG
77:
78:     'Build the search query
79:     oQuery.Query = "@all " & sSearchString & " AND #path " & DOCUMENTS_PATH & " AND NOT #path *_vti*"
80:     
81:     'Limit the number of search results returned
82:     oQuery.MaxRecords = 15
83:     
84:     'Sort the results by rank
85:     oQuery.SortBy = "rank[d]"
86:     
87:     'Specify which columns are returned
88:     oQuery.Columns = "doctitle, FileName, Path, Write, Size, Rank"
89:     
90:     'Create the results RecordSet
91:     Set oRS = oQuery.CreateRecordSet("nonsequential")
92:     
93:     iNumberOfSearchResults = 0
94:     
95:     'Count the number of results returned
96:     If Err.Number = 0 Then
97:     
98:         If Not oRS.EOF Then
99:             Do While Not oRS.EOF
100:                 iNumberOfSearchResults = iNumberOfSearchResults + 1
101:             oRS.MoveNext
102:             Loop
103:     
104:             oRS.MoveFirst
105:         End If
106:     
107:     End If
108:
109:     If iNumberOfSearchResults > 0 Then
110:
111:         Response.write("<font face=""Courier New"" size=""3"">")
112:         Response.write(iNumberOfSearchResults & " document(s) were found matching the query '" & sSearchString & "'<p>")
113:         Response.write("</font>")
114:
115:         Do While Not oRS.EOF
116:     
117:             'Extract the document's URL and title
118:             If Instr(oRS("doctitle"), "ISC_URL") > 0 Then
119:
120:              'Split the doctitle at a tab character
121:              DocumentInformation = Split(oRS("doctitle"), chr(9))
122:
123:              'The document's URL is the first item in the array
124:              sDocumentURL = DocumentInformation(0)
125:
126:              'Remove the "ISC_URL=" text in the document URL
127:              sDocumentURL = Replace(sDocumentURL, "ISC_URL=", "")
128:
129:              'The document's title is the second item in the array
130:              sDocumentTitle = DocumentInformation(1)
131:
132:             Else
133:
134:                 sDocumentTitle = oRS("doctitle")
135:                 sDocumentURL = "http://www.winnershtriangle.com/w/"
136:
137:             End If
138:
139:             'Extract the URL for other files (e.g. PDF and DOC files)
140:             If Left(oRS("FileName"), 2) = "o_" Then
141:             
142:                 sDocumentTitle = oRS("doctitle")
143:                 sDocumentURL = CreateURLFromFileName(oRS("FileName"))
144:             
145:             End If
146:
147:             iRanking = oRS("Rank")
148:
149:             iRanking = Int(iRanking/10)
150:
151:             sSpacer = ""
152:
153:             'Add some space so the document rank is right justified
154:             If iRanking < 100 Then sSpacer = " "
155:             If iRanking < 10 Then sSpacer = " " & sSpacer
156:
157:             'Determine which website the particular document originated        
158:             If Instr(sDocumentURL, "ariadne.ac.uk") > 0 Then sArticleSite = "    Ariadne"
159:             If Instr(sDocumentURL, "aspalliance.com") > 0 Then sArticleSite = "ASPAlliance"
160:             If Instr(sDocumentURL, "asptoday.com") > 0 Then sArticleSite = "   ASPToday"
161:
162:             Response.write("<font face=""Courier New"" size=""1"">")
163:             Response.write(sSpacer & iRanking & "% ")
164:             Response.write(sArticleSite & " ")
165:
166:             Response.write "<a href=""" & sDocumentURL & """ title=""" & sDocumentTitle & """>" & sDocumentTitle & "</a><br>" & vbCRLF
167:             Response.write("</font>")
168:
169:
170:             oRS.MoveNext
171:
172:          Loop
173:     
174:         Response.write("<font face=""Courier New"" size=""2"">")
175:         Response.write("<p><a href=""Search.asp"" title=""Try another search"">Try another search</a> ")
176:         Response.write("</font>")
177:
178:     Else
179:     
180:         'The search did not return any results
181:         If err.Number = 0 Then
182:
183:             Response.write("<font face=""Courier New"" size=""3"">")
184:             Response.write("No document(s) were found matching the query '" & sSearchString & "'<p>")
185:             Response.write("</font>")
186:
187:             Response.write("<font face=""Courier New"" size=""2"">")
188:             Response.write("<p><a href=""Search.asp"" title=""Try another search"">Try another search</a>")
189:
190:             Response.write("</font>")
191:
192:         'The search did not return any results and there was an error
193:         Else
194:
195:             Response.write("<font face=""Courier New"" size=""3"">")
196:             Response.write("Search Error<p>")
197:             Response.write("</font>")
198:
199:             Response.write("<font face=""Courier New"" size=""2"">")
200:             Response.write("The search gave the following error: ")
201:             Response.write(err.number & ": " & err.description & "")
202:             Response.write("</font>")
203:
204:             Response.write("<font face=""Courier New"" size=""2"">")
205:             Response.write("<p><a href=""Search.asp"" title=""Try another search"">Try another search</a>")
206:
207:             Response.write("</font>")
208:
209:         End If
210:
211:     End If
212:
213:     Set oQuery = nothing
214:
215: End If
216: %>
217: <!--END SEARCH RESULTS-->
218: </body>
219: </html>
220: <%
221: 'This function is used to cleanup the search query
222: 'SearchString = Search string
223: 'Return = cleaned query
224: Function CleanupQuery(SearchString)
225:     
226:     If Instr(1, SearchString, " ") > 0 Then 'if a query has a space then put in ANDs
227:
228:         If Instr(1, SearchString, " and ", 1) = 0 Then
229:             SearchString = Replace(SearchString, " ", " AND ")
230:         End If
231:
232:     End If
233:     
234:     CleanupQuery = SearchString
235:
236: End Function
237:
238: 'Non-HTML files like Adobe Acrobat PDF files and Word
239: 'documents are stored with their original URLs partially
240: 'encoded in their filenames. This function will return the
241: 'original URL of the file.
242: 'The encoding done by the Indexing Service Companion removes
243: 'characters that cannot be present in Windows filenames
244: '(these are: \/:*?"<>|)
245: Function CreateURLFromFileName(FileName)
246:     
247:     'Remove o_ prefix from URL
248:     FileName = Mid(FileName, 3, Len(FileName) - 2)
249:     
250:     'Remove other encoded characters
251:     FileName = Replace(FileName, "^f", "\")
252:     FileName = Replace(FileName, "^b", "/")
253:     FileName = Replace(FileName, "^c", ":")
254:     FileName = Replace(FileName, "^s", "*")
255:     FileName = Replace(FileName, "^q", "?")
256:     FileName = Replace(FileName, "^d", Chr(34))
257:     FileName = Replace(FileName, "^l", "<")
258:     FileName = Replace(FileName, "^g", ">")
259:     FileName = Replace(FileName, "^p", "|")
260:     
261:     CreateURLFromFileName = FileName
262:
263: End Function
264: %>

Close Window