public void inform(ResourceLoader loader) { TokenizerFactory factory = tokenizerFactory == null ? null : loadTokenizerFactory(loader, tokenizerFactory); Analyzer analyzer = new AnalyzerAnonymousInnerClassHelper(this, factory); try { string formatClass = format; if (format == null || format.Equals("solr")) { formatClass = typeof(SolrSynonymParser).Name; } else if (format.Equals("wordnet")) { formatClass = typeof(WordnetSynonymParser).Name; } // TODO: expose dedup as a parameter? map = loadSynonyms(loader, formatClass, true, analyzer); } catch (ParseException e) { throw new IOException("Error parsing synonyms file:", e); } }
public AnalyzerAnonymousInnerClassHelper(TestWordnetSynonymParser outerInstance, SynonymMap map) { this.outerInstance = outerInstance; this.map = map; }
public async Task <Response <SynonymMap> > CreateOrUpdateAsync(string synonymMapName, SynonymMap synonymMap, string ifMatch = null, string ifNoneMatch = null, CancellationToken cancellationToken = default) { if (synonymMapName == null) { throw new ArgumentNullException(nameof(synonymMapName)); } if (synonymMap == null) { throw new ArgumentNullException(nameof(synonymMap)); } using var message = CreateCreateOrUpdateRequest(synonymMapName, synonymMap, ifMatch, ifNoneMatch); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: case 201: { SynonymMap value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = SynonymMap.DeserializeSynonymMap(document.RootElement); return(Response.FromValue(value, message.Response)); }
public AnalyzerAnonymousInnerClassHelper(TestRemoveDuplicatesTokenFilter outerInstance, SynonymMap map, bool ignoreCase) { this.outerInstance = outerInstance; this.map = map; this.ignoreCase = ignoreCase; }
/// <summary> /// Creates a new synonym map or updates a synonym map if it already exists. /// <see href="https://docs.microsoft.com/rest/api/searchservice/Update-Synonym-Map" /> /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='synonymMapName'> /// The name of the synonym map to create or update. /// </param> /// <param name='synonymMap'> /// The definition of the synonym map to create or update. /// </param> /// <param name='searchRequestOptions'> /// Additional parameters for the operation /// </param> /// <param name='accessCondition'> /// Additional parameters for the operation /// </param> public static SynonymMap CreateOrUpdate(this ISynonymMapsOperations operations, string synonymMapName, SynonymMap synonymMap, SearchRequestOptions searchRequestOptions = default(SearchRequestOptions), AccessCondition accessCondition = default(AccessCondition)) { return(operations.CreateOrUpdateAsync(synonymMapName, synonymMap, searchRequestOptions, accessCondition).GetAwaiter().GetResult()); }
/// <summary> /// Creates a new synonym map or updates a synonym map if it already exists. /// <see href="https://docs.microsoft.com/rest/api/searchservice/Update-Synonym-Map" /> /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='synonymMapName'> /// The name of the synonym map to create or update. /// </param> /// <param name='synonymMap'> /// The definition of the synonym map to create or update. /// </param> /// <param name='searchRequestOptions'> /// Additional parameters for the operation /// </param> /// <param name='accessCondition'> /// Additional parameters for the operation /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <SynonymMap> CreateOrUpdateAsync(this ISynonymMapsOperations operations, string synonymMapName, SynonymMap synonymMap, SearchRequestOptions searchRequestOptions = default(SearchRequestOptions), AccessCondition accessCondition = default(AccessCondition), CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(synonymMapName, synonymMap, searchRequestOptions, accessCondition, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Creates a new synonym map or updates a synonym map if it /// already exists. /// <see href="https://docs.microsoft.com/rest/api/searchservice/Update-Synonym-Map" /> /// </summary> /// <param name='synonymMap'> /// The definition of the synonym map to create or update. /// </param> /// <param name='searchRequestOptions'> /// Additional parameters for the operation. /// </param> /// <param name='accessCondition'> /// Additional parameters for the operation. /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="CloudException"> /// Thrown when the operation returned an invalid status code. /// </exception> /// <exception cref="Microsoft.Rest.SerializationException"> /// Thrown when unable to deserialize the response. /// </exception> /// <exception cref="Microsoft.Rest.ValidationException"> /// Thrown when a required parameter is null. /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null. /// </exception> /// <returns> /// A response object containing the response body and response headers. /// </returns> public Task <AzureOperationResponse <SynonymMap> > CreateOrUpdateWithHttpMessagesAsync(SynonymMap synonymMap, SearchRequestOptions searchRequestOptions = default(SearchRequestOptions), AccessCondition accessCondition = default(AccessCondition), Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { return(CreateOrUpdateWithHttpMessagesAsync(synonymMap?.Name, synonymMap, searchRequestOptions, accessCondition, customHeaders, cancellationToken)); }
/// <summary> /// Creates a new synonym map. /// <see href="https://docs.microsoft.com/rest/api/searchservice/Create-Synonym-Map" /> /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='synonymMap'> /// The definition of the synonym map to create. /// </param> /// <param name='searchRequestOptions'> /// Additional parameters for the operation /// </param> public static SynonymMap Create(this ISynonymMapsOperations operations, SynonymMap synonymMap, SearchRequestOptions searchRequestOptions = default(SearchRequestOptions)) { return(operations.CreateAsync(synonymMap, searchRequestOptions).GetAwaiter().GetResult()); }
public virtual Response <SynonymMap> CreateOrUpdate(string synonymMapName, SynonymMap synonymMap, Guid?xMsClientRequestId = null, string ifMatch = null, string ifNoneMatch = null, CancellationToken cancellationToken = default) { return(RestClient.CreateOrUpdate(synonymMapName, synonymMap, xMsClientRequestId, ifMatch, ifNoneMatch, cancellationToken)); }
public virtual async Task <Response <SynonymMap> > CreateOrUpdateAsync(string synonymMapName, SynonymMap synonymMap, Guid?xMsClientRequestId = null, string ifMatch = null, string ifNoneMatch = null, CancellationToken cancellationToken = default) { return(await RestClient.CreateOrUpdateAsync(synonymMapName, synonymMap, xMsClientRequestId, ifMatch, ifNoneMatch, cancellationToken).ConfigureAwait(false)); }
public virtual Response <SynonymMap> Create(SynonymMap synonymMap, Guid?xMsClientRequestId = null, CancellationToken cancellationToken = default) { return(RestClient.Create(synonymMap, xMsClientRequestId, cancellationToken)); }
public virtual async Task <Response <SynonymMap> > CreateAsync(SynonymMap synonymMap, Guid?xMsClientRequestId = null, CancellationToken cancellationToken = default) { return(await RestClient.CreateAsync(synonymMap, xMsClientRequestId, cancellationToken).ConfigureAwait(false)); }
public async Task CreateIndexerAsync() { await using SearchResources resources = await SearchResources.CreateWithBlobStorageAsync(this, populate : true); Environment.SetEnvironmentVariable("SEARCH_ENDPOINT", resources.Endpoint.ToString()); Environment.SetEnvironmentVariable("SEARCH_API_KEY", resources.PrimaryApiKey); Environment.SetEnvironmentVariable("STORAGE_CONNECTION_STRING", resources.StorageAccountConnectionString); Environment.SetEnvironmentVariable("STORAGE_CONTAINER", resources.BlobContainerName); Environment.SetEnvironmentVariable("COGNITIVE_SERVICES_KEY", resources.CognitiveServicesKey); // Define clean up tasks to be invoked in reverse order added. Stack <Func <Task> > cleanUpTasks = new Stack <Func <Task> >(); try { #region Snippet:Azure_Search_Tests_Samples_CreateIndexerAsync_CreateSynonymMap // Create a new SearchIndexClient Uri endpoint = new Uri(Environment.GetEnvironmentVariable("SEARCH_ENDPOINT")); AzureKeyCredential credential = new AzureKeyCredential( Environment.GetEnvironmentVariable("SEARCH_API_KEY")); SearchIndexClient indexClient = new SearchIndexClient(endpoint, credential); #if !SNIPPET indexClient = resources.GetIndexClient(); #endif // Create a synonym map from a file containing country names and abbreviations // using the Solr format with entry on a new line using \n, for example: // United States of America,US,USA\n string synonymMapName = "countries"; #if !SNIPPET synonymMapName = Recording.Random.GetName(); #endif string synonymMapPath = "countries.txt"; #if !SNIPPET synonymMapPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "Samples", "countries.txt"); #endif SynonymMap synonyms; #if SNIPPET using (StreamReader file = File.OpenText(synonymMapPath)) { synonyms = new SynonymMap(synonymMapName, file); } #else synonyms = new SynonymMap(synonymMapName, CountriesSolrSynonymMap); #endif await indexClient.CreateSynonymMapAsync(synonyms); #endregion Snippet:Azure_Search_Tests_Samples_CreateIndexerAsync_CreateSynonymMap // Make sure our synonym map gets deleted, which is not deleted when our // index is deleted when our SearchResources goes out of scope. cleanUpTasks.Push(() => indexClient.DeleteSynonymMapAsync(synonymMapName)); #region Snippet:Azure_Search_Tests_Samples_CreateIndexerAsync_CreateIndex // Create the index string indexName = "hotels"; #if !SNIPPET indexName = Recording.Random.GetName(); #endif SearchIndex index = new SearchIndex(indexName) { Fields = { new SimpleField("hotelId", SearchFieldDataType.String) { IsKey = true, IsFilterable = true, IsSortable = true }, new SearchableField("hotelName") { IsFilterable = true, IsSortable = true }, new SearchableField("description") { AnalyzerName = LexicalAnalyzerName.EnLucene }, new SearchableField("descriptionFr") { AnalyzerName = LexicalAnalyzerName.FrLucene }, new SearchableField("tags", collection: true) { IsFilterable = true, IsFacetable = true }, new ComplexField("address") { Fields = { new SearchableField("streetAddress"), new SearchableField("city") { IsFilterable = true, IsSortable = true, IsFacetable = true }, new SearchableField("stateProvince") { IsFilterable = true, IsSortable = true, IsFacetable = true }, new SearchableField("country") { SynonymMapNames = new[] { synonymMapName },IsFilterable = true, IsSortable = true,IsFacetable = true }, new SearchableField("postalCode") { IsFilterable = true, IsSortable = true, IsFacetable = true } } } } }; await indexClient.CreateIndexAsync(index); #endregion Snippet:Azure_Search_Tests_Samples_CreateIndexerAsync_CreateIndex // Make sure our synonym map gets deleted, which is not deleted when our // index is deleted when our SearchResources goes out of scope. cleanUpTasks.Push(() => indexClient.DeleteIndexAsync(indexName)); #region Snippet:Azure_Search_Tests_Samples_CreateIndexerAsync_CreateDataSourceConnection // Create a new SearchIndexerClient SearchIndexerClient indexerClient = new SearchIndexerClient(endpoint, credential); #if !SNIPPET indexerClient = resources.GetIndexerClient(); #endif string dataSourceConnectionName = "hotels"; #if !SNIPPET dataSourceConnectionName = Recording.Random.GetName(); #endif SearchIndexerDataSourceConnection dataSourceConnection = new SearchIndexerDataSourceConnection( dataSourceConnectionName, SearchIndexerDataSourceType.AzureBlob, Environment.GetEnvironmentVariable("STORAGE_CONNECTION_STRING"), new SearchIndexerDataContainer(Environment.GetEnvironmentVariable("STORAGE_CONTAINER"))); await indexerClient.CreateDataSourceConnectionAsync(dataSourceConnection); #endregion Snippet:Azure_Search_Tests_Samples_CreateIndexerAsync_CreateDataSourceConnection // Make sure our data source gets deleted, which is not deleted when our // index is deleted when our SearchResources goes out of scope. cleanUpTasks.Push(() => indexerClient.DeleteDataSourceConnectionAsync(dataSourceConnectionName)); #region Snippet:Azure_Search_Tests_Samples_CreateIndexerAsync_Skillset // Translate English descriptions to French. // See https://docs.microsoft.com/azure/search/cognitive-search-skill-text-translation for details of the Text Translation skill. TextTranslationSkill translationSkill = new TextTranslationSkill( inputs: new[] { new InputFieldMappingEntry("text") { Source = "/document/description" } }, outputs: new[] { new OutputFieldMappingEntry("translatedText") { TargetName = "descriptionFrTranslated" } }, TextTranslationSkillLanguage.Fr) { Name = "descriptionFrTranslation", Context = "/document", DefaultFromLanguageCode = TextTranslationSkillLanguage.En }; // Use the human-translated French description if available; otherwise, use the translated description. // See https://docs.microsoft.com/azure/search/cognitive-search-skill-conditional for details of the Conditional skill. ConditionalSkill conditionalSkill = new ConditionalSkill( inputs: new[] { new InputFieldMappingEntry("condition") { Source = "= $(/document/descriptionFr) == null" }, new InputFieldMappingEntry("whenTrue") { Source = "/document/descriptionFrTranslated" }, new InputFieldMappingEntry("whenFalse") { Source = "/document/descriptionFr" } }, outputs: new[] { new OutputFieldMappingEntry("output") { TargetName = "descriptionFrFinal" } }) { Name = "descriptionFrConditional", Context = "/document", }; // Create a SearchIndexerSkillset that processes those skills in the order given below. string skillsetName = "translations"; #if !SNIPPET skillsetName = Recording.Random.GetName(); #endif SearchIndexerSkillset skillset = new SearchIndexerSkillset( skillsetName, new SearchIndexerSkill[] { translationSkill, conditionalSkill }) { CognitiveServicesAccount = new CognitiveServicesAccountKey( Environment.GetEnvironmentVariable("COGNITIVE_SERVICES_KEY")) }; await indexerClient.CreateSkillsetAsync(skillset); #endregion Snippet:Azure_Search_Tests_Samples_CreateIndexerAsync_Skillset // Make sure our skillset gets deleted, which is not deleted when our // index is deleted when our SearchResources goes out of scope. cleanUpTasks.Push(() => indexerClient.DeleteSkillsetAsync(skillsetName)); #region Snippet:Azure_Search_Tests_Samples_CreateIndexerAsync_CreateIndexer string indexerName = "hotels"; #if !SNIPPET indexerName = Recording.Random.GetName(); #endif SearchIndexer indexer = new SearchIndexer( indexerName, dataSourceConnectionName, indexName) { // We only want to index fields defined in our index, excluding descriptionFr if defined. FieldMappings = { new FieldMapping("hotelId"), new FieldMapping("hotelName"), new FieldMapping("description"), new FieldMapping("tags"), new FieldMapping("address") }, OutputFieldMappings = { new FieldMapping("/document/descriptionFrFinal") { TargetFieldName = "descriptionFr" } }, Parameters = new IndexingParameters { // Tell the indexer to parse each blob as a separate JSON document. IndexingParametersConfiguration = new IndexingParametersConfiguration { ParsingMode = BlobIndexerParsingMode.Json } }, SkillsetName = skillsetName }; // Create the indexer which, upon successful creation, also runs the indexer. await indexerClient.CreateIndexerAsync(indexer); #endregion Snippet:Azure_Search_Tests_Samples_CreateIndexerAsync_CreateIndexer // Make sure our indexer gets deleted, which is not deleted when our // index is deleted when our SearchResources goes out of scope. cleanUpTasks.Push(() => indexerClient.DeleteIndexerAsync(indexerName)); // Wait till the indexer is done. await WaitForIndexingAsync(indexerClient, indexerName); #region Snippet:Azure_Search_Tests_Samples_CreateIndexerAsync_Query // Get a SearchClient from the SearchIndexClient to share its pipeline. SearchClient searchClient = indexClient.GetSearchClient(indexName); #if !SNIPPET searchClient = InstrumentClient(new SearchClient(endpoint, indexName, credential, GetSearchClientOptions())); #endif // Query for hotels with an ocean view. SearchResults <Hotel> results = await searchClient.SearchAsync <Hotel>("ocean view"); #if !SNIPPET bool found = false; #endif await foreach (SearchResult <Hotel> result in results.GetResultsAsync()) { Hotel hotel = result.Document; #if !SNIPPET if (hotel.HotelId == "6") { Assert.IsNotNull(hotel.DescriptionFr); found = true; } #endif Console.WriteLine($"{hotel.HotelName} ({hotel.HotelId})"); Console.WriteLine($" Description (English): {hotel.Description}"); Console.WriteLine($" Description (French): {hotel.DescriptionFr}"); } #endregion Snippet:Azure_Search_Tests_Samples_CreateIndexerAsync_Query Assert.IsTrue(found, "Expected hotel #6 not found in search results"); } finally { // We want to await these individual to create a deterministic order for playing back tests. foreach (Func <Task> cleanUpTask in cleanUpTasks) { await cleanUpTask(); } } }