コード例 #1
0
        static async Task Run(CommandLineOptions options, CancellationToken cancellationToken = default)
        {
            var searchIndexConfig = new SearchIndexConfiguration
            {
                AzureCognitiveSearchServiceName = options.SearchServiceName,
                AzureCognitiveSearchKey         = options.SearchServiceKey,
                LearningProviderIndexName       = options.IndexName,
            };

            await ProcessEstablishmentsFile(options, searchIndexConfig, cancellationToken);
        }
コード例 #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");
        }
コード例 #3
0
        protected AcsSearchIndex(SearchIndexConfiguration configuration, string indexName, ILoggerWrapper logger)
        {
            _configuration = configuration;
            _indexName     = indexName;
            _logger        = logger;

            var properties  = typeof(TSearch).GetProperties();
            var definitions = new List <SearchFieldDefinition>();

            foreach (var property in properties)
            {
                definitions.Add(new SearchFieldDefinition
                {
                    Name         = property.Name,
                    DataType     = property.PropertyType,
                    IsSearchable = property.GetCustomAttribute(typeof(IsSearchableAttribute)) != null,
                    IsFilterable = property.GetCustomAttribute(typeof(IsFilterableAttribute)) != null,
                });
            }

            _fieldDefinitions = definitions.ToArray();
        }
コード例 #4
0
 public AcsLearningProviderSearchIndex(SearchIndexConfiguration configuration, ILoggerWrapper logger) 
     : base(configuration, configuration.LearningProviderIndexName, logger)
 {
 }
コード例 #5
0
 public AcsManagementGroupSearchIndex(SearchIndexConfiguration configuration, ILoggerWrapper logger)
     : base(configuration, configuration.ManagementGroupIndexName, logger)
 {
 }