public AzurSearchIndexerService(
            IOptions <AzureBlobOptions> azureBlobOptions,
            IOptions <SearchIndexerClientOptions> searchIndexerClientOptions
            )
        {
            _azureBlobOptions = azureBlobOptions;

            _indexingParameters = new();
            _indexingParameters.Configuration.Add("parsingMode", "json");

            _searchIndexerClient = new SearchIndexerClient(null, null);

            _azureBlobIndexer = new SearchIndexer(
                name: searchIndexerClientOptions.Value.IndexerName,
                dataSourceName: searchIndexerClientOptions.Value.DataSourceName,
                targetIndexName: searchIndexerClientOptions.Value.IndexName)
            {
                Parameters = _indexingParameters,
                Schedule   = new IndexingSchedule(TimeSpan.FromDays(1))
            };

            _azureBlobIndexer.FieldMappings.Add(
                new FieldMapping("Id")
            {
                TargetFieldName = "HotelId"
            });
            _searchIndexerDataContainer = new SearchIndexerDataContainer("hotel-rooms");
        }
Ejemplo n.º 2
0
 public async Task CreateDataSourceConnectionAsync(string dataSourceName, string containerName, string connectionString)
 {
     try
     {
         SearchIndexerDataContainer        searchIndexerDataContainer        = new SearchIndexerDataContainer(containerName);
         SearchIndexerDataSourceConnection searchIndexerDataSourceConnection = new SearchIndexerDataSourceConnection(
             dataSourceName,
             SearchIndexerDataSourceType.AzureBlob,
             connectionString,
             searchIndexerDataContainer);
         await _searchIndexerClient.CreateOrUpdateDataSourceConnectionAsync(searchIndexerDataSourceConnection);
     }
     catch (Exception)
     {
         throw new Exception("Cognitive Search APIs -> Failed To Create Data Source Connection!");
     }
 }