Sitecore7 Azure Search Service Provider (Preview/Draft)
Disclaimer: Please note this is not a finished article describing a search provider but instead work in progress/revision notes for learning.
Search within Sitecore client and on a website is made available through a search provider. Sitecore ships with a Lucene search provider and a Solr search provider is also available but the flexibility of the Sitecore platform allows you to integrate any search engine.
Microsoft has recently made the Azure Search Services available in a preview and I was interested to see how Azure Search Services could be integrated into Sitecore. To start with the goal was to produce a walking skeleton that provided search both in the Sitecore client and via Sitecore's api from Microsoft's Azure Search Service.
1. Read/Do - Adam Conn from Sitecore published a series of articles on how to create an xml search provider
2. Read/Do - Microsoft's Configure Search in the Azure Preview portal
The Index
In order to store data created during indexing and retrieve it when performing searches an index is required. To keep things simple, I manually created a Azure Search Service index with Fiddler following Microsoft's configuration guide. The index was defined using the following json:
{
"name"
:
"sitecoredemo"
,
"fields"
: [
{
"name"
:
"ItemId"
,
"type"
:
"Edm.String"
,
"key"
:
true
,
"searchable"
:
false
},
{
"name"
:
"Path"
,
"type"
:
"Edm.String"
},
{
"name"
:
"Key"
,
"type"
:
"Edm.String"
},
{
"name"
:
"Language"
,
"type"
:
"Edm.String"
},
{
"name"
:
"Version"
,
"type"
:
"Edm.String"
},
{
"name"
:
"Name"
,
"type"
:
"Edm.String"
,
"suggestions"
:
true
},
{
"name"
:
"DisplayName"
,
"type"
:
"Edm.String"
,
"suggestions"
:
true
},
{
"name"
:
"Content"
,
"type"
:
"Edm.String"
,
"filterable"
:
false
,
"sortable"
:
false
,
"facetable"
:
false
,
"suggestions"
:
true
},
{
"name"
:
"Uri"
,
"type"
:
"Edm.String"
},
{
"name"
:
"Tags"
,
"type"
:
"Collection(Edm.String)"
},
{
"name"
:
"TemplateId"
,
"type"
:
"Edm.String"
},
{
"name"
:
"TemplateName"
,
"type"
:
"Edm.String"
},
{
"name"
:
"Created"
,
"type"
:
"Edm.DateTimeOffset"
},
{
"name"
:
"CreatedBy"
,
"type"
:
"Edm.String"
},
{
"name"
:
"Updated"
,
"type"
:
"Edm.DateTimeOffset"
},
{
"name"
:
"UpdatedBy"
,
"type"
:
"Edm.String"
}
]
}
To confirm the index had been created correctly I requested details of the index via Fiddler
ISearchIndex
A class must be created to represent the index which implements Sitecores ISearchIndex interface
IProviderCrawler
Crawlers are used to discover content in Sitecore that should be indexed. Sitecore has a standard crawler but following the example from the Sitecore post I created my own.
IIndexOperations
A class implementing the interface IIndexOperations is used to create an object that has the responsibility of updating the crawler's index.
This class contains the logic for transforming the Sitecore content into a format suitable for pushing to the index.
IProviderUpdateContext
A class implementing the IProviderUpdateContext is required to create an object that uses the transformed content and indexes it.
ProviderIndexSearchConfiguration
In order to ensure the search provider is configurable with config files, a class inherriting from the ProviderIndexSearchConfiguration class is required.
Configuring Sitecore
Sitecore is configured to use the built in Lucene search engine. Before the Azure search provider is configured I need to disable Lucene. In the version of Sitecore I am using here, Sitecore.NET 7.2 (rev. 140526), there are seven configuration files in Sitecores App_Config/Include folder which need to be disabled or removed so they do not get loaded and interfere with the new provider or create an error for the Sitecore installation. To disable the configuration, simply change the file extension, for example Sitecore uses .example but I usually add a _disabled to the config extension so I can quickly see which configuration files I have disabled.
[web root]\App_Config\Include\Sitecore.ContentSearch.Lucene.DefaultIndexConfiguration.config_disabled
[web root]\App_Config\Include\Sitecore.ContentSearch.Lucene.Index.Core.config_disabled
[web root]\App_Config\Include\Sitecore.ContentSearch.Lucene.Index.Master.config_disabled
[web root]\App_Config\Include\Sitecore.ContentSearch.Lucene.Index.Web.config_disabled
[web root]\App_Config\Include\Sitecore.ContentSearch.Lucene.Indexes.Sharded.Core.config_disabled
[web root]\App_Config\Include\Sitecore.ContentSearch.Lucene.Indexes.Sharded.Master.config_disabled
[web root]\App_Config\Include\Sitecore.ContentSearch.Lucene.Indexes.Sharded.Web.config._disabled