All options Search API form
[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.
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
Programmer instructions
The web form and script used in this example are standard ASP.NET Visual Basic, 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 Sub SearchButton_Click(sender As Object, e As EventArgs)
Try
Dim from as Integer, hitto as Integer
from = System.Int32.Parse(FromText.Text)
hitto = System.Int32.Parse(ToText.Text)
Dim fis As New fisClient.SearchService(SearchAPIURL.SelectedItem.Text)
Dim hit_elems As fisClient.fisHitAttributes
hit_elems = 0
For Each item As ListItem in Search2Elements.Items
If item.Selected Then
If item.Value="All" Then
hit_elems += fisClient.fisHitAttributes.All
End If
if item.Value="ResultNo" Then
hit_elems += fisClient.fisHitAttributes.ResultNo
End If
if item.Value="Title" Then
hit_elems += fisClient.fisHitAttributes.Title
End If
if item.Value="URL" Then
hit_elems += fisClient.fisHitAttributes.URL
End If
If item.Value="HighlightURL" Then
hit_elems += fisClient.fisHitAttributes.HighlightURL
End If
if item.Value="Abstract" Then
hit_elems += fisClient.fisHitAttributes.Abstract
End If
if item.Value="Filename" Then
hit_elems += fisClient.fisHitAttributes.Filename
End If
if item.Value="WordCount" Then
hit_elems += fisClient.fisHitAttributes.WordCount
End If
if item.Value="Date" Then
hit_elems += fisClient.fisHitAttributes.Date
End If
if item.Value="Indexed" Then
hit_elems += fisClient.fisHitAttributes.Indexed
End If
if item.Value="Size" Then
hit_elems += fisClient.fisHitAttributes.Size
End If
if item.Value="Snippet" Then
hit_elems += fisClient.fisHitAttributes.Snippet
End If
if item.Value="PageWordCount" Then
hit_elems += fisClient.fisHitAttributes.PageWordCount
End If
End If
Next
Dim req As New fisClient.fisSearchRequest(SearchText.Text)
req.HitsFrom = from
req.HitsTo = hitto
req.HitElems = hit_elems
If Subsets.Items.Count>0 Then
req.Subsets = ""
For Each subsetitem As ListItem in Subsets.Items
If subsetitem.Selected Then
req.Subsets += subsetitem.Text+","
End If
Next
End If
Dim SearchTitle As string
SearchTitle = Title.Text
Dim GotTitle As Boolean
GotTitle = false
If Not SearchTitle is Nothing Then
SearchTitle = SearchTitle.Trim()
If SearchTitle.Length>0 Then
GotTitle = true
End If
End If
Dim SearchDescription As String
SearchDescription = Description.Text
Dim GotDescription As Boolean
GotDescription = false
If Not SearchDescription is Nothing Then
SearchDescription = SearchDescription.Trim()
If SearchDescription.Length>0 Then
GotDescription = true
End If
End If
If GotTitle Or GotDescription Then
req.SearchFields = new ArrayList()
If GotTitle Then
req.SearchFields.Add(new fisClient.fisSearchField(Title.ID,SearchTitle))
End If
if GotDescription Then
req.SearchFields.Add(new fisClient.fisSearchField(Description.ID,SearchDescription))
End If
End If
Dim result As fisClient.fisSearchResult
HitDataGrid.CurrentPageIndex = 0
result = fis.Search(req)
ShowResults(result)
Session("fisSearchResult") = result
Catch ex As Exception
JustShowMessage(ex.Message)
End Try
End Sub
|
|