Knowledgebase Home Page  >  SearchUnit  >  Version 2 Articles
Search the Knowledge Base
How can I customize SearchResult, so that I control (filter) the results directly (for example)?
https://keyoti.com/kb/Default.aspx?ToDo=view&questId=72&catId=66

Options

Print this page
Email this to a friend
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 results

results.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
  1. Restricting access to certain users
  2. Showing results for certain file types
  3. Showing results from certain parts of the web-site
  4. Filtering based on the type of data applicable to the user
  5. etc...
 
(Note, this functionality is only available from v1.1).

Related Questions:

Attachments:

No attachments were found.