Imports System Imports System.Drawing Imports System.Collections Imports Keyoti.SearchEngine.DataAccess Imports Keyoti.SearchEngine Namespace KeyotiSearchDemo_VB.Example1_Simple Public Class SearchResult Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Protected WithEvents SearchResult1 As Keyoti.SearchEngine.Web.SearchResult Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink 'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here InitializeMatchCounter() End Sub Private Sub SearchResult1_ItemCreated(ByVal sender As Object, ByVal e As Keyoti.SearchEngine.Web.SearchResultItemEventArgs) Handles SearchResult1.ItemCreated If TypeOf e.Item Is Keyoti.SearchEngine.Web.ResultItem Then Dim lbl As Label Dim resultData As Keyoti.SearchEngine.Search.ResultItem resultData = CType(e.Data, Keyoti.SearchEngine.Search.ResultItem) Dim numberOfMatches = Me.FindNumberOfMatches(resultData.URIString) lbl = CType(e.Item.FindControl("matchNumLabel"), Label) If Not lbl Is Nothing Then lbl.Text = numberOfMatches & " matches found." End If End If End Sub 'create a data access instance Dim da = New Keyoti.SearchEngine.DataAccess.XmlDataAccess Dim documentRecords As ArrayList Dim resultmap As OccurrenceMap Sub InitializeMatchCounter() 'setup the index directory if necessary Keyoti.SearchEngine.Configuration.xmlLocation = Me.SearchResult1.IndexDirectory 'take the first word Dim searchTerm As String = Me.SearchResult1.QueryExpression.Split(" ")(0) 'open the data access da.Open() 'retreive a map of the occurrences of searchTerm in all the documents in the index resultmap = da.GetMatchingDocumentsAndOccurrencesForWord(searchTerm, New ArrayList, New Hashtable, New Keyoti.SearchEngine.Search.SearchOptions) 'the map contains document IDs, but we want the actual DocumentRecords for those IDs so we can get the URL of the doc. documentRecords = da.GetDocuments(New ArrayList(resultmap.DocumentIDs)) End Sub Sub FinalizeMatchCounter() da.Close() End Sub Function FindNumberOfMatches(ByVal uri As String) As Int32 Dim numberOfOccurrences As Integer 'find document in result map Dim docRec As DocumentRecord For Each docRec In documentRecords 'the URL we might want If (docRec.URI.ToString().Equals(uri)) Then 'the number of matches found in document numberOfOccurrences = resultmap(docRec.DocumentID).Count End If Next docRec Return numberOfOccurrences End Function Private Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Unload FinalizeMatchCounter() End Sub End Class End Namespace