Skip to content

Creating a Search Provider Component

Kyle edited this page Jan 10, 2016 · 2 revisions

The Rock Framework has a pretty easy way to hook new "search providers" into the main search window. Here are the high level steps:

  1. Create a class inherits from Rock.Search.SearchComponent which implements the Search method that takes a search string and returns any matching results in an IQuerable<string>.
  2. Create a search results block that handles displaying the results list when multiple matches are found or redirects to an appropriate 'view item' page (using the friendly route name) when only one item was found.
    1. If one does not yet exist, add a route to a your page with this block (e.g. "Person/Search/{SearchType}/{SearchTerm}")
    2. If one does not yet exist, add a route to a page that can view the item (e.g. "Person/{personId}")

When you add a new search component in your environment, Rock will automatically detect it and list it on the Search Services page (Administration->System Settings->Search Services) For now, it's in there where you will need to specify the Result URL route (e.g. such as Person/Search/name/{0}) and the Search Label. The Search Label will be displayed in the search box as a drop down option. Later on, if you're going to ship your component, you'll probably want to create a migration for it using the steps below.

Create a Migration

If you're creating a migration for a new search provider component, you will probably want to:

  1. Add the new component as a new Entity
  2. Add the appropriate attributes (Result URL, Search Label, Active, and Order)
  3. Add the appropriate default attributes values
    1. The Result URL value should be a route that includes the identifier as the {0} as in `"Person/Search/name/{0}"
    2. The Active value should be "True" otherwise it won't be activated in the system.
  4. Add your new BlockType, add a new search results page, and add an instance of your block to that page.
  5. Add a route to your search results page (e.g. Person/Search/name/{0}).

Prior to the v0.9 release you can see an example migration in 201307312305307_GroupSearchComponent.cs

Clone this wiki locally