Example #1
0
        public void Initialize(string connectionStringName)
        {
            _searchServiceClient          = factoryWrapper.CreateObject <SearchServiceClient>("contentSearch/searchServiceClient", true);
            _searchServiceClient.Observer = factoryWrapper.CreateObject <ISearchServiceAvailabilityManager>("contentSearch/availabilityManager", true) as IHttpMessageObserver;
            if (ConfigurationManager.ConnectionStrings[connectionStringName] == null)
            {
                return;
            }
            string connectionString1 = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;

            foreach (string connectionString2 in connectionString1.Split(new char[1] {
                '|'
            }))
            {
                try
                {
                    AzureSearchServiceClient assc = _searchServiceClient as AzureSearchServiceClient;
                    if (assc != null)
                    {
                        assc.Initialize(_indexName, connectionString2);
                    }
                    else
                    {
                        _searchServiceClient.Initialize(_indexName, connectionString2);
                    }

                    if (_searchServiceClient.IndexExists())
                    {
                        break;
                    }
                    _searchServiceClient.CreateIndex(new IndexDefinition(null, new IndexedField[4]
                    {
                        new IndexedField("key", "Edm.String", true, false, true, false, true, false),
                        new IndexedField("sitecorename", "Edm.String", false, false, true, false, true, false),
                        new IndexedField("indextype", "Edm.String", false, false, true, false, true, false),
                        new IndexedField("servicename", "Edm.String", false, false, true, false, true, false)
                    }));
                    break;
                }
                catch (Exception ex)
                {
                    SearchLog.Log.Error("Failed to initialize CloudSearchProviderIndexName", ex);
                }
            }
        }