public AzureSearchConcertSearchService(string searchServiceName, string adminKey, string concertsSqlDatabaseConnectionString) { this.searchServiceName = searchServiceName; this.searchServiceCredentials = new SearchCredentials(adminKey); this.concertsSqlDatabaseConnectionString = concertsSqlDatabaseConnectionString; this.concertsIndexClient = new SearchIndexClient(this.searchServiceName, IndexNameConcerts, this.searchServiceCredentials); }
private static SearchServiceClient CreateSearchServiceClient(string searchServiceName, string adminApiKey) { SearchCredentials creds = new SearchCredentials(adminApiKey); SearchServiceClient serviceClient = new SearchServiceClient(searchServiceName, creds); return(serviceClient); }
/// <summary> /// Instagram の投稿検索サービスを DI に登録します。 /// </summary> /// <param name="services"></param> /// <returns></returns> public static IServiceCollection AddInstagramSearch(this IServiceCollection services, CloudStorageAccount storageAccount, CognitiveSearchConfiguration search, WebProxyConfiguration?webProxy = null) { services.AddInstagram(webProxy); const string SearchServiceHttpClient = "KKTalking.Domain.Instagram.Search.SearchService.HttpClient"; services.AddHttpClient(SearchServiceHttpClient); services.TryAddSingleton(provider => { //--- Blob Client var blobClient = storageAccount.CreateCloudBlobClient(); //--- Azure Cognitive Search var factory = provider.GetRequiredService <IHttpClientFactory>(); var httpClient = factory.CreateClient(SearchServiceHttpClient); var credentials = new SearchCredentials(search.ApiKey); var serviceClient = new SearchServiceClient(credentials, httpClient, false) { SearchServiceName = search.ServiceName }; //--- サービス生成 return(ActivatorUtilities.CreateInstance <SearchService>(provider, blobClient, serviceClient)); }); return(services); }
public static IServiceCollection AddAzureSearch(this IServiceCollection services) { services.AddTransient <AzureSearchBatchIndexer>(); services.AddTransient <AzureSearchService>(); services.AddTransient <AzureSearchIndexer>(); services.AddTransient <IndexActionBuilder>(); services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <AzureSearchOptions> >().Value; var credentials = new SearchCredentials(options.ApiKey); return(new SearchServiceClient(options.AccountName, credentials)); }); services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <AzureSearchOptions> >().Value; var credentials = new SearchCredentials(options.ApiKey); return(new SearchIndexClient(options.AccountName, PackageDocument.IndexName, credentials)); }); return(services); }
public SearchApiController(AzureSearchSettings settings) { var credentials = new SearchCredentials(settings.ApiKey); var azureSearchClient = new SearchIndexClient(settings.ServiceName, settings.IndexName, credentials); SearchClient = new ReleaseNotesSearchClient(azureSearchClient); }
public AzSearchProductsRepository(IOptions <ConfigurationOptions> options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } _getConfiguration = () => options.Value; var config = _getConfiguration(); if (string.IsNullOrEmpty(config.QueryKey)) { throw new InvalidOperationException($"AzureSearch configuration value '{nameof(config.QueryKey)}' is missing"); } if (string.IsNullOrEmpty(config.ServiceName)) { throw new InvalidOperationException($"AzureSearch configuration value '{nameof(config.ServiceName)}' is missing"); } if (string.IsNullOrEmpty(config.ProductsIndexName)) { throw new InvalidOperationException($"AzureSearch configuration value '{nameof(config.ProductsIndexName)}' is missing"); } var searchApiCredentials = new SearchCredentials(config.QueryKey); _searchClient = new SearchIndexClient(searchApiCredentials) { SearchServiceName = config.ServiceName, IndexName = config.ProductsIndexName }; }
public async Task <ServiceResponse <List <BlogMetaData> > > GetLatestBlogGistsAsync() { ServiceResponse <List <BlogMetaData> > response = new ServiceResponse <List <BlogMetaData> >(); SearchParameters searchParameters = new SearchParameters(orderBy: new string[] { "LastModifiedDate desc" }, top: 3); SearchCredentials searchCredentials = new SearchCredentials(Environment.GetEnvironmentVariable(SEARCH_API_KEY_KEY)); try { using (SearchIndexClient client = new SearchIndexClient(SEARCH_SERVICE_NAME, SEARCH_INDEX_NAME, searchCredentials)) { List <BlogMetaData> metas = new List <BlogMetaData>(); DocumentSearchResult <Document> searchResult = await client.Documents.SearchAsync("*", searchParameters : searchParameters); foreach (SearchResult <Document> item in searchResult.Results) { string serializedDoc = JsonConvert.SerializeObject(item.Document); BlogMetaData metaData = JsonConvert.DeserializeObject <BlogMetaData>(serializedDoc); metas.Add(metaData); } response.Data = metas; } } catch (Exception ex) { response.Error = ex; } return(response); }
public SearchClientProvider(ILogger logger, string serviceName, string key) { _logger = logger; var searchCredentials = new SearchCredentials(key); _searchServiceClient = new SearchServiceClient(serviceName, searchCredentials); }
public SearchQuery(string typeId, SearchCredentials credentials, string relatedId, int pageSize) { PageSize = pageSize; RelatedId = relatedId; Credentials = new Dictionary <string, SearchCredentials> { { typeId, credentials } }; }
public AzureSearchClient(IOptions <Settings> options) { _settings = options.Value.AzureSearchSettings; var credentials = new SearchCredentials(_settings.ApiKey); _searchServiceClient = new SearchServiceClient(_settings.ServiceName, credentials); _searchIndexClient = GetSearchIndexClient(); }
public SearchClient(ISettings settings) { _settings = settings; var credentials = new SearchCredentials(settings.ApiKey); _searchServiceClient = new SearchServiceClient(settings.Name, credentials); _searchIndexClient = GetOrCreateSearchIndexClient(); }
public AzureSearchClient() { searchServiceName = Utility.GetResource <string>("SearchServiceName"); searchIndex = Utility.GetResource <string>("SearchIndexName"); searchApiKey = Utility.GetResource <string>("SearchApiKey"); searchCredentials = new SearchCredentials(searchApiKey); searchClient = new SearchServiceClient(searchServiceName, searchCredentials); }
public SearchService(AzureSearchConfiguration configuration) { _configuration = configuration; var azureCredentials = new SearchCredentials(_configuration.ApiKey); _searchAdminClient = new SearchServiceClient(_configuration.SearchServiceName, azureCredentials); _searchIndexClient = new SearchIndexClient(_configuration.SearchServiceName, _configuration.IndexName, azureCredentials); }
public ISearchServiceClient CreateSearchServiceClient() { var credentials = new SearchCredentials(_configuration["SearchServiceAdminApiKey"]); var httpClient = _httpClientFactory.CreateClient(); return(new SearchServiceClient(credentials, httpClient, false) { SearchServiceName = _configuration["SearchServiceName"], }); }
static SearchController() { var credentials = new SearchCredentials("422CE86A5BD07505CAB44F1CBAA12A02"); const string searchServiceName = "dm-bookstore"; playersSearchIndexClient = new SearchIndexClient(searchServiceName, "players", credentials); booksSearchIndexClient = new SearchIndexClient(searchServiceName, "books", credentials); studentsSearchIndexClient = new SearchIndexClient(searchServiceName, "students", credentials); cache = Redis.RedisConnection.GetDatabase(); }
public SearchClient() { string settingKey = Constant.AppSettingKey.SearchServiceName; string serviceName = AppSetting.GetValue(settingKey); settingKey = Constant.AppSettingKey.SearchAdminKey; string adminKey = AppSetting.GetValue(settingKey); SearchCredentials searchCredentials = new SearchCredentials(serviceName); SearchServiceClient searchClient = new SearchServiceClient(adminKey, searchCredentials); }
public StoreSearcher(string apiKey, string searchServiceName, string indexName) { var credentials = new SearchCredentials(apiKey); searchIndexClient = new SearchIndexClient(credentials, httpClient, false) { SearchServiceName = searchServiceName, IndexName = indexName, UseHttpGetForQueries = true }; }
private static void PostDocumentBatch(List <JobDocument> documents) { var credential = new SearchCredentials(AZURE_SEARCH_KEY); SearchServiceClient serviceClient = new SearchServiceClient(ACURE_SEARCH_SERVICE_NAME, credential); var indexClient = serviceClient.Indexes.GetClient("denvertechjobs"); var batch = IndexBatch.MergeOrUpload(documents); indexClient.Documents.Index(batch); }
/// <summary> /// Static constructor initializes the Azure Search context. /// </summary> static AzureSearch() { string apiKey = ConfigurationManager.AppSettings["SearchServiceApiKey"]; searchServiceName = ConfigurationManager.AppSettings["SearchServiceName"]; var credentials = new SearchCredentials(apiKey); serviceClient = new SearchServiceClient(searchServiceName, credentials); biographyIndex = new SearchIndexClient(searchServiceName, BIOGRAPHY_INDEX, credentials); storyIndex = new SearchIndexClient(searchServiceName, STORY_INDEX, credentials); }
public SearchClient() { string settingKey = Constants.AppSettingKey.AzureSearch; string[] accountCredentials = AppSetting.GetValue(settingKey, true); string accountName = accountCredentials[0]; string accountKey = accountCredentials[1]; SearchCredentials credentials = new SearchCredentials(accountKey); _search = new SearchServiceClient(accountName, credentials); }
public void ConstructorThrowsForBadParameters() { var creds = new SearchCredentials("abc"); var searchServiceName = "abc"; var handler = new HttpClientHandler(); var uri = new Uri("http://tempuri.org"); var invalidName = ")#%&/?''+&@)#*@%#"; Assert.Throws <ArgumentNullException>("credentials", () => new SearchServiceClient(credentials: null)); Assert.Throws <ArgumentNullException>( "searchServiceName", () => new SearchServiceClient(searchServiceName: null, credentials: creds)); Assert.Throws <ArgumentException>( "searchServiceName", () => new SearchServiceClient(searchServiceName: String.Empty, credentials: creds)); Assert.Throws <ArgumentException>( "searchServiceName", () => new SearchServiceClient(searchServiceName: invalidName, credentials: creds)); Assert.Throws <ArgumentNullException>( "credentials", () => new SearchServiceClient(searchServiceName, credentials: null)); Assert.Throws <ArgumentNullException>( "credentials", () => new SearchServiceClient(credentials: null, rootHandler: handler)); Assert.Throws <ArgumentNullException>(() => new SearchServiceClient(credentials: creds, rootHandler: null)); Assert.Throws <ArgumentNullException>( "baseUri", () => new SearchServiceClient(baseUri: null, credentials: creds)); Assert.Throws <ArgumentNullException>("credentials", () => new SearchServiceClient(uri, credentials: null)); Assert.Throws <ArgumentNullException>( "searchServiceName", () => new SearchServiceClient(searchServiceName: null, credentials: creds, rootHandler: handler)); Assert.Throws <ArgumentException>( "searchServiceName", () => new SearchServiceClient(searchServiceName: String.Empty, credentials: creds, rootHandler: handler)); Assert.Throws <ArgumentException>( "searchServiceName", () => new SearchServiceClient(searchServiceName: invalidName, credentials: creds, rootHandler: handler)); Assert.Throws <ArgumentNullException>( "credentials", () => new SearchServiceClient(searchServiceName, credentials: null, rootHandler: handler)); Assert.Throws <ArgumentNullException>( () => new SearchServiceClient(searchServiceName, creds, rootHandler: null)); Assert.Throws <ArgumentNullException>( "baseUri", () => new SearchServiceClient(baseUri: null, credentials: creds, rootHandler: handler)); Assert.Throws <ArgumentNullException>( "credentials", () => new SearchServiceClient(uri, credentials: null, rootHandler: handler)); Assert.Throws <ArgumentNullException>(() => new SearchServiceClient(uri, creds, rootHandler: null)); }
public async Task <ServiceResponse <List <BlogMetaData> > > GetRecommendedGistsAsync(string searchRequest) { if (string.IsNullOrWhiteSpace(searchRequest)) { return(await this.GetLatestBlogGistsAsync()); } string searchFullText = searchRequest .Replace(",", " ") .Split(' ') .Where(x => !string.IsNullOrWhiteSpace(x)) .Select(x => HttpUtility.UrlEncode(x)) .Aggregate((l, r) => $"{l} +{r}"); searchFullText = "+" + searchFullText; List <BlogMetaData> metas = new List <BlogMetaData>(); ServiceResponse <List <BlogMetaData> > response = new ServiceResponse <List <BlogMetaData> >(); SearchParameters searchParameters = new SearchParameters(orderBy: new string[] { "LastModifiedDate" }, queryType: QueryType.Full, searchMode: SearchMode.Any); SearchCredentials searchCredentials = new SearchCredentials(Environment.GetEnvironmentVariable(SEARCH_API_KEY_KEY)); try { using (SearchIndexClient client = new SearchIndexClient(SEARCH_SERVICE_NAME, SEARCH_INDEX_NAME, searchCredentials)) { DocumentSearchResult <Document> searchResult = await client.Documents.SearchAsync(searchFullText, searchParameters : searchParameters); foreach (SearchResult <Document> item in searchResult.Results) { string serializedDoc = JsonConvert.SerializeObject(item.Document); BlogMetaData metaData = JsonConvert.DeserializeObject <BlogMetaData>(serializedDoc); metas.Add(metaData); } } } catch (Exception ex) { var x = ex; } if (metas.Any()) { response.Data = metas; return(response); } return(await this.GetLatestBlogGistsAsync()); }
public static BaGetApplication AddAzureSearch(this BaGetApplication app) { app.Services.AddBaGetOptions <AzureSearchOptions>(nameof(BaGetOptions.Search)); app.Services.AddTransient <AzureSearchBatchIndexer>(); app.Services.AddTransient <AzureSearchService>(); app.Services.AddTransient <AzureSearchIndexer>(); app.Services.AddTransient <IndexActionBuilder>(); app.Services.TryAddTransient <ISearchService>(provider => provider.GetRequiredService <AzureSearchService>()); app.Services.TryAddTransient <ISearchIndexer>(provider => provider.GetRequiredService <AzureSearchIndexer>()); app.Services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <AzureSearchOptions> >().Value; var credentials = new SearchCredentials(options.ApiKey); return(new SearchServiceClient(options.AccountName, credentials)); }); app.Services.AddSingleton(provider => { var options = provider.GetRequiredService <IOptions <AzureSearchOptions> >().Value; var credentials = new SearchCredentials(options.ApiKey); return(new SearchIndexClient(options.AccountName, PackageDocument.IndexName, credentials)); }); app.Services.AddProvider <ISearchService>((provider, config) => { if (!config.HasSearchType("AzureSearch")) { return(null); } return(provider.GetRequiredService <AzureSearchService>()); }); app.Services.AddProvider <ISearchIndexer>((provider, config) => { if (!config.HasSearchType("AzureSearch")) { return(null); } return(provider.GetRequiredService <AzureSearchIndexer>()); }); return(app); }
public async Task DeleteSearchIndexes() { var key = _configuration["Search:ApiKey"]; var serviceName = _configuration["Search:ServiceName"]; var searchCredentials = new SearchCredentials(key); var searchServiceClient = new SearchServiceClient(serviceName, searchCredentials); var result = await searchServiceClient.Indexes.ListNamesAsync(); foreach (var name in result) { await searchServiceClient.Indexes.DeleteAsync(name); } }
public static SearchServiceClient GetSearchServiceClient( this SearchServiceFixture fixture, params DelegatingHandler[] handlers) { TestEnvironment currentEnvironment = TestEnvironmentFactory.GetTestEnvironment(); Uri baseUri = currentEnvironment.GetBaseSearchUri(fixture.SearchServiceName); currentEnvironment.BaseUri = baseUri; var credentials = new SearchCredentials(fixture.PrimaryApiKey); return(fixture.MockContext.GetServiceClientWithCredentials <SearchServiceClient>( currentEnvironment, credentials, false, handlers)); }
/// <summary> /// Creates, populates, and queries an index of mountains. /// </summary> /// <param name="endpoint">The Search service URI.</param> /// <param name="key">The admin key for the Search service.</param> /// <param name="query">Keywords to query. The default is "*".</param> /// <param name="wait">The number of seconds to wait for indexing, if created. The default is 2 seconds.</param> /// <returns></returns> private static async Task Main(Uri endpoint, string key, string query = "*", int wait = 2) { using var cts = new CancellationTokenSource(); Console.CancelKeyPress += (sender, args) => { cts.Cancel(); args.Cancel = true; }; var serviceName = endpoint.Host.Substring(0, endpoint.Host.IndexOf('.')); var credentials = new SearchCredentials(key); var serviceClient = new SearchServiceClient(serviceName, credentials); var indexClient = new SearchIndexClient(serviceName, Mountain.IndexName, credentials); if (!await serviceClient.Indexes.ExistsAsync(Mountain.IndexName, cancellationToken: cts.Token)) { var fields = FieldBuilder.BuildForType <Mountain>(); var index = new Index(Mountain.IndexName, fields); await serviceClient.Indexes.CreateOrUpdateAsync(index, cancellationToken : cts.Token); var batch = new IndexBatch <Mountain>(new [] { new IndexAction <Mountain>(new Mountain { Name = "Mount Rainier", Summit = GeographyPoint.Create(46.85287, -121.76044), }), }); await indexClient.Documents.IndexAsync(batch); await Task.Delay(TimeSpan.FromSeconds(wait)); } var results = await indexClient.Documents.SearchAsync <Mountain>(query, cancellationToken : cts.Token); foreach (var result in results.Results) { var mountain = result.Document; Console.WriteLine("https://www.bing.com/maps?cp={0}~{1}&sp=point.{0}_{1}_{2}", mountain.Summit.Latitude, mountain.Summit.Longitude, Uri.EscapeUriString(mountain.Name)); } }
internal async Task RunAsync() { var searchName = "searchdemos"; var cred = new SearchCredentials("[removed]"); var cl = new SearchServiceClient(searchName, cred); var ds = new DataSource("tenant-2", DataSourceType.AzureSql, new DataSourceCredentials("[removed]"), new DataContainer("dbo.vApplications"), null, new HighWaterMarkChangeDetectionPolicy("AppLastUpdate")); await cl.DataSources.CreateOrUpdateAsync(ds); var indexer = new Indexer("tenant-2", "tenant-2", "applications", null, null, new IndexingSchedule(TimeSpan.FromMinutes(5))); await cl.Indexers.CreateOrUpdateAsync(indexer); }
private static async Task RunProbeCommandAsync(SearchScorerSettings settings, HttpClient httpClient) { var credentials = new SearchCredentials(settings.AzureSearchApiKey); var azureSearchClient = new SearchServiceClient(settings.AzureSearchServiceName, credentials); var index = await azureSearchClient.GetNuGetSearchIndexAsync(settings); Console.WriteLine("Running {0} tests.", GetProbeTests(settings).Count()); foreach (var test in GetProbeTests(settings)) { var searchClient = new SearchClient(httpClient); var scoreEvaluator = new IREvalutation.RelevancyScoreEvaluator(searchClient); // Update the Azure Search index await azureSearchClient.UpdateNuGetSearchIndexAsync( settings, index, test.PackageIdWeight, test.TokenizedPackageIdWeight, test.TagsWeight, test.DownloadScoreBoost); // Score the new index. var report = await scoreEvaluator.GetCustomVariantReportAsync( settings, customVariantUrl : settings.TreatmentBaseUrl); // Save the result to the output path SearchProbesCsvWriter.Append( settings.ProbeResultsCsvPath, new SearchProbesRecord { PackageIdWeight = test.PackageIdWeight, TokenizedPackageIdWeight = test.TokenizedPackageIdWeight, TagsWeight = test.TagsWeight, DownloadScoreBoost = test.DownloadScoreBoost, CuratedSearchScore = report.CuratedSearchQueries.Score, ClientCuratedSearchScore = report.ClientCuratedSearchQueries.Score, FeedbackScore = report.FeedbackSearchQueries.Score }); } }
public async Task <DocumentSearchResult> Search([FromUri] string searchText) { var credentials = new SearchCredentials(AzureSearchConfig.SearchServiceApiKey); SearchIndexClient client = new SearchIndexClient(AzureSearchConfig.SearchServiceName , AzureSearchConfig.SearchIndexName, credentials); var callersGeoLocation = LocationHelper.GetCallerLocation(); var scoringParam = new ScoringParameter(AzureSearchConfig.GeoScoringParameterName, $"{callersGeoLocation.Longitude},{callersGeoLocation.Latitude}"); var parameters = new SearchParameters { SearchMode = SearchMode.All, Facets = AzureSearchConfig.SearchIndexFacets, ScoringProfile = AzureSearchConfig.ScoringProfileName, ScoringParameters = new[] { scoringParam } }; return(await client.Documents.SearchAsync(searchText, parameters)); }
private SearchIndexClient GetSearchIndexClientForKey( string indexName, string apiKey, params DelegatingHandler[] handlers) { TestEnvironment currentEnvironment = TestEnvironmentFactory.GetTestEnvironment(); Uri baseUri = new Uri( currentEnvironment.GetBaseSearchUri(SearchServiceName), String.Format("indexes('{0}')/", indexName)); currentEnvironment.BaseUri = baseUri; var credentials = new SearchCredentials(apiKey); return(MockContext.GetServiceClientWithCredentials <SearchIndexClient>( currentEnvironment, credentials, false, handlers)); }