Showing the Results

Showing the Results

Top  Previous  Next

The results of faceted navigation and search queries are often shown in a way specific to a solution. Also the most typical pattern for showing candidate topics (results) is by writing a custom ASPX page that includes the facet controls (the selectors and FSO). For this reason no standard web parts or controls are provided to show search results, however the approach is quite simple.

The search results can be shown with a repeater-style control or added via code that rebuilds the control hierarchy at the appropriate time.

To retrieve search results from an FSO use the method GetFacetedSearchResults. You can call this method at any time after the selectors are registered with the FSO. This methods returns a DataTable object containing one row for each candidate topic. By default, the FSO will return only the topic ID of hits, however the selectors will make their own requests for information (using the API provided by NetworkedPlanet.EnterpriseService.Web.Model.CommonValueSelectQueryTerms), such as :

1.Topic display name
2.First subject identifier

The FSO will ignore duplicates, so it is good practice to always explicitly request the query terms you wish to be returned in the candidate topic results set. This is done by implementing the NetworkedPlanet.EnterpriseService.Web.Model.IValueSelectQueryTermProvider interface. This mandates a single property: SelectQueryTerms which returns a collection of query terms that will be retrieved during the faceted search.

Commonly the EPiServer Page ID will be required (allowing the search page to display information about each page received). This can be done using the following code:

public IEnumerable<ValueSelectQueryTerm> SelectQueryTerms

{

  get

  {

    ValueSelectQueryTerm[] selectQueryTerms = new ValueSelectQueryTerm[1];

    selectQueryTerms[0] = new ValueSelectQueryTerm();

    selectQueryTerms[0].ColumnName = "pageid";

    selectQueryTerms[0].PropertyTypeID = EPiConfig.NP_TM_PageIdOccurrenceTypeId;

    return selectQueryTerms;

  }

}

This code creates a simple single-element array and inserts a new ValueSelectQueryTerm instance that selects the page ID occurrence. The ColumnName attribute nominates the name of the column in the data set that will be used, the PropertyTypeID specifies the TMCore topic ID of the occurrence type.

Any occurrence type may be specified in this way. If multiple occurrences are found of the same type then only the first one found will be returned. As this property is accessed several times by the FSO it is more efficient to build constant sets of ValueSelectQueryTerms. The data is never altered by the FSO so this is a safe thing to do.

This behaviour may be changed in future versions to return multiple rows for each occurrence found. Therefore when processing the rows in the returned data table you should check for duplicate topic IDs and process them accordingly.

/// <summary>

/// A set of value select query terms that are required by this search page.

/// </summary>

/// <remarks>

/// Initialized in the class constructor <see cref="Search()"/></remarks>

private static ValueSelectQueryTerm[] _selectQueryTerms;

/// <summary>

/// Class constructor that creates the set of query terms required and stores them in <see cref="_selectQueryTerms"/>.

/// </summary>

static SearchQueryTerms()

{

  _selectQueryTerms = new ValueSelectQueryTerm[2];

  _selectQueryTerms[0] = new ValueSelectQueryTerm();

  _selectQueryTerms[0].ColumnName = "pageid";

  _selectQueryTerms[0].PropertyTypeID = EPiConfig.NP_TM_PageIdOccurrenceTypeId;

  _selectQueryTerms[1] = new ValueSelectQueryTerm();

  _selectQueryTerms[1].ColumnName = "topic_name";

  _selectQueryTerms[1].PropertyTypeID = NetworkedPlanet.EnterpriseServiceClient.TopicMapIndex.SpecialIndexKeys.ID_TO_TOPIC_DISPLAY_NAME;

}

/// <summary>

/// Returns the set of query terms generated at class initialization and stored in <see cref="_selectQueryTerms"/>.

/// </summary>

public IEnumerable<ValueSelectQueryTerm> SelectQueryTerms

{

  get { return _selectQueryTerms; }

}

You can then register the query term provider during the OnLoad phase using:

this.Fso.RegisterQueryTermProvider(new SearchQueryTerms());

To simplify, make the ASPX code-beside file implement the IValueSelectQueryTermProvider interface and register using:

this.Fso.RegisterQueryTermProvider(this);

During the PreRender or DataBind phase (i.e. after event processing has taken place) you can then call the GetFacetedSearchResults() method and render the results of the search in any way you choose.