Skip to content

Instantly share code, notes, and snippets.

@beachside-project
Last active August 2, 2023 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beachside-project/991ce8a2f967e4439d153fd38acfb589 to your computer and use it in GitHub Desktop.
Save beachside-project/991ce8a2f967e4439d153fd38acfb589 to your computer and use it in GitHub Desktop.
Cognitive Search - Camel case sample for System.Text.Json dependency
// こんな定義があるとして
// TODO: Cognitive Search の Uri をセット
private static readonly Uri SearchEndpoint = new Uri("");
// TODO: ADMIN の API キーをセット
private const string AdminApiKey = "";
// TODO: インデックス名をセット
private const string IndexName = "";
// using statement
using Azure;
using Azure.Core.Serialization;
using Azure.Search.Documents;
using Azure.Search.Documents.Indexes;
using System.Text.Json;
// searchClient の生成方法はこれ
var jsonSerializerOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
var searchClientOptions = new SearchClientOptions {Serializer = new JsonObjectSerializer(jsonSerializerOptions)};
var credential = new AzureKeyCredential(AdminApiKey);
var searchClient = new SearchClient(SearchEndpoint, IndexName, credential, searchClientOptions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment