Search API form - display to a Repeater
[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 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
Programmer instructions
This page contains Visual Basic script code that is compiled when the page is loaded for the first time
- it does not use a .vb 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 Sub SearchButton_Click(sender As Object, e As EventArgs)
Try
Dim fis As New fisClient.SearchService(SearchAPIURL.SelectedItem.Text)
Dim req As New fisClient.fisSearchRequest(SearchText.Text)
Dim result As fisClient.fisSearchResult
result = fis.Search(req)
ShowResults(result)
Catch ex As Exception
JustShowMessage(ex.Message)
End Try
End Sub
Private Sub ShowResults(result As fisClient.fisSearchResult)
...
HitRepeater.DataSource = result.Hits
HitRepeater.DataBind()
End Sub
|
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.
|