FindinSite-MS: Search engine for an ASP.NET website   .
  search
Powered by FindinSite-MS
. Home | Installation | Indexing | Control Panel | Web services | Advanced | Purchasing .
. .
  Search API / Example 1 C# / Example 2 C# / Example 3 C#

 

Search API form - display to a DataGrid

    [This is C# version] [VB version]

findinsite-ms has a Search API web service - a programmer interface to the search engine that can be used over the internet.

This ASP.NET example shows a search form and displays the results in a DataDrid control, displaying 10 hits at a time. This approach is familiar as this is how most search engines display their results - although the layout could be improved.

If you do a search for * here (ie to find all possible hits) then the page should return quickly because only 10 results have to be returned to your browser. The same search done in Example 1 could take a long time over a slow connection because hundreds of results have to be returned. However, see the Information Flows section for a full discussion of possible delays.

The results are cached in a Session variable so that requests for another set of hits can be fulfilled without having to call the Search API.

Try out the search form - then see below for programming details.


Search form

Search API URL:
Search

Results:


Programmer instructions

The example works in exactly the same way as Example 1 so full programming details are not shown.

The SearchButton_Click() and ShowResults() script methods are largely the same. However SearchButton_Click() resets the DataGrid page index to zero, and stores the result in the "fisSearchResult" Session variable.
HitDataGrid.CurrentPageIndex = 0;
ShowResults(result);
Session["fisSearchResult"] = result;

The HitDataGrid DataGrid control is used in a very similar way to the Repeater control in example 1, ie the fisSearchResult.Hits array is set as its DataSource. The DataGrid control PageIndexChanged event is set to the new script method Page_Change():

private void Page_Change(object source, DataGridPageChangedEventArgs e)
{
try
{
    // Set CurrentPageIndex to the page the user clicked.
    HitDataGrid.CurrentPageIndex = e.NewPageIndex;

    fisClient.fisSearchResult result = (fisClient.fisSearchResult)Session["fisSearchResult"];
    if( result==null)
    {
        result = new fisClient.fisSearchResult();
        result.Message = "Session did not store fisSearchResult";
    }

    ShowResults(result);
}
catch( Exception ex)
{
    JustShowMessage(ex.Message);
}
}

This code sets the DataGrid control CurrentPageIndex, retrieves the result from the Session variable, and calls ShowResults() as before.

The example can be enhanced easily to cope if the Session has expired.

  All site Copyright © 1996-2009 PHD Computer Consultants Ltd, PHDCC   Privacy  

Last modified: 30 October 2005.