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 Repeater

    [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 example ASP.NET web form page displays a simple form with one search textbox.
  • When a search is requested, the page sends the search to findinsite-ms.
  • Finally, it displays all the found results in a Repeater control.
  • This approach is simple but may take some time to respond for a large number of hits.

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

Search form

Search API URL:
Search

Results:


Programmer instructions

This page contains C# script code that is compiled when the page is loaded for the first time - it does not use a .cs file. However it does use the fisClient class library, which should be in bin/phdcc.fis.fisClient.dll. If you have downloaded the development kit, then you can see the page source.

The search form for the page was generated using standard ASP.NET Web Forms controls, eg:
<form ... runat="server">
<asp:Label ... runat="server"></asp:Label ...>
<asp:textbox ... runat="server"></asp:textbox ...>
etc.

The "Go" button is called SearchButton. Clicking on this fires the SearchButton_Click() event handler, which contains this code:

private void SearchButton_Click(object sender, System.EventArgs e)
{
    try
    {
        fisClient.SearchService fis = new fisClient.SearchService(SearchAPIURL.SelectedItem.Text);
        fisClient.fisSearchRequest req = new fisClient.fisSearchRequest(SearchText.Text);
        fisClient.fisSearchResult result = fis.Search(req);

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

private void ShowResults(fisClient.fisSearchResult result)
{
    ...
    HitRepeater.DataSource = result.Hits;
    HitRepeater.DataBind();
}

This code makes a new fisClient.SearchService object, passing in the selected URL. It then makes a new request object (fisClient.fisSearchRequest) containing the entered search text; all other request options are left at their default values, so all details of all hits will be returned.

The code then calls Search(). The returned fisSearchResult object is passed to ShowResults(). The crucial part of this method sets the fisSearchResult.Hits array as the DataSource for the Repeater control called HitRepeater. ASP.NET then iterates through all the hits, generating HTML according to the XML templates specified for the repeater control:

<asp:repeater id="HitRepeater" runat="server">
<HeaderTemplate>
    <ol>
</HeaderTemplate>
<ItemTemplate>
    <LI><asp:HyperLink id="Hyperlink1" runat="server"
            NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "URL")%>'>
            <%# DataBinder.Eval(Container.DataItem, "Title")%>
        </asp:HyperLink>
        <asp:Label id="Label3" runat="server"
            Text='<%# DataBinder.Eval(Container.DataItem, "Abstract")%>'>
        </asp:Label>
        <br>
    </LI>
</ItemTemplate>
<FooterTemplate>
    </ol>
</FooterTemplate>
</asp:repeater>

ASP.NET extracts the URL, Title and Abstract fields of each fisHit, and generates an ordered list with the title hyperlinked to the URL, followed by the abstract.

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

Last modified: 30 October 2005.