private static bool CheckDuplication(IDBConnector dbConnector, Contest contest) { int sportTypeDuplicationRange = SportTypeTimeRangeDuplication.GetTimeRangeBySportType(contest.SportType); ISearchService searchService = new AzureSearchService(); SearchIndexParameters parameters = new SearchIndexParameters() { Filter = $"SportType eq '{contest.SportType}' and League eq '{contest.League}' " + $"and HomeTeam eq '{contest.HomeTeam}' and AwayTeam eq '{contest.AwayTeam}' " + $"and GameStartDate gt {contest.GameStartDate.AddHours(-sportTypeDuplicationRange).ToString("yyyy-MM-ddTHH:mm:ssZ")} " + $"and GameStartDate lt {contest.GameStartDate.AddHours(sportTypeDuplicationRange).ToString("yyyy-MM-ddTHH:mm:ssZ")}", Select = new[] { "id" } }; var results = searchService.RunQuery(parameters); if (results == null || (results != null && results.Results.Count == 0)) { return(false); } else { return(true); } }
public string SearchQuery(string index, string query) { var client = new AzureSearchService("dotnetconfsearch", "162ED4F1F498A366C066F1A1B1430F5D"); var result = client.RunQuery <AzureSearchModel>(index, new Microsoft.Azure.Search.Models.SearchParameters(), query, null).Result; return(JsonConvert.SerializeObject(result.Collection)); }
public void Search() { const string testIndexName = "content"; var searchService = new AzureSearchService(TestSettings.AzureSearchApiKey, TestSettings.AzureSearchUrlPrefix, TestSettings.AzureSearchApiVersion); // Prepare test env: create a new index // var result = searchService.CreateIndex(typeof(TestDocument), testIndexName); // Assert.IsTrue(result.IsSuccessStatusCode, "Failed to create index. " + result.StatusCode); try { // Prepare test env (2): insert a document var itemsToAdd = GetData(); searchService.AddContent(testIndexName, itemsToAdd); // Wait a bit, give AzureSearch some time to process Thread.Sleep(1000); // Test: Search var searchResult = searchService.Search<SearchResultItem>(testIndexName, "Azure Portal"); Assert.IsTrue(searchResult.value.Count > 0, "Failed to get search results!"); } finally { // Cleanup: delete the newly created index // searchService.DeleteIndex(testIndexName); } }
public void Search() { const string testIndexName = "content"; var searchService = new AzureSearchService(TestSettings.AzureSearchApiKey, TestSettings.AzureSearchUrlPrefix, TestSettings.AzureSearchApiVersion); // Prepare test env: create a new index // var result = searchService.CreateIndex(typeof(TestDocument), testIndexName); // Assert.IsTrue(result.IsSuccessStatusCode, "Failed to create index. " + result.StatusCode); try { // Prepare test env (2): insert a document var itemsToAdd = GetData(); searchService.AddContent(testIndexName, itemsToAdd); // Wait a bit, give AzureSearch some time to process Thread.Sleep(1000); // Test: Search var searchResult = searchService.Search <SearchResultItem>(testIndexName, "Azure Portal"); Assert.IsTrue(searchResult.value.Count > 0, "Failed to get search results!"); } finally { // Cleanup: delete the newly created index // searchService.DeleteIndex(testIndexName); } }
public void InsertDocumentInBulk() { const string testIndexName = "cx"; var searchService = new AzureSearchService(TestSettings.AzureSearchApiKey, TestSettings.AzureSearchUrlPrefix, TestSettings.AzureSearchApiVersion); // Prepare test env: create a new index var result = searchService.CreateIndex(typeof(TestDocument), testIndexName); Assert.IsTrue(result.IsSuccessStatusCode, "Failed to create index. " + result.StatusCode); try { var itemsToAdd = GetData(2); searchService.AddContent(testIndexName, itemsToAdd); // Wait a bit, give AzureSearch some time to process Thread.Sleep(1000); // Test: try to get document count var count = searchService.GetCount(testIndexName); Assert.IsTrue(count >= 1, "Unable to get item count. "); } finally { // Cleanup: delete the newly created index searchService.DeleteIndex(testIndexName); } }
public BooksController(IOptions <AzureSearchService> _searchOptions) { // Use this client handler to bypass ssl policy errors clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); }; _client = new HttpClient(clientHandler); searchOptions = _searchOptions.Value; }
/// <summary> /// Using Search Index engine, retrieve to results. /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <returns></returns> private List <Contest> GetContestList(DateTime from, DateTime to) { try { string formattedFromDate = from.ToString("yyyy-MM-ddTHH:mm:ssZ"); string formattedToDate = to.ToString("yyyy-MM-ddTHH:mm:ssZ"); ISearchService searchService = new AzureSearchService(); SearchIndexParameters parameters = new SearchIndexParameters() { Filter = $"GameStartDate gt {formattedFromDate} and GameStartDate lt {formattedToDate}", Select = new[] { "id", "GameStartDate", "CompetitionName", "HomeTeam", "AwayTeam", "SportType", "League" } }; var results = searchService.RunQuery(parameters); List <Contest> contests = new List <Contest>(); if (results != null && results.Results != null) { BuildResults(results, contests); } return(contests); } catch (Exception ex) { Console.WriteLine(ex); return(null); } }
public static void DoBlob() { // Imagenes desde un blob var imagesUrls = JsonConvert.DeserializeObject <Paths>(System.IO.File.ReadAllText("../../../Ficheros/Path.json")); var searchList = new List <AzureSearchModel>(); foreach (var url in imagesUrls.data) { var prediction = (AIServices.PredictionImageByUrl(url.Signature).FirstOrDefault()); if (prediction != null) { searchList.Add(new AzureSearchModel() { Tag = prediction.TagName, Scoring = prediction.Probability.ToString(), Url = url.Signature }); } } string searchServiceName = "dotnetconfsearch"; string adminApiKey = "162ED4F1F498A366C066F1A1B1430F5D"; //Create index var azureSearch = new AzureSearchService(searchServiceName, adminApiKey); var indexCreate = azureSearch.CreateIndexAsync <AzureSearchModel>("csindex", false, null).Result; // Group by year - One document by year var uploadDocument = azureSearch.UploadDocuments <AzureSearchModel>("csindex", searchList.ToArray()).Result; }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> private static void Main(string[] args) { Console.WriteLine("Options: \n1. Clear Search (ALL) \n2. Clear Search (Document) \n3. Add Document"); var value = Console.ReadLine(); var input = 0; if (!int.TryParse(value, out input)) { return; } searchService = new AzureSearchService(SearchServiceName, SearchServiceKey, ApplicationConstants.SearchIndex); switch (input) { case 1: ClearSearchAll(); break; case 2: Console.WriteLine("Enter Blog ID"); ClearSearchDocument(Console.ReadLine()); break; case 3: AddSearchDocument(); break; default: Console.WriteLine("Invalid Option"); break; } Console.WriteLine("Completed"); Console.ReadKey(); }
public async Task FilterLogsWithCriteria() { const string INDEX_NAME = "filter-logs-with-criteria"; //surround with "using" so that anything in a buffer is sent on dispose using (var azureSearchService = new AzureSearchService(AzureSearchServiceName, _azureSearchApiKey)) { try { // create an index - if an existing index is required: azureSearchService.GetIndexAsync() var index = await azureSearchService.CreateIndexForLogAsync(INDEX_NAME); var indexer = azureSearchService.CreateIndexerForLog( index.Name, documentsPerBatch: 1); var web3 = new Web3.Web3(BlockchainUrl); var blockchainProcessor = web3.Processing.Logs.CreateProcessor( action: log => indexer.IndexAsync(log), criteria: log => AddressUtil.Current.AreAddressesTheSame(log.Address, "0x9edcb9a9c4d34b5d6a082c86cb4f117a1394f831")); var cancellationTokenSource = new CancellationTokenSource(); await blockchainProcessor.ExecuteAsync(3146685, cancellationTokenSource.Token, 3146684); await Task.Delay(5000); // allow time to index Assert.Equal(2, await azureSearchService.CountDocumentsAsync(INDEX_NAME)); } finally { await azureSearchService.DeleteIndexAsync(INDEX_NAME); } } }
public async Task FilterLogs() { const string INDEX_NAME = "filter-logs"; //surround with "using" so that anything in a buffer is sent on dispose //to clear the buffer manually - searchIndexProcessor.EventIndexer.SubmitPendingItemsAsync() using (var azureSearchService = new AzureSearchService(AzureSearchServiceName, _azureSearchApiKey)) { try { // create an index - if an existing index is required: azureSearchService.GetIndexAsync() var index = await azureSearchService.CreateIndexForLogAsync(INDEX_NAME); var indexer = azureSearchService.CreateIndexerForLog(index.Name, documentsPerBatch: 1); var web3 = new Web3.Web3(BlockchainUrl); var blockchainProcessor = web3.Processing.Logs.CreateProcessor(log => indexer.IndexAsync(log)); var cancellationTokenSource = new CancellationTokenSource(); await blockchainProcessor.ExecuteAsync(3146685, cancellationTokenSource.Token, 3146684); await Task.Delay(5000); // allow time to index Assert.Equal(25, await azureSearchService.CountDocumentsAsync(INDEX_NAME)); } finally { await azureSearchService.DeleteIndexAsync(INDEX_NAME); } } }
public async Task OneEvent() { const string INDEX_NAME = "transfer-logs"; //surround with "using" so that anything in a buffer is sent on dispose using (var azureSearchService = new AzureSearchService(AzureSearchServiceName, _azureSearchApiKey)) { try { //setup var index = await azureSearchService.CreateIndexForEventLogAsync <TransferEvent_ERC20>(INDEX_NAME); var indexer = azureSearchService.CreateIndexerForEventLog <TransferEvent_ERC20>(index.Name, documentsPerBatch: 1); var web3 = new Web3.Web3(BlockchainUrl); var blockchainProcessor = web3.Processing.Logs.CreateProcessor <TransferEvent_ERC20>((transfer) => indexer.IndexAsync(transfer)); var cancellationTokenSource = new CancellationTokenSource(); //execute await blockchainProcessor.ExecuteAsync(3146694, cancellationTokenSource.Token, 3146684); //assert await Task.Delay(5000); // allow time to index Assert.Equal(19, await azureSearchService.CountDocumentsAsync(INDEX_NAME)); } finally { await azureSearchService.DeleteIndexAsync(INDEX_NAME); } } }
public void GetIndex() { const string testIndexName = "con94"; var searchService = new AzureSearchService(TestSettings.AzureSearchApiKey, TestSettings.AzureSearchUrlPrefix, TestSettings.AzureSearchApiVersion); // Prepare test env: create a new index var result = searchService.CreateIndex(typeof(TestDocument), testIndexName); Assert.IsTrue(result.IsSuccessStatusCode, "Failed to create index. " + result.StatusCode); // Test: try to get the newly created index and verify structure var indexDefinitionInJson = searchService.GetIndex(testIndexName); var jsonObject = JsonConvert.DeserializeObject(indexDefinitionInJson, typeof(ExpandoObject)); var data = jsonObject as IDictionary <string, object>; Assert.IsNotNull(data, "Failed to retrieve index information"); // A valid response will contain the following six properties: // @odata.context, name, fields, scoringProfile, defaultScoringProfile, corsOptions Assert.IsTrue(data.Keys.Count == 6, "Failed to retrieve index information"); // Cleanup: delete the newly created index searchService.DeleteIndex(testIndexName); }
static async Task Main(string[] args) { var searchServiceName = ConfigurationManager.AppSettings.Get("searchServiceName"); var searchServiceKey = ConfigurationManager.AppSettings.Get("searchServiceKey"); var searchServiceClient = new AzureSearchService(searchServiceName, searchServiceKey); //first we delete existing search structures if exist in order to create them later from zero await searchServiceClient.DeleteDataSourceAsync("jsonaudiosdatasource"); await searchServiceClient.DeleteIndexerAsync("netcoreconf2020-indexer"); await searchServiceClient.DeleteSkillsetAsync("jsonskillsets"); await searchServiceClient.DeleteIndexAsync("netcoreconf2020index"); //then we create our azure search structures var json = ReadJsonResource("jsonaudiosdatasource"); await searchServiceClient.CreateorUpdateDataSource("jsonaudiosdatasource", json); json = ReadJsonResource("netcoreconf2020index"); await searchServiceClient.CreateorUpdateAzureIndex("netcoreconf2020index", json); json = ReadJsonResource("jsonskillsets"); await searchServiceClient.CreateorUpdateSkillset("jsonskillsets", json); json = ReadJsonResource("netcoreconf2020indexer"); await searchServiceClient.CreateorUpdateIndexer("netcoreconf2020indexer", json); }
public async Task IndexingTransferFunctions() { using (var azureSearchService = new AzureSearchService(AzureSearchServiceName, _azureSearchApiKey)) { await azureSearchService.DeleteIndexAsync(AzureTransferIndexName); using (var azureFunctionMessageIndexer = await azureSearchService.GetOrCreateFunctionIndex <TransferFunction>(indexName: AzureTransferIndexName)) { var transferHandler = new FunctionIndexTransactionHandler <TransferFunction>(azureFunctionMessageIndexer); var web3 = new Web3.Web3("https://rinkeby.infura.io/v3/25e7b6dfc51040b3bfc0e47317d38f60"); var blockchainProxy = new BlockchainProxyService(web3); var handlers = new HandlerContainer { TransactionHandler = transferHandler }; var blockProcessor = BlockProcessorFactory.Create(blockchainProxy, handlers); var processingStrategy = new ProcessingStrategy(blockProcessor); var blockchainProcessor = new BlockchainProcessor(processingStrategy); var blockRange = new BlockRange(3146684, 3146694); await blockchainProcessor.ProcessAsync(blockRange); await Task.Delay(TimeSpan.FromSeconds(5)); //ensure we have written the expected docs to the index Assert.Equal(3, await azureFunctionMessageIndexer.DocumentCountAsync()); } await azureSearchService.DeleteIndexAsync(AzureTransferIndexName); } }
private async Task SearchFaqAsync(IDialogContext context, IAwaitable <object> result) { var activity = await result as Activity; var searchText = activity.Text; // 空白文字は OR検索に変更 if (searchText.Contains(" ") || searchText.Contains(" ")) { searchText = activity.Text.Replace(" ", "|").Replace(" ", "|"); } // 全文検索 (search=searchText) AzureSearchService searchService = new AzureSearchService(); SearchResult searchResult = await searchService.Search(searchText); context.Done(searchResult); // カテゴリー内FAQ検索 (facet=Category1) //FacetResult facetResult = await searchService.FetchFacets(); //if (facetResult.Facets.Category1.Length > 0) //{ // await context.PostAsync($"Category1 にある FAQ の数は" + // facetResult.Facets.Category1.Length.ToString() + "個です"); //} }
public void DeleteDocument() { const string testIndexName = "contents"; var searchService = new AzureSearchService(TestSettings.AzureSearchApiKey, TestSettings.AzureSearchUrlPrefix, TestSettings.AzureSearchApiVersion); // Prepare test env: create a new index var result = searchService.CreateIndex(typeof(TestDocument), testIndexName); Assert.IsTrue(result.IsSuccessStatusCode, "Failed to create index. " + result.StatusCode); try { // Prepare test env (2): insert a document var itemsToAdd = GetData(); searchService.AddContent(testIndexName, itemsToAdd); // Wait a bit, give AzureSearch some time to process Thread.Sleep(1000); // Test: Delete var count = searchService.GetCount(testIndexName); Assert.IsTrue(count >= 1, "Unable to get item count. "); } finally { // Cleanup: delete the newly created index searchService.DeleteIndex(testIndexName); } }
private static AzureSearchService CreateAzureSearchServiceAndMarkForDisposal(this ILogsProcessorBuilder processorBuilder, string searchServiceName, string apiKey) { var searchService = new AzureSearchService(searchServiceName, apiKey); processorBuilder.DisposeOnProcessorDisposing(searchService); return(searchService); }
/// <summary> /// Initializes a new instance of the <see cref="MetaWeblogHandler" /> class. /// </summary> /// <exception cref="BlogSystemException">unable to create container</exception> /// <exception cref="RahulRai.Websites.Utilities.Common.Exceptions.BlogSystemException">unable to create container</exception> public MetaWeblogHandler() { TraceUtility.LogInformation("Metawebloghander started initializing"); try { if (null == this.metaweblogTable) { this.metaweblogTable = new AzureTableStorageService <TableBlogEntity>( this.connectionString, this.blogTableName, AzureTableStorageAssist.ConvertEntityToDynamicTableEntity, AzureTableStorageAssist.ConvertDynamicEntityToEntity <TableBlogEntity>); this.metaweblogTable.CreateStorageObjectAndSetExecutionContext(); TraceUtility.LogInformation("Blog table created"); } if (null == this.mediaStorageService) { this.mediaStorageService = new BlobStorageService(this.connectionString); if (FileOperationStatus.FolderCreated != this.mediaStorageService.CreateContainer( this.blogResourceContainerName, VisibilityType.FilesVisibleToAll)) { TraceUtility.LogWarning("Resource container could not be created"); throw new BlogSystemException("unable to create container"); } } if (null == this.azureQueueService) { this.azureQueueService = new AzureQueueService(this.connectionString, this.queueName); } if (null != this.searchService) { return; } this.searchService = new AzureSearchService( this.searchServiceName, this.searchServiceKey, ApplicationConstants.SearchIndex); TraceUtility.LogInformation("Search service initialized"); } catch (BlogSystemException) { //// This is a custom exception. Throw it again. throw; } catch (Exception exception) { TraceUtility.LogError(exception); throw new BlogSystemException("failed to initialize"); } }
public async Task OneEventWithMapping() { const string INDEX_NAME = "one-event-with-mapping"; using (var azureSearchService = new AzureSearchService(AzureSearchServiceName, _azureSearchApiKey)) { try { //setup //create a definition of an index - //it describes the fields, key and data types //at this stage - it is only an in-memory schema var index = CreateAzureIndexDefinition(INDEX_NAME); //create the index in azure index = await azureSearchService.CreateIndexAsync(index); // create a processor for a specific event and map to a custom DTO for the search var indexer = azureSearchService.CreateIndexerForEventLog <TransferEvent_ERC20, CustomTransferSearchDocumentDto>( index.Name, (e) => new CustomTransferSearchDocumentDto { From = e.Event.From, To = e.Event.To, Value = e.Event.Value.ToString(), BlockNumber = e.Log.BlockNumber.Value.ToString(), TxHash = e.Log.TransactionHash, LogAddress = e.Log.Address, LogIndex = (int)e.Log.LogIndex.Value, DocumentKey = $"{e.Log.TransactionHash}_{e.Log.LogIndex.Value}" }, documentsPerBatch: 1); var web3 = new Web3.Web3(BlockchainUrl); var blockchainProcessor = web3.Processing.Logs.CreateProcessor <TransferEvent_ERC20>( transfer => indexer.IndexAsync(transfer)); var cancellationTokenSource = new CancellationTokenSource(); //execute await blockchainProcessor.ExecuteAsync(3146694, cancellationTokenSource.Token, 3146684); //assert await Task.Delay(5000); // allow time to index Assert.Equal(19, await azureSearchService.CountDocumentsAsync(INDEX_NAME)); } finally { await azureSearchService.DeleteIndexAsync(INDEX_NAME); } } }
public KnowledgeBot(IConfiguration config) { this.configuration = config; indexClient = AzureSearchService.CreateSearchIndexClient(configuration["SearchServiceName"], configuration["SearchDialogsIndexName"], configuration["SearchServiceQueryApiKey"]); qnaClient = new QnAMaker(new QnAMakerEndpoint() { EndpointKey = configuration["QnAKey"], Host = configuration["QnAEndpoint"], KnowledgeBaseId = configuration["QnAKnowledgeBaseId"] }); translatorClient = new Translator(configuration["TranslationAPI"]); botLUISModel = new LuisModel(configuration["LUISAppId"], configuration["LUISApiKey"], new Uri(configuration["LUISEndpointUri"])); }
public void CreateIndex() { const string testIndexName = "con92"; var searchService = new AzureSearchService(TestSettings.AzureSearchApiKey, TestSettings.AzureSearchUrlPrefix, TestSettings.AzureSearchApiVersion); // Test: verify index creation process var result = searchService.CreateIndex(typeof(TestDocument), testIndexName); Assert.IsTrue(result.IsSuccessStatusCode, "Failed to create index. " + result.StatusCode); // Cleanup: delete the newly created index searchService.DeleteIndex(testIndexName); }
public async Task AzureSearch(string term) { if (!string.IsNullOrWhiteSpace(term)) { var results = await AzureSearchService.Search(term); AzureSearchResults = new ObservableCollection <Value>(results.Value); } else { AzureSearchResults = new ObservableCollection <Value>(); } }
public void CreateIndex() { const string testIndexName = "con92"; var searchService = new AzureSearchService(TestSettings.AzureSearchApiKey, TestSettings.AzureSearchUrlPrefix, TestSettings.AzureSearchApiVersion); // Test: verify index creation process var result = searchService.CreateIndex(typeof(TestDocument), testIndexName); Assert.IsTrue(result.IsSuccessStatusCode, "Failed to create index. " + result.StatusCode); // Cleanup: delete the newly created index searchService.DeleteIndex(testIndexName); }
public async Task AnEventAndItsTransaction() { const string EVENT_INDEX_NAME = "transfer-logs-related"; const string FUNCTION_INDEX_NAME = "related-transfer-functions"; //surround with "using" so that anything in a buffer is sent on dispose using (var azureSearchService = new AzureSearchService(AzureSearchServiceName, _azureSearchApiKey)) { try { //setup var transferEventIndex = await azureSearchService.CreateIndexForEventLogAsync <TransferEvent_ERC20>(EVENT_INDEX_NAME); var transferFunctionIndex = await azureSearchService.CreateIndexForFunctionMessageAsync <TransferFunction>(FUNCTION_INDEX_NAME); var transferIndexer = azureSearchService.CreateIndexerForEventLog <TransferEvent_ERC20>(transferEventIndex.Name); var transferFunctionIndexer = azureSearchService.CreateIndexerForFunctionMessage <TransferFunction>(transferFunctionIndex.Name); //this handler ensures the transaction is a Transfer and invokes the indexer var transferFunctionProcessorHandler = transferFunctionIndexer.CreateProcessorHandler(); var web3 = new Web3.Web3(BlockchainUrl); var blockchainProcessor = web3.Processing.Logs.CreateProcessor <TransferEvent_ERC20>(async(log) => { await transferIndexer.IndexAsync(log); var transactionWithReceipt = await web3.Eth.GetTransactionReceiptVO(log.Log.BlockNumber, log.Log.TransactionHash).ConfigureAwait(false); await transferFunctionProcessorHandler.ExecuteAsync(transactionWithReceipt); }); var cancellationTokenSource = new CancellationTokenSource(); //execute await blockchainProcessor.ExecuteAsync(3146694, cancellationTokenSource.Token, 3146684); //assert await Task.Delay(5000); // allow time to index Assert.Equal(19, await azureSearchService.CountDocumentsAsync(EVENT_INDEX_NAME)); Assert.Equal(3, await azureSearchService.CountDocumentsAsync(FUNCTION_INDEX_NAME)); } finally { await azureSearchService.DeleteIndexAsync(EVENT_INDEX_NAME); await azureSearchService.DeleteIndexAsync(FUNCTION_INDEX_NAME); } } }
private async Task SendSearchToBackchannel(IDialogContext context, IMessageActivity activity, string textSearch) { var searchService = new AzureSearchService(); var searchResult = await searchService.Search(textSearch); if (searchResult != null && searchResult.Value.Length != 0) { var reply = ((Activity)activity).CreateReply(); reply.Type = ActivityTypes.Event; reply.Name = "searchResults"; reply.Value = searchResult.Value; await context.PostAsync(reply); } }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); // parse query parameter dynamic data = await req.Content.ReadAsAsync <object>(); log.Info("Data:" + data.Lista + data.Id + data.site); // Set name to query string or body data string lista = data?.Lista; string id = data?.Id; string site = data?.site; if (lista != null && id != null) { log.Info("Lista " + lista + " id " + id + " site " + site); SPOService spoM = new SPOService(site); var image = spoM.GetPhotoInfo(lista, id); CelebrityService cService = new CelebrityService(); var content = cService.MakeAnalysisCelebrity(image); var celebrityName = cService.GetCelebrity(content.celebrity); log.Info("Obteniendo el celebrity"); var azureSearch = new AzureSearchService(); var indexCreate = azureSearch.CreateIndexAsync <AzureSearchModel>("newsindex", false, null).Result; var contentIndex = new AzureSearchModel() { IdSharepoint = id, Name = celebrityName, Tags = content.tags, Id = id }; var uploadDocument = azureSearch.UploadDocuments <AzureSearchModel>("newsindex", new List <AzureSearchModel>() { contentIndex }.ToArray()); log.Info("Creado el search"); spoM.SetResultNews(lista, id, JsonConvert.SerializeObject(content.tags)); return(req.CreateResponse(HttpStatusCode.OK, "Noticia categorizada")); } else { return(req.CreateResponse(HttpStatusCode.BadRequest, "Faltan parametros")); } }
public async Task UsingTheIndividualComponents() { TransferMetadata.CurrentChainUrl = BlockchainUrl; var web3 = new Web3.Web3(BlockchainUrl); using (var azureSearchService = new AzureSearchService(AzureSearchServiceName, _azureSearchApiKey)) { await azureSearchService.DeleteIndexAsync(AzureTransferIndexName); try { using (var transferIndexer = await azureSearchService.CreateEventIndexer <TransferEvent_ERC20>(AzureTransferIndexName)) { using (var transferProcessor = new EventIndexProcessor <TransferEvent_ERC20>(transferIndexer)) { var logProcessor = new BlockRangeLogsProcessor( web3.Eth.Filters.GetLogs, new ILogProcessor[] { transferProcessor }); var progressRepository = new JsonBlockProgressRepository(CreateJsonFileToHoldProgress()); var progressService = new StaticBlockRangeProgressService( 3146684, 3146694, progressRepository); var batchProcessorService = new LogsProcessor( logProcessor, progressService, maxNumberOfBlocksPerBatch: 2); BlockRange?lastBlockRangeProcessed; do { lastBlockRangeProcessed = await batchProcessorService.ProcessOnceAsync(); } while (lastBlockRangeProcessed != null); Assert.Equal(19, transferIndexer.Indexed); } } } finally { await azureSearchService.DeleteIndexAsync(AzureTransferIndexName); } } }
private async Task useAzureSearch(ITurnContext context) { // Configure the parementers for the search through the Azure Search Service SearchParameters parameters = new SearchParameters() { SearchMode = SearchMode.Any, Select = new[] { "content", "language", "metadata_storage_path", "keyphrases" } }; // Get the documents through Azure search using the AzureSearchService service class DocumentSearchResult <SearchDocument> searchResults = AzureSearchService.RunQuery(context.Activity.Text, indexClient, parameters); if (searchResults != null && searchResults.Results.Count > 0) { // Output information on the first (most relevant) document) await context.SendActivity(await translatorClient.Translate($"Ich habe {searchResults.Results.Count} Dokumente zu diesem Thema gefunden. Das ist der Anfang der Dokumentes.", "de", userNativeLanguage)); await context.SendActivity(searchResults.Results[0].Document.content.Substring(0, 400)); string url = AzureSearchService.DecodeUrl(searchResults.Results[0].Document.metadata_storage_path); await context.SendActivity(await translatorClient.Translate($"Hier kannst du das Dokument herunterladen: {url}", "de", userNativeLanguage)); // If there are more results, just display some links. if (searchResults.Results.Count > 1) { string moreDocs = String.Empty; moreDocs += await translatorClient.Translate("Weitere passende Dokumente:", "de", userNativeLanguage); moreDocs += "\n"; // Display up to five more links for (int i = 1; i < searchResults.Results.Count; i++) { moreDocs += AzureSearchService.DecodeUrl(searchResults.Results[i].Document.metadata_storage_path) + "\n"; if (i > 5) { break; } } await context.SendActivity(moreDocs); } } else { await context.SendActivity(await translatorClient.Translate("Ich habe zu diesem Suchbegriff leider kein Dokument gefunden. 😥", "de", userNativeLanguage)); } }
public async Task ExploreCategory(IDialogContext context, LuisResult result) { EntityRecommendation categoryEntityRecommendation; result.TryFindEntity("category", out categoryEntityRecommendation); var category = ((Newtonsoft.Json.Linq.JArray)categoryEntityRecommendation? .Resolution["values"])?[0]?.ToString(); var originalText = result.Query; AzureSearchService searchService = new AzureSearchService(); if (string.IsNullOrWhiteSpace(category)) { FacetResult facetResult = await searchService.FetchFacets(); if (facetResult.Facets.Category.Length != 0) { List <string> categories = new List <string>(); foreach (Category searchedCategory in facetResult.Facets.Category) { categories.Add($"{searchedCategory.Value}({ searchedCategory.Count})"); } PromptDialog.Choice(context, this.AfterMenuSelection, categories, "お探しの答えがKBの中にあるか確認しましょう。" + "どのカテゴリーをご覧になりますか?"); } } else { SearchResult searchResult = await searchService.SearchByCategory(category); if (searchResult.Value.Length != 0) { await context.PostAsync($"{category} には以下のようなKBが" + "見つかりました。" + "**More details** をクリックすると詳細が表示されます。"); } await CardUtil.ShowSearchResults(context, searchResult, $"KBから{category} カテゴリーの記事は見つかりませんでした。"); context.Done <object>(null); } }
public void DeleteIndex() { const string testIndexName = "con94"; var searchService = new AzureSearchService(TestSettings.AzureSearchApiKey, TestSettings.AzureSearchUrlPrefix, TestSettings.AzureSearchApiVersion); // Prepare test env // 1. create a new index var result = searchService.CreateIndex(typeof(TestDocument), testIndexName); Assert.IsTrue(result.IsSuccessStatusCode, "Failed to create index. " + result.StatusCode); // Test: try to delete the newly created index var deleteResult = searchService.DeleteIndex(testIndexName); Assert.IsTrue(result.IsSuccessStatusCode, "Failed to delete index. " + result.StatusCode); }
private static async Task QueryOnAzureSearch(ITurnContext turnContext) { SearchParameters parameters = new SearchParameters() { SearchMode = SearchMode.Any, Top = 1, Filter = null, }; // Get the documents through Azure search using the AzureSearchService service class DocumentSearchResult <Squad> searchResults = AzureSearchService.RunQuery(turnContext.Activity.Text, indexClient, parameters); foreach (var res in searchResults.Results) { await turnContext.SendActivityAsync($"Squad Paragraph: {res.Document.paragraph_text}"); } }
public void DeleteIndex() { const string testIndexName = "con94"; var searchService = new AzureSearchService(TestSettings.AzureSearchApiKey, TestSettings.AzureSearchUrlPrefix, TestSettings.AzureSearchApiVersion); // Prepare test env // 1. create a new index var result = searchService.CreateIndex(typeof(TestDocument), testIndexName); Assert.IsTrue(result.IsSuccessStatusCode, "Failed to create index. " + result.StatusCode); // Test: try to delete the newly created index var deleteResult = searchService.DeleteIndex(testIndexName); Assert.IsTrue(result.IsSuccessStatusCode, "Failed to delete index. " + result.StatusCode); }
public virtual async Task AfterMenuSelection(IDialogContext context, IAwaitable <string> result) { this.category = await result; this.category = System.Text.RegularExpressions.Regex.Replace(this.category, @"\([^)]*\)", string.Empty); AzureSearchService searchService = new AzureSearchService(); SearchResult searchResult = await searchService.SearchByCategory(this.category); await context.PostAsync($"{this.category}には以下のようなKBが" + "見つかりました。" + "**More details** をクリックすると詳細が表示されます。"); await CardUtil.ShowSearchResults(context, searchResult, $"KB から" + "{this.category} カテゴリーの記事は見つかりませんでした。"); context.Done <object>(null); }
public void GetIndex() { const string testIndexName = "con94"; var searchService = new AzureSearchService(TestSettings.AzureSearchApiKey, TestSettings.AzureSearchUrlPrefix, TestSettings.AzureSearchApiVersion); // Prepare test env: create a new index var result = searchService.CreateIndex(typeof(TestDocument), testIndexName); Assert.IsTrue(result.IsSuccessStatusCode, "Failed to create index. " + result.StatusCode); // Test: try to get the newly created index and verify structure var indexDefinitionInJson = searchService.GetIndex(testIndexName); var jsonObject = JsonConvert.DeserializeObject(indexDefinitionInJson, typeof(ExpandoObject)); var data = jsonObject as IDictionary<string, object>; Assert.IsNotNull(data, "Failed to retrieve index information"); // A valid response will contain the following six properties: // @odata.context, name, fields, scoringProfile, defaultScoringProfile, corsOptions Assert.IsTrue(data.Keys.Count == 6, "Failed to retrieve index information"); // Cleanup: delete the newly created index searchService.DeleteIndex(testIndexName); }
static void Main(string[] args) { const string testIndexName = "contents"; // 1. Create an instance of the service to communicate with AzureSearch service var searchService = new AzureSearchService(TestSettings.AzureSearchApiKey, TestSettings.AzureSearchUrlPrefix, TestSettings.AzureSearchApiVersion); searchService.DeleteIndex(testIndexName); // 2. Create the index and check status var result = searchService.CreateIndex(typeof(Content), testIndexName); if (result.IsSuccessStatusCode) { Console.WriteLine("Index: {0} was created successfully.", testIndexName); } else { var task = result.Content.ReadAsStringAsync(); task.Wait(); var errorMessage = task.Result; Console.WriteLine(); } //3. Prepare the list of documents/items to upload and upload in batch var jsonDocuments = GetData(); var itemsToUpload = new List<object>(); int count = 1; foreach (var doc in jsonDocuments) { count++; var item = new Content(); (doc as JObject).FillObject(item); itemsToUpload.Add(item); if (count > TestSettings.AzureSearchBatchUpdateLimit) { searchService.AddContent(testIndexName, itemsToUpload); itemsToUpload.Clear(); count = 0; } } // Upload any remaining items if (itemsToUpload.Count > 0) { searchService.AddContent(testIndexName, itemsToUpload); } // 5. Check total document count // Depending on service tier and server load, azure service may take some time // to process the uploaded data. Let's wait for 1 sec before checking the count Thread.Sleep(1000); var totalDocuments = searchService.GetCount(testIndexName); Console.WriteLine("Total documents in index: " + totalDocuments); Console.WriteLine(""); // 6. Run a search query var searchResult = searchService.Search<SearchResultItem>(testIndexName, "Windows 8"); Console.WriteLine("Search result for term: Windows 8"); foreach (SearchResultItem item in searchResult.value) { Console.WriteLine("Title: {0} \nScore: {1}\n", item.Title, item.SearchScore); } // Uncomment this line if you like to delete the index // searchService.DeleteIndex(testIndexName); Console.Read(); }