Example #1
0
        static void Init(CommandLineOptions options)
        {
            var searchIndex = new AcsLearningProviderSearchIndex(
                new SearchIndexConfiguration
            {
                AzureCognitiveSearchServiceName = options.AcsServiceName,
                AzureCognitiveSearchKey         = options.AcsKey,
                LearningProviderIndexName       = options.IndexName,
            },
                _logger);

            _searchManager = new LearningProviderSearchManager(searchIndex, _logger);
        }
Example #2
0
        static async Task ProcessEstablishmentsFile(CommandLineOptions options,
                                                    SearchIndexConfiguration searchIndexConfig, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(options.EstablishmentsFilePath))
            {
                return;
            }

            _logger.Info($"Reading establishments from {options.EstablishmentsFilePath}");
            Establishment[] establishments;
            using (var stream = new FileStream(options.EstablishmentsFilePath, FileMode.Open, FileAccess.Read))
                using (var reader = new StreamReader(stream))
                    using (var parser = new CsvFileParser <Establishment>(reader, new EstablishmentCsvMapping()))
                    {
                        establishments = parser.GetRecords();
                    }

            _logger.Info($"Found {establishments.Length} establishments");

            var index = new AcsLearningProviderSearchIndex(searchIndexConfig, _logger);

            // _logger.Info($"Creating index {options.IndexName}");
            // await index.CreateOrUpdateIndexAsync(cancellationToken);
            var skip = 0;
            var take = 50;

            while (skip < establishments.Length)
            {
                var batch = establishments
                            .Skip(skip)
                            .Take(take)
                            .Select(e => new LearningProviderSearchDocument
                {
                    Name             = e.Name,
                    SourceSystemName = "GIAS",
                    SourceSystemId   = e.Urn.ToString(),
                })
                            .ToArray();

                _logger.Info($"Uploading batch of documents {skip} - {skip + take} of {establishments.Length}");
                await index.UploadBatchAsync(batch, cancellationToken);

                skip += take;
            }
            _logger.Info("Finished uploading establishments to index");
        }