|Number of votes:||3|
Ever wondered how to add your own search result to the new search box in SiteCenter? If not I’ll give you a quick introduction anyway.
This is how you do it, first read the “Introduction to Gadgets” and follow the project setup instructions.
When that is done open the QuickChat project inside Visual Studio and add a new class called UsersSearchProvider.
Open the newly created file and implement the EPiServer.Shell.Search.Contracts.ISearchProvider on the class.
if you look at the code above you will see two properties, Area and Category.
The Area property is used for “spot-light” searching, this property maps directly to the different Module Areas that has been configured. E.g if you would like your search result to be prioritized when you are in Edit mode the Area should be CMS which is the module area name for the EPiServer CMS.
The Category property is used when the search results are displayed. In our case we want the the results to be categorized as Users because we are going to search for users.
To keep this sample as simple as possible I will just use the regular Membership.FindUsersByName and FindUsersByEmail to find all users inside EPiServer and then redirect the link result to Admin/EditUser.aspx, won’t be that nice but it does the trick.
This is how you do it:
You will need to add a reference to the MEF assembly (System.ComponentModel.Composition), It’s located in the PublicTemplates bin directory.
Look easy right? That’s why we use MEF to export dependencies from the modules inside SiteCenter.
This is what happens behind the hood:
Our search controller imports all classes that have been exported with the ISearchProvider contract and then filters these depending on the ISearchProvider.Area when performing a search.