示例#1
0
        public HomeController(IOptions <AppSecrets> optionsAccessor, ISearchRepository repository)
        {
            // Initialize search repository
            _repository = repository;

            // Secrets
            ApiKey      = optionsAccessor.Value.SearchApiKey;
            ServiceName = optionsAccessor.Value.SearchServiceName;

            // Search service client
            _serviceClient = _repository.CreateSearchServiceClient(ApiKey, ServiceName);

            // Delete if it exists.
            _repository.DeleteFlightsIndexIfExists(_serviceClient);

            // Create flight index
            _repository.CreateFlightsIndex(_serviceClient);

            ISearchIndexClient indexClient = _serviceClient.Indexes.GetClient("flights");

            // Adding flight data
            _repository.AddFlightData(indexClient);

            _indexClient = _repository.CreateSearchIndexClient(ApiKey, ServiceName);
        }