For my first blog post, i’ll present a module that I’ve published on the marketplace three months ago but never wrote an article about it.
When you create a website with Sitecore these days, you probably use renderings with Datasource items (Displaying a box with some information about a bike, some information about the company, … ) which is good and a Sitecore best practice !
But if you implemented a free text search using Sitecore Content Search, you probably encountered the problems of the datasource index items. Of course, those items are not indexed on the _content field of an item, because the default behavior is to index all the fields of an item in the _content field, but this is not really the default behavior that you are excepting when you do a fulltext search.
If there is a car description coming from a sublayout and you search for text which is this car description, in your search result, you want to see this page. Of course, to do that, you can use a Crawler (Like ForwardSearch or Coveo or maybe something else) but for those of you who really like the Sitecore Content Search (or already implemented it), Sitecore Datasource Indexer may resolve this problem.
Just get the package
and install it via the Sitecore Installation Wizard.
Note: If you are using MVC, i just released a new package for you – Datasource Indexer 2.0
After installing the Sitecore Datasource Indexer module, a new section will appear on your Sublayout (or View Rendering/ Controller Rendering /… ) which is called Datasource Indexer.
This is the place where you can configure what the Sublayout should do. You have some choices to do :
- Do we want to index the Sublayout ? Check or Uncheck the Checkbox Is Indexed
- Do we want to index all the fields of a Sublayout or only some of them ? You can select via the multilist field which fields to index
- Are you satisfied by the default indexing way, or do you want to add your own way to index a field (Maybe a calculated field, image field, document … ) ? Add your own class (Namespace, dll) (Described later)
Index Class field
What does the indexer do? He takes all the text fields of your Datasource item, concats the value into a single string, and adds it to the _content field.
So you can create your own class which must inherit from DatasourceComputed and implement the method string Run(Item item, RenderingSettings renderingSettings);
Index All Field and Indexed Item Field
Here you have the choice, maybe you want to index all the fields or just select some of the fields which should be indexed (For example, you show a Promotion with Image, and you don’t want to index the body of the item but the title and the abstract).
So you have to uncheck the Index All Fields and then select Title and Abstract.
The magic behind that works if you put a Datasource Template, if you don’t, the multilist field will not know which field to take.
Improvements or wrong code ?
If you see any error in the code, please tell me, i’ll try to fix it.
If you have an idea to improve the module also let me know