មេរៀននេះជួយអ្នកដាក់កំណត់ Azure AI Search ដោយប្រើទ្វារគ្រប់គ្រង Azure។ សូមអនុវត្តជំហានខាងក្រោមដើម្បីបង្កើតនិងកំណត់រចនាសម្ព័ន្ធសេវាកម្ម Azure AI Search របស់អ្នក។
មុនចាប់ផ្តើម សូមប្រាកដថាអ្នកមានរបស់ខាងក្រោម៖
https://<service-name>.search.windows.net។Azure AI Search ស្របទ្រង់ទ្រាយជាមួយឧបករណ៍ផ្សេងៗដើម្បីបង្កើនសមត្ថភាពស្វែងរករបស់អ្នក។ អ្នកអាចប្រើ Azure CLI, Python SDK, .NET SDK និងឧបករណ៍ផ្សេងៗសម្រាប់ការកំណត់រចនាសម្ព័ន្ធច្រើនជាងនេះ និងប្រតិបត្តិការរបស់អ្នក។
ចូលទៅក្នុង Azure CLI ដោយប្រើពាក្យបញ្ជា៖
az login
(ផ្តល់អនុសាសន៍) បើកការចូលរួមដោយគ្មានកូនសោជាមួយ Microsoft Entra ID (RBAC):
az search service update --name <service-name> --resource-group <resource-group> --auth-options aadOrApiKey
az role assignment create --assignee <your-user-or-principal-id> --role "Search Service Contributor" --scope $(az search service show -g <resource-group> -n <service-name> --query id -o tsv)
az role assignment create --assignee <your-user-or-principal-id> --role "Search Index Data Contributor" --scope $(az search service show -g <resource-group> -n <service-name> --query id -o tsv)
# az search service show has no "endpoint" field; build the URL from the service name.
export AZURE_SEARCH_SERVICE_ENDPOINT="https://<service-name>.search.windows.net"
ជាមួយការបើក RBAC, ឧទាហរណ៍ Python និង .NET SDK ខាងក្រោមផ្ទៀងផ្ទាត់ដោយប្រើ DefaultAzureCredential ដែលប្រើសម័យ az login របស់អ្នកនៅពេលអភិវឌ្ឍន៍ក្នុងស្រុក — មិនចាំបាច់មានកូនសោរដ្ឋបាលទេ។ សូមមើល Connect to Azure AI Search using roles។
# az search service show has no "endpoint" field; build the URL from the service name.
export AZURE_SEARCH_SERVICE_ENDPOINT="https://<service-name>.search.windows.net"
export AZURE_SEARCH_API_KEY=$(az search admin-key show -g <resource-group> --service-name <service-name> --query "primaryKey" -o tsv)
# az search service show has no "endpoint" field; build the URL from the service name.
$env:AZURE_SEARCH_SERVICE_ENDPOINT = "https://<service-name>.search.windows.net"
$env:AZURE_SEARCH_API_KEY = $(az search admin-key show -g <resource-group> --service-name <service-name> --query "primaryKey" -o tsv)
តំឡើងបណ្ណាល័យ Azure Cognitive Search client និង Azure Identity សម្រាប់ Python៖
pip install azure-search-documents azure-identity
ប្រើកូដ Python ខាងក្រោមដើម្បីបង្កើតសន្ទស្សន៍ និងបញ្ចូលឯកសារ៖
import os
from azure.identity import DefaultAzureCredential
from azure.search.documents import SearchClient
from azure.search.documents.indexes import SearchIndexClient
from azure.search.documents.indexes.models import SearchIndex, SimpleField, edm
service_endpoint = os.getenv("AZURE_SEARCH_SERVICE_ENDPOINT")
index_name = "sample-index"
# Keyless (recommended): uses your `az login` identity via Entra ID RBAC.
# Requires the "Search Service Contributor" and "Search Index Data Contributor" roles.
credential = DefaultAzureCredential()
# Fallback (key-based auth):
# from azure.core.credentials import AzureKeyCredential
# credential = AzureKeyCredential(os.getenv("AZURE_SEARCH_API_KEY"))
index_client = SearchIndexClient(service_endpoint, credential)
fields = [
SimpleField(name="id", type=edm.String, key=True),
SimpleField(name="content", type=edm.String, searchable=True),
]
index = SearchIndex(name=index_name, fields=fields)
index_client.create_index(index)
search_client = SearchClient(service_endpoint, index_name, credential)
documents = [
{"id": "1", "content": "Hello world"},
{"id": "2", "content": "Azure Cognitive Search"}
]
search_client.upload_documents(documents)
ប្រតិបត្តិពាក្យបញ្ជាខាងក្រោមដើម្បីបង្កើតសន្ទស្សន៍ និងបញ្ចូលឯកសារ៖
dotnet run ./AzureSearch.cs
ឧទាហរណ៍ .NET ខាងក្រោមប្រើ DefaultAzureCredential ដែលអាចប្រើការចូលគណនី Azure CLI របស់អ្នកពី az login នៅពេលអភិវឌ្ឍនៅក្នុងស្រុក។
នេះគឺជាកូដ .NET នៃ AzureSearch.cs៖
#:package Azure.Search.Documents@11.*
#:package Azure.Identity@1.21.0
#:property PublishAot=false
using Azure;
using Azure.Identity;
using Azure.Search.Documents;
using Azure.Search.Documents.Indexes;
using Azure.Search.Documents.Indexes.Models;
var serviceEndpoint = new Uri(Environment.GetEnvironmentVariable("AZURE_SEARCH_SERVICE_ENDPOINT")!);
var indexName = "sample-index";
// Keyless (recommended): uses your `az login` identity via Entra ID RBAC.
// Requires the "Search Service Contributor" and "Search Index Data Contributor" roles.
var credential = new DefaultAzureCredential();
// Fallback (key-based auth): the `using Azure;` directive above already imports
// AzureKeyCredential; replace the credential line above with:
// var credential = new AzureKeyCredential(Environment.GetEnvironmentVariable("AZURE_SEARCH_API_KEY")!);
var indexClient = new SearchIndexClient(serviceEndpoint, credential);
var fields = new List<SearchField>()
{
new SimpleField("id", SearchFieldDataType.String) { IsKey = true },
new SearchableField("content")
};
var index = new SearchIndex(name: indexName, fields: fields);
var response = await indexClient.CreateOrUpdateIndexAsync(index);
Console.WriteLine($"Index '{response.Value.Name}' ready.");
var searchClient = new SearchClient(serviceEndpoint, indexName, credential);
var documents = new[]
{
new { id = "1", content = "Hello world" },
new { id = "2", content = "Azure Cognitive Search" }
};
var result = await searchClient.UploadDocumentsAsync(documents);
Console.WriteLine($"Uploaded {result.Value.Results.Count} documents to index '{response.Value.Name}'.");
សម្រាប់ព័ត៌មានលម្អិតបន្ថែម សូមយោងឯកសារខាងក្រោម៖
អ្នកបានដាក់កំណត់ Azure AI Search ដោយជោគជ័យប្រើទ្វារគ្រប់គ្រង Azure និងឧបករណ៍ផ្សេងៗរួចរាល់។ ឥឡូវនេះ អ្នកអាចស្វែងយល់សមត្ថភាពលម្អិត និងលក្ខណៈពិសេសធម្មច្រើនបន្ថែមរបស់ Azure AI Search ដើម្បីបង្កើនដំណោះស្រាយស្វែងរករបស់អ្នក។
សម្រាប់ជំនួយបន្ថែម សូមចូលទៅកាន់ Azure Cognitive Search documentation។
ការបដិសេធ: ឯកសារនេះត្រូវបានបម្លែងភាសា ដោយប្រើសេវាបម្លែងភាសា AI Co-op Translator។ ទោះយើងខ្ញុំមានក្តីប្រាថ្នាឱ្យបានច្បាស់លាស់ តែសូមយល់ដឹងថាការបម្លែងដោយស្វ័យប្រវត្តិក៏អាចមានកំហុសឬភាពមិនត្រឹមត្រូវ។ ឯកសារដើមជាភាសាទីតាំងគួរត្រូវបានគេប្រើជាប្រភពច្បាស់លាស់។ សម្រាប់ព័ត៌មានសំខាន់ៗ សូមណែនាំឱ្យប្រើប្រាស់ការប្រែដោយមនុស្សជំនាញ។ យើងខ្ញុំមិនទទួលខុសត្រូវចំពោះការយល់ច្រឡំ ឬការបកស្រាយខុសបន្ទាប់ពីការប្រើប្រាស់ការបម្លែងនេះនោះទេ។