|
ASP Kitchen: Classic ASP Articles: Searching Index Server With ASP Searching Index Server With ASPIntroductionA previous article on ASPAlliance.com enthuses about Index Server. Id agree with the author - Index Server makes it very straightforward to create search solutions that would cost many thousands of dollars to implement using alternative technologies. This article describes what is required to use Index Server from within ASP. It assumes you have access to a web server running Internet Information Server 4.0 on Windows NT Server. The article is particularly suitable if, like me, you have Windows NT hosting with a company such as Alentus, who can supply Index Server support for a modest annual charge. Note that Windows 2000 Server also has an equivalent to Index Server called Indexing Services, but theres no guarantee that these code samples will work on Windows 2000. Incidentally, the code samples described in this article are available from a link at the end of the article. Creating a search formThe first thing to do is to create a page containing a form in which the user can enter their search word or phrase. You can of course have a combined search form page and search results page, but I prefer to keep them separate. An example search form is shown below. This code should be saved as SearchForm.asp: <form method="POST"
action="SearchResults.asp" name="frmSearch"> As you can see from this HTML, it is a simple form that will post a single text field called query to the page called SearchResults.asp. Creating a search results pageThe following code can be used for a basic search results page. It should be saved as SearchResults.asp. The first part of the search results page initialises variables and constants: <% The search string was posted from the SearchForm.asp search form page, and the word or phrase to be searched for are extracted from the query item in the Request.Form collection. The SEARCH_CATALOG constant is also defined. This name will vary so you will have to change it. If your site is hosted with a hosting company then they will usually set up a catalog on the Index Server for you, then let you know the name of your search catalog. If you are using your own web server, then you should be able to determine the catalog name from the Index Server Management Console. Describing how to set up and use Index Server catalogs is beyond the scope of this article, but further information is available in the IIS 4.0 reference guide (try http://localhost/iishelp/). The next part of the search results page initialises the Index Server Query COM component which enables the search to be performed: <% Further details of the Query objects methods and properties are to be found in the IIS 4.0 online documentation. The properties of the object set in the sample code above are as follows:
Finally, an ADO RecordSet is created from the records found for this search. The neat thing about Index Server is that the returned RecordSet of search results can be used in an almost identical fashion to RecordSets returned from databases. A list of results is, therefore, displayed simply by looping through this RecordSet and displaying fields from the RecordSet: <% This code loops through the records corresponding to the matching documents found and displays some of the properties of each document. This is where the columns property of the Index Server Query are used: these specify the column names that are returned for each record. In the sample code above, FileName refers to the records name on disk.
doctitle corresponds to the documents title (i.e. <title> tag if the document is HTML). Size is the size in bytes of the file on disk. Create is the date and time the document was created, whereas Write is the date and time the document was modified. Finally, Characterization is a summary of the document. The summary corresponds to the Description meta tag in HTML files, so it is worthwhile putting this tag into documents. If the Description tag isnt present, Index Server will display the first one or two sentences from the document. Finally at the bottom of the page the objects are released: <% An example screenshot of the search results page is below as described above, the page displays the FileName, doctitle, Size, Create and Characterization for each matching document:
As you can see the page is fairly basic, so a few cosmetic improvements would be required if the page was to be used on a production website. Further suggestions for improving the display of search results are in the article "More about Searching Index Server With ASP". Code samples and working ASP pages
Further reading
Useful Development Tools
Author detailsBrett Burridge has worked as a web developer since 1997 and has developed web applications for a range of corporations, start up busiensses and educational establishments. Brett is presently employed as an Internet developer and technical writer through his own company, Winnersh Triangle Web Solutions Limited. The company produces a number of innovative products, including a range of software documentation tools, which include the ASP Documentation Tool, the .NET Documentation Tool for VB.NET and C#, and the SQL Server Documentation Tool. Other products include The Website Utility, which functions as a website error checker, search engine optimizer and ASP/ASP.NET search engine builder application. As well as the ASPAlliance, Brett has written articles for Ariadne.ac.uk, ASPToday, the software documentation portal www.softwaredocumentation.info, and has contributed recipes to the ASP.NET Developer's Cookbook. links Outside web development, Brett is interested in travelling (here are my travel logs from New York, Hong Kong and Tokyo), digital photography (here's my photo gallery), tropical fishkeeping and collecting contemporary works of art by artists such as Doug Hyde. Contact Brett by emailing Article history"Searching Index Server With ASP" published on ASPAlliance.com on 30 September 2001. Last revised 13 May 2003. ASP Kitchen: Classic ASP Articles: Searching Index Server With ASP |
|
||||||||||||||||||||||||||||
| © page content copyright Brett Burridge 1998 - 2008. | |||||||||||||||||||||||||||||