Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 2
0
        public void Initialize(ISearchIndex index, string indexName)
        {
            CloudSearchProviderSuggestionIndex searchProviderIndex = index as CloudSearchProviderSuggestionIndex;

            if (searchProviderIndex == null)
            {
                throw new NotSupportedException($"Only {typeof(CloudSearchProviderIndex).Name} is supported");
            }
            ConnectionStringSettings connectionString1 = ConfigurationManager.ConnectionStrings[searchProviderIndex.ConnectionStringName];

            if (connectionString1 == null)
            {
                throw new Sitecore.Exceptions.ConfigurationException($"The connection string for '{searchProviderIndex.ConnectionStringName}' is not provided.");
            }
            string[] strArray = connectionString1.ConnectionString.Split(new string[1] {
                "|"
            }, StringSplitOptions.RemoveEmptyEntries);
            IFactoryWrapper instance = _serviceCollectionClient.GetInstance <IFactoryWrapper>();

            foreach (string connectionString2 in strArray)
            {
                try
                {
                    ISearchService searchService = instance.CreateObject <ISearchService>("contentSearch/searchService", true);
                    (searchService as ISearchIndexInitializable)?.Initialize(searchProviderIndex);

                    var ssci = searchService as ISearchServiceConnectionInitializable;
                    if (ssci != null)
                    {
                        if (indexName != null)
                        {
                            ssci.Initialize(indexName, connectionString2);
                        }
                        else
                        {
                            ssci.Initialize(searchProviderIndex.SearchCloudIndexName, connectionString2);
                        }
                    }

                    if (searchService is ISearchServiceSchemaSyncNotification syncNotification)
                    {
                        syncNotification.SchemaSynced += new EventHandler(SearchServiceOnSchemaSynced);
                    }
                    _innerServices.Add(searchService);
                }
                catch (Exception ex)
                {
                    SearchLog.Log.Info("Search service connection string initialization failed.", ex);
                }
            }
            if (!_innerServices.Any())
            {
                throw new CloudSearchCompositeSearchServiceException("There is no search service available.");
            }
            Name   = string.Join(";", _innerServices.Select(x => x.Name));
            Schema = new CloudSearchIndexSchema(ExtractSchemaSnapshot());
        }