Knowledgebase Home Page  >  SearchUnit
Search the Knowledge Base
How to summarize number of results in other categories and link to them
https://keyoti.com/kb/Default.aspx?ToDo=view&questId=191&catId=54

Options

Print this page
Email this to a friend

In this scenario we demonstrate how to show the number of search results for a specific category along side the default search results summary, with a direct link to display the results for the category. Eg.

 

 

This example assumes that pages are either in the 'default' location category, or in the 'Support' location category.  When a search is done initially, without specifying a location to search within, pages in any location category are matched.  To read more about location categories and to see how to specify the category using meta tags please click here.

 

 

1. To find the number of pages in the Support section we do a search using the SearchAgent class, to see how many results there are. (for details see http://keyoti.com/products/search/dotNetWeb/Help2010/UserGuide/Examples/Programmatic%20Searching.htm)

 

 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not SearchResult1.QueryExpression Is Nothing Then

            Dim configuration As Configuration = SearchResult1.Configuration

            Dim licensekey As String = "…………………"

            Dim sa As SearchAgent = New SearchAgent(configuration)

            sa.LicenseKey = licensekey

            Dim results As Keyoti.SearchEngine.Search.SearchResult = sa.Search(SearchResult1.QueryExpression, New SearchOptions("Support", Nothing), 1, 100)

            If results.Count > 0 Then

                supportResultsMessage = results.Count & " in the Support section."

            Else

                supportResultsMessage = ""

            End If

        End If

    End Sub

 

 

the number of results under ‘Support’ can now be seen by looking at;

 

results.Count

 

 

2. The link to the 'Support' results page is added to the Header Template like this;

 

"searchpage.aspx?QueryExpr=" & SearchResult1.QueryExpression & "&loc=Support"

 

Note: The search results page in our example is called 'searchpage.aspx'.

 

 

Now the number of search results for the location category will be shown with a link to display the results page.

 

 

 

Complete codebehind page;

 

Imports Keyoti.SearchEngine.Search

Imports Keyoti.SearchEngine

 

Partial Class searchpage1

 

    Inherits System.Web.UI.Page

 

    Protected supportResultsMessage As String

 

 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

 

        If Not SearchResult1.QueryExpression Is Nothing Then

 

            Dim configuration As Configuration = SearchResult1.Configuration

            Dim licensekey As String = "............."

            Dim sa As SearchAgent = New SearchAgent(licensekey, configuration)

            sa.LicenseKey = licensekey

            Dim results As Keyoti.SearchEngine.Search.SearchResult = sa.Search(SearchResult1.QueryExpression, New SearchOptions("Support", Nothing), 1, 100)

            If results.Count > 0 Then

                supportResultsMessage = results.Count & " in the Support section."

            Else

                supportResultsMessage = ""

            End If

        End If

    End Sub

End Class

 

Header Template;

 

       <HeaderTemplate>

<div class='SEHeader' style='font-family: sans-serif, Verdana, Arial, Helvetica; font-size:9pt; background-color:#CCD7EC; border-top: 1px solid #95A9D3; border-left:1px solid  #95A9D3;border-right: 1px solid #95A9D3; padding:6px;'>Showing result page <b><%# Container.ResultsPage %></b>. There are <b><%# Container.NumberOfResults %></b> search results for &quot;<b>and there were <a href="<%="searchpage.aspx?QueryExpr=" & SearchResult1.QueryExpression & "&loc=Support" %>"><%=supportResultsMessage %></a><%# Container.IgnoredWordsMessage %></div><br /><br />

</HeaderTemplate>

If you have any questions, please email support.

 

 


Related Questions:

Attachments:

No attachments were found.