複数の言語を含むようにインデックスを強化する
検索インデックスには、複数言語のサポートを追加できます。 言語サポートを手動で追加するには、サポートするすべての言語で翻訳されたすべてのテキスト フィールドを提供します。 Azure AI サービスを使用して、エンリッチメント パイプラインを通じて翻訳されたテキストを提供することも選択できます。
ここでは、さまざまな言語のフィールドをインデックスに追加する方法を確認します。 その後、結果を特定の言語のフィールドに制限します。 最後に、エンド ユーザーのネイティブ言語を強化するスコアリング プロファイルを作成します。
言語固有のフィールドを追加する
インデックスに複数の言語を追加するには、まず、翻訳が必要なすべてのフィールドを特定します。 次に、サポートする言語ごとにこれらのフィールドを複製します。
たとえば、インデックスに英語の説明フィールドがある場合、フランス語の翻訳には description_fr を追加し、ドイツ語には description_de を追加します。 フィールドごとに、対応する言語アナライザーを定義に追加します。
インデックスの JSON 定義は次のようになります。
{
"name": "description",
"type": "Edm.String",
"facetable": false,
"filterable": false,
"key": false,
"retrievable": true,
"searchable": true,
"sortable": false,
"analyzer": "en.microsoft",
"indexAnalyzer": null,
"searchAnalyzer": null,
"synonymMaps": [],
"fields": []
},
{
"name": "description_de",
"type": "Edm.String",
"facetable": false,
"filterable": false,
"key": false,
"retrievable": true,
"searchable": true,
"sortable": false,
"analyzer": "de.microsoft",
"indexAnalyzer": null,
"searchAnalyzer": null,
"synonymMaps": [],
"fields": []
},
{
"name": "description_fr",
"type": "Edm.String",
"facetable": false,
"filterable": false,
"key": false,
"retrievable": true,
"searchable": true,
"sortable": false,
"analyzer": "fr.microsoft",
"indexAnalyzer": null,
"searchAnalyzer": null,
"synonymMaps": [],
"fields": []
},
{
"name": "description_it",
"type": "Edm.String",
"facetable": false,
"filterable": false,
"key": false,
"retrievable": true,
"searchable": true,
"sortable": false,
"analyzer": "it.microsoft",
"indexAnalyzer": null,
"searchAnalyzer": null,
"synonymMaps": [],
"fields": []
},
言語のフィールドを制限する
このモジュールでは、検索要求で返されるフィールドを制限する方法を既に確認しました。 検索するフィールドを選択することもできます。 言語固有の検索ソリューションでは、この 2 つの機能を組み合わせて、フィールド内の特定の言語に焦点を当てることができます。
search='parfait pour se divertir'&$select=listingId, description_fr, city, region, tags&$searchFields=tags, description_fr&queryType=full
上記で searchFields
および select
プロパティを使用すると、不動産サンプル データベースからこれらの結果が返されます。
{
"@odata.context": "https://advanced-cognitive-search.search.windows.net/indexes('realestate-us-sample-index')/$metadata#docs(*)",
"value": [
{
"@search.score": 12.124968,
"listingId": "OTM4MjY1OA2",
"description_fr": "Il s'agit d'un condo et est parfait pour se divertir. Cette maison offre des vues côtières Situé à proximité d'une rivière et un bureau, moulures and une véranda couverte.",
"city": "Seattle",
"region": "wa",
"tags": [
"condo",
"entertaining",
"coastal views",
"river",
"office",
"crown mouldings",
"covered front porch"
]
},
Azure AI サービスを使用して複数の言語でインデックスをエンリッチする
翻訳にアクセスできない場合は、Azure AI サービスを使用してインデックスをエンリッチし、翻訳されたフィールドを追加できます。
手順として、各言語のフィールドを追加し、各言語のスキルを追加してから、翻訳されたテキストを適切なフィールドにマップします。
たとえば、小売プロパティのインデックスの例に日本語とウクライナ語の翻訳を追加してみましょう。
新しいフィールドを追加する
これらのプロパティを持つ 2 つの新しいフィールドをインデックスに追加します。最初に日本語の翻訳を、2 番目にウクライナ語を格納します。
{
"name": "description_jp",
"type": "Edm.String",
"facetable": false,
"filterable": false,
"key": false,
"retrievable": true,
"searchable": true,
"sortable": false,
"analyzer": "ja.microsoft",
"indexAnalyzer": null,
"searchAnalyzer": null,
"synonymMaps": [],
"fields": []
},
{
"name": "description_uk",
"type": "Edm.String",
"facetable": false,
"filterable": false,
"key": false,
"retrievable": true,
"searchable": true,
"sortable": false,
"analyzer": "uk.microsoft",
"indexAnalyzer": null,
"searchAnalyzer": null,
"synonymMaps": [],
"fields": []
}
翻訳スキルセットを追加する
スキルセット定義に 2 つのスキルを追加して、document/description
フィールドを 2 つの言語に翻訳します。
"skills": [
{
"@odata.type": "#Microsoft.Skills.Text.TranslationSkill",
"name": "#1",
"description": null,
"context": "/document/description",
"defaultFromLanguageCode": "en",
"defaultToLanguageCode": "ja",
"suggestedFrom": "en",
"inputs": [
{
"name": "text",
"source": "/document/description"
}
],
"outputs": [
{
"name": "translatedText",
"targetName": "description_jp"
}
]
},
{
"@odata.type": "#Microsoft.Skills.Text.TranslationSkill",
"name": "#2",
"description": null,
"context": "/document/description",
"defaultFromLanguageCode": "en",
"defaultToLanguageCode": "uk",
"suggestedFrom": "en",
"inputs": [
{
"name": "text",
"source": "/document/description"
}
],
"outputs": [
{
"name": "translatedText",
"targetName": "description_uk"
}
]
}
]
翻訳された出力をインデックスにマップする
最後の手順では、インデクサーを更新して、翻訳されたテキストをインデックスにマップします。
"outputFieldMappings": [
{
"sourceFieldName": "/document/description/description_jp",
"targetFieldName": "description_jp"
},
{
"sourceFieldName": "/document/description/description_uk",
"targetFieldName": "description_uk"
}
]
これで、ドキュメントに 2 つの新しい翻訳された説明フィールドが追加されました。
"value": [
{
"@search.score": 1,
"listingId": "OTM4MjI2NQ2",
"beds": 5,
"baths": 4,
"description": "This is an apartment residence and is perfect for entertaining. This home provides lakefront property located close to parks and features a detached garage, beautiful bedroom floors, and lots of storage.",
"description_de": "Dies ist eine Wohnanlage und ist perfekt für Unterhaltung. Dieses Haus bietet Seeliegenschaft Parks in der Nähe und verfügt über eine freistehende Garage schöne Zimmer-Etagen and viel Stauraum.",
"description_fr": "Il s'agit d'un appartement de la résidence et est parfait pour se divertir. Cette maison offre propriété au bord du lac Situé à proximité de Parcs et dispose d'un garage détaché, planchers de belle chambre and beaucoup de rangement.",
"description_it": "Si tratta di un appartamento residence ed è perfetto per intrattenere. Questa casa fornisce proprietà lungolago Situato vicino ai parchi e dispone di un garage indipendente, piani di bella camera da letto and sacco di stoccaggio.",
"description_es": "Se trata de una residencia Apartamento y es perfecto para el entretenimiento. Esta casa ofrece propiedad de lago situado cerca de parques y cuenta con un garaje independiente, pisos de dormitorio hermoso and montón de almacenamiento.",
"description_pl": "Jest to apartament residence i jest idealny do zabawy. Ten dom zapewnia lakefront Wlasciwosc usytuowany w poblizu parków i oferuje garaz wolnostojacy, piekna sypialnia podlogi and mnóstwo miejsca do przechowywania.",
"description_nl": "Dit is een appartement Residentie en is perfect voor entertaining. Dit huis biedt lakefront eigenschap vlakbij parken en beschikt over een vrijstaande garage, mooie slaapkamer vloeren and veel opslag.",
"description_jp": "これはアパートの住居であり、娯楽に最適です。 この家は公園の近くに位置する湖畔のプロパティを提供し、独立したガレージ、美しいベッドルームの床とストレージの多くを備えています。",
"description_uk": "Це багатоквартирна резиденція і прекрасно підходить для розваг. Цей будинок забезпечує нерухомість на березі озера, розташовану недалеко від парків, і має окремий гараж, красиві підлоги спальні та багато місць для зберігання речей.",
...
},