Dev Direct Solution Center

For more information and to buy this product...

How to add a search engine to your site and index documents from the file system & web server

  For a copy of the sample project please click here to download and install the product evaluation.

Introduction

These C# and VB.NET solutions show how to build a search index from files in the local file system (which may not be linked to the site itself) and then display a search box which causes the index to be searched and displays a search results page.

Detail

Setup

1. Download and install the Search Pro for ASP.NET
2. Open the solution file Company_Intranet_Scenario.sln
(Located under Visual Studio 2005 advanced demo projects)
3. Run the project and view Example1_CompanyIntranet for a full guide to this solution.

The Controls

The SearchBox control is simply dragged on to the designer to provide the search query box for your users. All that is required is to set the ResultPageURL to the page containing the SearchResult control.

<SearchEngine:SearchBox ID="SearchBox1" runat="server" ResultPageURL="SearchResults.aspx">

SearchResult Control: This control does all the work necessary to search your entire web site or intranet. Just set the IndexDirectory property to a folder to be used to store the index files.

<SearchEngine:SearchResult ID="SearchResult1" runat="server" IndexDirectory="~/Example1_CompanyIntranet/IndexDirectory"

The index management tool (below) is accessed from the SearchResult control providing a user friendly way of importing documents, managing content or location categories and building the index.

Full Solution Guide

This example shows how to index a site containing various documents located on the web server and file-system. This demonstrates usage when a web-site has document folders without HTML links to each document.

We will;

1. Import ASPX and HTML pages from the web server
2. Import PDF and Word documents stored on the file-system
3. Build the index
4. Configure the windows service to update the index once a week
5. Deploy new documents

1. Import pages from web server

From the page containing the SearchResult control (Example1_CompanyIntranet/SearchResults.aspx in our example), access the index management tool and select Import Documents/Records.

To begin importing enter the start URL for the site and click Import. In this example;

http://localhost:49094/Company_Intranet/IntranetDemoSite/Notices.aspx

The spider will then proceed to read the site and add new links. Once complete you can see these links by clicking Edit Doc. UrI List.

2. Import documents from file-system

In our demo site we have a folder that contains documents we want indexed for searching but are not linked to from any pages on the site (IntranetDemoSite/Policies/).

The easiest way to add these to the index is to use a file-system import.

From the Import section of the index management tool, select FileSystemDocumentStore from the Type of Source drop down list.

Enter the Local Folder Path, in this example;

..\..\IntranetDemoSite\Policies\ which contains the documents on the file-system required to be indexed for searching. The local folder path can be relative to the index directory.

Next enter the Virtual Folder Path, in this example;

http://localhost:49094/Company_Intranet/IntranetDemoSite/Policies/ any documents found under the local folder path are automatically mapped to the Virtual Folder path.

Before Importing we need to set the document types to be included in the Import. Click More Options and under Target Match List add the document types, in this example '.doc' and '.pdf'. Only these document types will be Imported.

Click Import to add the documents to the index. Once complete you can see the documents that have been added by clicking Edit Doc. UrI List.

3. Build the index

From the index management tool, click Build Index for Searching and then Start Build.

4. Configure the windows service

In our example we want to update the index with any new documents, automatically, once each week. This is achieved by using the windows service. For details on installing the windows service please see the Administration App. & Windows Service section of the Help user-guide.

The configuration.xml file under the Index Directory needs to be setup with the details required by the windows service. To edit the configuration, from the SearchResult control select Configuration and scroll down to the Windows Service section at the bottom.

The following settings should be configured;

ServiceRebuildFrequency - how many hours should pass since the last indexing operation. In this example it is set to 168. (24hrs x 7 days).

ServiceRebuildHour - the hour of the day at which the first indexing operation will happen. In this example it is set to 13. The first indexing operation will therefore start at 1:00pm.

ServiceWillReImport - whether the windows service will reimport all sources when re-indexing. In this example the tick box is checked so that any new linked documents will be added to the index.

Click OK to save the changes to the configuration file. After any changes are made to the windows service settings you must restart the service for any changes to take effect. Load the service (Control Panel > Administrative Tools > Services) open Keyoti_Search_Index_Service and restart.

5. Deploy new documents

New documents which have been added and are linked to by the site will be added during the next re-indexing operation.

File-system:

Any new documents added to the local folder can be deployed by copying them to the Virtual Folder. The new documents will be added during the next re-indexing operation.

------

This solution demonstrates the simplest way implementing Search for ASP.NET, please view the full product demos in the evaluation which show how to integrate search in a variety of situations.

Visit Keyoti for more information and more samples.