Example #1
0
        static string GetIndexSchema()
        {
            // Extract the schema for this index
            // We use REST here because we can take the response as-is

            Uri        ServiceUri = new Uri("https://" + SourceSearchServiceName + ".search.windows.net");
            HttpClient HttpClient = new HttpClient();

            HttpClient.DefaultRequestHeaders.Add("api-key", SourceAdminKey);

            string Schema = string.Empty;

            try
            {
                Uri uri = new Uri(ServiceUri, "/indexes/" + SourceIndexName);
                HttpResponseMessage response = AzureSearchHelper.SendSearchRequest(HttpClient, HttpMethod.Get, uri);
                AzureSearchHelper.EnsureSuccessfulSearchResponse(response);
                Schema = response.Content.ReadAsStringAsync().Result.ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex.Message.ToString());
            }

            return(Schema);
        }
Example #2
0
        static Indexes GetIndexes()
        {
            // Get all the indexes from the source
            Uri        ServiceUri = new Uri("https://" + SourceSearchServiceName + ".search.windows.net");
            HttpClient HttpClient = new HttpClient();

            HttpClient.DefaultRequestHeaders.Add("api-key", SourceAPIKey);

            string indexResponse = string.Empty;

            try
            {
                Uri uri = new Uri(ServiceUri, "/indexes/");
                HttpResponseMessage response = AzureSearchHelper.SendSearchRequest(HttpClient, HttpMethod.Get, uri, null, "$select=name");
                AzureSearchHelper.EnsureSuccessfulSearchResponse(response);
                indexResponse = response.Content.ReadAsStringAsync().Result.ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex.Message.ToString());
            }

            return(JsonConvert.DeserializeObject <Indexes>(indexResponse));
        }
Example #3
0
        static void ReCreateSynonymMap()
        {
            // Get the Synonym map from the source
            Uri        sourceServiceUri = new Uri("https://" + SourceSearchServiceName + ".search.windows.net");
            HttpClient HttpClient       = new HttpClient();

            HttpClient.DefaultRequestHeaders.Add("api-key", SourceAPIKey);

            string synonymMapName = "synonym-map";
            string synonymBody    = "";

            try
            {
                // QnAMaker uses the synonymmap of synonym-map
                Uri uri = new Uri(sourceServiceUri, "/synonymmaps/" + synonymMapName + "/");
                HttpResponseMessage response = AzureSearchHelper.SendSearchRequest(HttpClient, HttpMethod.Get, uri);
                AzureSearchHelper.EnsureSuccessfulSearchResponse(response);
                synonymBody = response.Content.ReadAsStringAsync().Result.ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex.Message.ToString());
            }

            // Delete the source synonymmap if it exists
            Uri targetServiceUri = new Uri("https://" + TargetSearchServiceName + ".search.windows.net");

            HttpClient.DefaultRequestHeaders.Remove("api-key");
            HttpClient.DefaultRequestHeaders.Add("api-key", TargetAPIKey);

            try
            {
                // QnAMaker uses the synonymmap of synonym-map
                Uri uri = new Uri(targetServiceUri, "/synonymmaps/" + synonymMapName + "/");
                HttpResponseMessage response = AzureSearchHelper.SendSearchRequest(HttpClient, HttpMethod.Delete, uri);
                AzureSearchHelper.EnsureSuccessfulSearchResponse(response);
                string resp = response.Content.ReadAsStringAsync().Result.ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex.Message.ToString());
            }

            // Create the new synonym in the target if it exists
            if (!string.IsNullOrEmpty(synonymBody))
            {
                synonymBody = "{" + synonymBody.Substring(synonymBody.IndexOf("\"name\""));
                try
                {
                    // QnAMaker uses the synonymmap of synonym-map
                    Uri uri = new Uri(targetServiceUri, "/synonymmaps/" + synonymMapName + "/");
                    HttpResponseMessage response = AzureSearchHelper.SendSearchRequest(HttpClient, HttpMethod.Put, uri, synonymBody);
                    AzureSearchHelper.EnsureSuccessfulSearchResponse(response);
                    synonymBody = response.Content.ReadAsStringAsync().Result.ToString();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: {0}", ex.Message.ToString());
                }
            }

            Console.WriteLine("Synonym Map created in Target");
        }