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


All options Search API form

    [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.

The page contains a search form that lets you try out all the available search options provided by the Search API. The results are shown in a paged DataGrid in the same way as Example 2. The page also lets you try out the GetSubsets() and GetFieldnames() Search API methods - click on the "Get Subsets List" button - then the "Get Fields List" button.

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

Search form

Search API URL:
From: If "From" and "To" fields are both 0 (zero), then all search hits are returned. For other numbers, only the appropriate hits are returned.
"title" field:
"description" field:


Programmer instructions

The web form and script used in this example are standard ASP.NET C#, so a detailed explanation is not given. See Example 1 and Example 2 for details of the basic interactions. The following code block shows the new SearchButton_Click() handler.

Note that this example does NOT show how to request blocks of hits on demand when the DataGrid page index changes. To only request hit information when the page index changes, you will probably need to provide a custom class as the DataGrid DataSource.

private void SearchButton_Click(object sender, System.EventArgs e)
    int from = System.Int32.Parse(FromText.Text);
    int to = System.Int32.Parse(ToText.Text);
    fisClient.SearchService fis = new fisClient.SearchService(SearchAPIURL.SelectedItem.Text);
    fisClient.fisHitAttributes hit_elems = 0;
    foreach (ListItem item in Search2Elements.Items)
            if( item.Value=="All")
                hit_elems |= fisClient.fisHitAttributes.All;
            if( item.Value=="ResultNo")
                hit_elems |= fisClient.fisHitAttributes.ResultNo;
            if( item.Value=="Title")
                hit_elems |= fisClient.fisHitAttributes.Title;
            if( item.Value=="URL")
                hit_elems |= fisClient.fisHitAttributes.URL;
            if( item.Value=="HighlightURL")
                hit_elems |= fisClient.fisHitAttributes.HighlightURL;
            if( item.Value=="Abstract")
                hit_elems |= fisClient.fisHitAttributes.Abstract;
            if( item.Value=="Filename")
                hit_elems |= fisClient.fisHitAttributes.Filename;
            if( item.Value=="WordCount")
                hit_elems |= fisClient.fisHitAttributes.WordCount;
            if( item.Value=="Date")
                hit_elems |= fisClient.fisHitAttributes.Date;
            if( item.Value=="Indexed")
                hit_elems |= fisClient.fisHitAttributes.Indexed;
            if( item.Value=="Size")
                hit_elems |= fisClient.fisHitAttributes.Size;
            if( item.Value=="Snippet")
                hit_elems |= fisClient.fisHitAttributes.Snippet;
            if( item.Value=="PageWordCount")
                hit_elems |= fisClient.fisHitAttributes.PageWordCount;

    fisClient.fisSearchRequest req = new fisClient.fisSearchRequest(SearchText.Text);
    req.HitsFrom = from;
    req.HitsTo = to;
    req.HitElems = hit_elems;
    if( Subsets.Items.Count>0)
        req.Subsets = "";
        foreach( ListItem subsetitem in Subsets.Items)
            if( subsetitem.Selected)
                req.Subsets += subsetitem.Text+",";
    string SearchTitle = Title.Text;
    bool GotTitle = false;
    if( SearchTitle!=null)
        SearchTitle = SearchTitle.Trim();
        if( SearchTitle.Length>0)
        GotTitle = true;
    string SearchDescription = Description.Text;
    bool GotDescription = false;
    if( SearchDescription!=null)
        SearchDescription = SearchDescription.Trim();
        if( SearchDescription.Length>0)
            GotDescription = true;
    if( GotTitle || GotDescription)
        req.SearchFields = new ArrayList();
        if( GotTitle)
            req.SearchFields.Add(new fisClient.fisSearchField(Title.ID,SearchTitle));
        if( GotDescription)
            req.SearchFields.Add(new fisClient.fisSearchField(Description.ID,SearchDescription));

    fisClient.fisSearchResult result = fis.Search(req);

    HitDataGrid.CurrentPageIndex = 0;

    Session["fisSearchResult"] = result;
catch( Exception ex)
  All site Copyright © 1996-2009 PHD Computer Consultants Ltd, PHDCC   Privacy  

Last modified: 30 October 2005.