Deliver superior customer experiences with an AI-driven platform for creating and deploying cognitive chatbots
Deliver Awesome UI with the most complete toolboxes for .NET, Web and Mobile development
Automate UI, load and performance testing for web, desktop and mobile
A complete cloud platform for an app or your entire digital business
Detect and predict anomalies by automating machine learning to achieve higher asset uptime and maximized yield
Automate decision processes with a no-code business rules engine
Optimize data integration with high-performance connectivity
Connect to any cloud or on-premises data source using a standard interface
Build engaging multi-channel web and digital experiences with intuitive web content management
Personalize and optimize the customer experience across digital touchpoints
Build, protect and deploy apps across any platform and mobile device
The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
Feeling bad that we’ve let you wait so long for this series, though we’ve announced it back in the mid summer, I’ve decided to throw in a bonus track. You will not find this post on the roadmap, though it will eventually make it to the manual. In this post I will demonstrate how to implement search index for products module. This will give us an ability to offer the visitors of our site very narrow and specific search.
As always, this post is the part of a sequential series – so before starting to work with it please go to the introductory post and set up the project as it is explained there. You don’t need to go through all the stages of the series, but the first one is required.
NOTE: This project has been compiled with Sitefinity 3.5 SP 1, though it should work just fine on Sitefinity 3.5 fine as well.
Before we get into details, let’s take a moment and take a look at the high level overview of search in Sitefinity. As always, it is based on provider model, which will allow us to reuse great amount of functionality and implement only the parts specific to our products module. There are three things we will need to implement in order to get our search index up and running:
As you will see, all of these are rather simple to implement – and if you are familiar with the way we [Sitefinity team] implement controls – you’ll be done with this in less than an hour. Take a look at Figure 1 for the logical diagram of Sitefinity search index.
Figure 1: Diagram representing interplay between Sitefinity search service and products specific search classes
And in addition to that,we’ll need to provide the search service with the ProductsIndexProvider class.
So, that we have a better idea what are we talking about, let’s take a look how are the two controls used and how do they look like in Sitefinity. Take a look at Figure 2 to see how will ProductsIndexSettings control be used inside of Sitefinity administration area:
Figure 2: ProductsIndexSettings control
As you can see from the Figure 2, ProductsIndexSettings control is used by the end user in order to set up the index. We, as developers, can make this control any way we want and can demand all kinds of information from the end user that we may need to use later in provider. In this example, I am demanding the user to enter the Product Page url, so that in ProductsIndexProvider I can set the url of the each result item (e.g. user will set this to a page where ProductsView control is present).
Now, let’s move on to ProductsIndexView control. The purpose of this control to display the settings on already created index. Take a look at Figure 3 to see how this control looks like in Sitefinity:
Figure 3: ProductsIndexView control – visualizes the index settings
Admittedly, not the most complicated control, since we have only one setting for this control (Products Page).
The final part of our task will be develop ProductsIndexProvider. This will be much simpler than it seems, since we have based our module on Generic Content module and therefore can use a handy base class that comes with it.
Every module that will sport its own search index must implement IIndexingSupportModule interface. Since we will use some custom permission checking in this module, we’ll also make module secured (notice how we did not do this in the Permissions part, because Generic Content module controls did everything for us).
Securing the module will start in the products manager, so open the following file in your Telerik.Samples.Products project:
And start by adding a static constructor to it, like this:
next, add the static SecurityRoots property:
Now, what exactly are the “SecurityRoots”? Well, nothing more than permission objects for providers. In the future, this will make more sense as we start introducing more granular permission (per item and so on), but for now, it’s enough to know that we are basically registering every provider in the module as a permission object that can be secured.
Let’s head to the ProductsModule class, the main class of our module, and change the base class from WebModule to SecuredModule and implement the IIndexingSupportModule interface on it as well. The module class declaration should look like this:
Since we have changed the base class, and inherited from the SecuredModule abstract class, we’ll need to implement SecuredModule members. There are two only, and here is how you can implement them:
So, what we are doing here is providing the base SecuredModule class with the providers and associated GlobalPermission objects which base class will then use to secure the providers. The plumbing itself is not of our concern at the moment.
We’ve also implemented IIndexingSupportModule interface on the module and the interface mandates one member, so let’s add that one too:
Now, this function simply returns array of IServiceClientInfo objects implemented by this module. Yes, that means that we can actually have more than one IndexingService per module. We won’t complicate things here, and we’ll only return one IndexingServiceClientInfo object. Since we have not implemented ProducsIndexProvider, ProductsIndexSettingsControl and ProductsIndexViewControl yet, Visual Studio will probably try to warn you about this – but you can safely ignore it for now. We’ll come back to this later on.
The ProductsIndexProvider class is in charge of providing the search service with the data to index. Since products module is based on Generic Content module, we will reuse the ContentIndexProvider class and just modify few things which are different for our module – like provider name and settings. Add following file to your Telerik.Samples.Products project (at the root):
and paste following code into it:
There are couple of things worth noting here – first notice how we are overriding DefaultContentProvider property so that we can return the DefaultContentProvider for the Products module and not for Generic Content (in base class). Secondly, notice that we also override the Initialize method and initialize the values we need in our provider (productsPageUrl) from the settings. That’s all really there is to it – the rest, like getting the content and adding it to index, will be done for us by the base class.
As it was explained at the beginning of this post, IndexSettings controls are created so that we can collect settings from end users that we will use later in our IndexProvider class. If you go back to the last paragraph, you’ll see that on Initialize we are getting the ProductPageUrl setting from the settings object. In order to let user set this property, we need to create ProductsIndexSettingsControl class and provider user with the UI elements to enter the value of that setting.
In your Telerik.Samples.Products project create a following folder:
and add following file to this folder:
Paste following code in the the file:
The control looks like any other control we’ve implemented in Sitefinity so far, so I will not go over containers, templates and other things that have been explained many times throughout our developer’s manual. There are only two important things to note here. Control must implement ISettingsControl interface and this interface mandates following member:
Now, you remember how I said that ProductPageUrl setting will be populated by the ProductIndexSetting control? This is how it does it – everything else in this control is just UI programming.
Since, this is a control we’ll need a template for it. You can get the templates for search controls from the project that accompanies this article. Templates are located in:
folder. NOTE: Do not forget to copy the resource files from the App_LocalResources folder.
One last thing to do and we’re done. We need to implement ProductsIndexView control. To do so, add
file to Telerik.Samples.Products project in this folder:
Then paste the following code into it:
This control is even simpler than the previous one. All it has to do is display the saved settings for the provider.
This control also requires the template and you can get them from the project that accompanies this article. Templates are located in:
folder. NOTE: Do not forget to copy the resource files from the App_LocalResources folder.
You are done. Build your project, create few products, head to administration and create a new search index for products. Start indexing, place the SearchBox and SearchResults controls (available in the toolbox) somewhere on your pages and test the index out.
You can download the whole project from here.
If you have any questions, suggestions or run into problems – leave a comment.
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Copyright © 2018 Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.