Due to the Search control's open API many parts of the functionality can be customized. In this example we modify SearchAgent which is used by SearchResult and apply a filter onto the results. Steps to use a 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 public class MySearchAgent : Keyoti.SearchEngine.Search.SearchAgent{ public MySearchAgent():base(){}public MySearchAgent(string key):base(key){}/// <summary>/// Applying a filter to results/// </summary>/// <param name="result">object to be added to results</param>/// <param name="results">the search result's collection</param>protected override void AddResultItemToResults(Keyoti.SearchEngine.Search.ResultItem result, ArrayList results){ if( result.URIString.IndexOf("default.aspx") == -1 ) //if we have default in the URI, dont add to resultsresults.Add(result); } } This example applies an arbitrary filter to the results, so that we never see a URL with default.aspx in the results. This filter could be for anything, including domain names and GET query strings. 4. In the Page_Load method use the MySearchAgent class private void Page_Load(object sender, System.EventArgs e){ this.SearchResult1.SearchAgent = new MySearchAgent();} In this way you can do pretty much anything to do results that appear, such as - Restricting access to certain users
- Showing results for certain file types
- Showing results from certain parts of the web-site
- Filtering based on the type of data applicable to the user
- etc...
(Note, this functionality is only available from v1.1). |