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 VB / Example 2 VB / Example 3 VB

 

Search API form - display to a DataGrid

    [C# version] [This is 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 Sub Page_Change(sender As Object, e As DataGridPageChangedEventArgs)

    Try
        ' Set CurrentPageIndex to the page the user clicked.
        HitDataGrid.CurrentPageIndex = e.NewPageIndex

        Dim result As fisClient.fisSearchResult
        result = Session("fisSearchResult")
        if result is Nothing Then
            result = new fisClient.fisSearchResult()
            result.Message = "Session did not store fisSearchResult"
        End If

    ShowResults(result)
    Catch ex As Exception
        JustShowMessage(ex.Message)
    End Try

End Sub

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.