This article is for v3 down, for v2010 please see the 'Filtering Results' example in the Help documentation.
It is possible to change the behavior of the SearchResult control so that it returns results according to your own filter, this is done by simply subclassing the SearchAgent class (the core search class which SearchResult uses to search the index).
The example below shows how to customize SearchAgent and use it in SearchResult. The subclass simply filters any pages with 'default.aspx' in their URL, however it can easily be adapted to filter anything.
Steps to add customized SearchAgent
1. Open code-behind for page holding the SearchResult control
2. Add a reference to the Keyoti.SearchEngine.Core assembly if one doesn't already exist
3. Create a new class, eg MySearchAgent
This example applies an arbitrary filter to the results
public class MySearchAgent : Keyoti.SearchEngine.Search.SearchAgent
{
public MySearchAgent(string key, Keyoti.SearchEngine.Configuration configuration) : base(key, configuration) { }
///
/// Applying filters to results
///
/// object to be added to results
/// the search result's collections
protected override void AddResultItemToResults(Keyoti.SearchEngine.Search.ResultItem result, Keyoti.SearchEngine.Utils.ResultItemList results)
{
if (result.UriString.IndexOf("default.aspx") == -1) //if we have default in the URI, dont add to results
results.Add(result);
}
}
4. In the Page_Load method use the MySearchAgent class
protected void Page_Load(object sender, EventArgs e)
{
string licenseKey = ".....";
this.SearchResult1.SearchAgent = new MySearchAgent(licenseKey, SearchResult1.Configuration);
}
In this example we filter out the "default.aspx" page so that it's not in the results. This also demonstrates how customization can be performed through subclassing. If you have any questions about this please email support@keyoti.com