CodeSnip: Using the Windows Indexing Service with ASP.NET and C#
page 3 of 5
by Brett Burridge
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 36674/ 136

How the Code Works

The ASP.NET page contains two web controls. A label control called LabelNumberOfResults is used to display the number of search results. It is also used to display an errors encountered during a search.

The page also contains a DataGrid control called DataGridSearchResults. This control is used to display the search results. There are columns within this DataGrid for displaying a document's rank, its title and the date the document was last updated. The title is a hyperlink to the actual document itself.

Note that further columns can of course be added if other document properties need to be displayed. Although a DataGrid is used in this example, other web controls can be useful for displaying search results - in some cases it would be appropriate to use the Repeater control for example.

The sample search does not contain a form for a user to enter a search query - for now the query is held within the C#'s QueryText string variable. This value could of course be assigned using the value of a textbox.

The name of the Indexing Service search catalog is contained in the CatalogName variable.

The document rank returned by the Windows Indexing Service has a value of between 0 and 1000 (with 1000 being the most closely matching document). The sample C# code reduces this to a figure between 0 and 10, which then allows the rank of each document to be shown graphically through a set of images with the filenames 0bars.png to 10bars.png inclusive.

Ordering Search Results

It is useful to be able to order search results. One way of achieving this would be to create a DataView from the search results data, and use that to populate the DataGrid:

Listing 1

//Create a DataView from the search results data
DataView SearchDataView = new DataView(SearchResultsTable.Tables[0]);
//Sort the search results by rank
SearchDataView.Sort = "PageRank DESC";
DataGridSearchResults.DataSource = SearchDataView;

Finally, if you are interested in extending the functionality of Indexing Services to allow content on any web server or ODBC database to be indexed and searchable, then take a look at the Indexing Service Companion utility I wrote: http://www.winnershtriangle.com/w/Products.IndexingServiceCompanion.asp.


View Entire Article

User Comments

No comments posted yet.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2018 ASPAlliance.com  |  Page Processed at 2018-02-25 9:00:32 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search