Docs Menu
Docs Home
/
MongoDB Atlas
/ /

Atlas Search でのオートコンプリートの使用方法

項目一覧

  • オートコンプリートを使用したインデックスの定義
  • オートコンプリート クエリの実行

このチュートリアルでは、オートコンプリート クエリを有効にする Atlas Search インデックスの作成方法について説明します。 次の例では、インデックスにより、 autocomplete演算子が指定されたフィールド値をクエリできるようになります。

どちらの例でも、次の手順について説明します。

  1. sample_mflix.moviesコレクションに対して、 オートコンプリート データ型を使用して Atlas Search インデックスを設定します。

  2. 入力文字シーケンスについて、 sample_mflix.moviesコレクション内の指定されたフィールドに対して Atlas Search クエリを実行します。

開始する前に、Atlas クラスターが前提条件に記載されている要件を満たしていることを確認してください。

Atlas Search インデックスを作成するには、プロジェクトに対するProject Data Access Admin以上のアクセス権が必要です。

Atlas Search autocompleteタイプを使用して、オートコンプリート用に string フィールドのテキスト値をインデックス化できます。 さまざまなユースケースを満たすために、 autocompleteタイプを構成できます。 トークン化戦略や発音区別符号のフォールディングなど、 autocompleteタイプで使用できる構成オプションの詳細については、「 autocompleteフィールド プロパティの構成 」を参照してください。 autocompleteタイプとしてインデックス作成されたフィールドは、オートコンプリート演算子のみを使用してクエリできます。

このセクションでは、 トークン化戦略を使用して、オートコンプリート用の フィールドとtitle plotフィールドをインデックス化する Atlas SearchedgeGram インデックスを作成します。

1
  1. まだ表示されていない場合は、希望するプロジェクトを含む組織を選択しますナビゲーション バーのOrganizationsメニュー

  2. まだ表示されていない場合は、ナビゲーション バーのProjectsメニューから目的のプロジェクトを選択します。

  3. Clusters ページがまだ表示されていない場合は、サイドバーの Database をクリックします。

    [ クラスター]ページが表示されます。

2

GoAtlas Searchページには、サイドバー、Data Explorer 、またはクラスターの詳細ページから できます。

  1. サイドバーで、 Services見出しの下のAtlas Searchをクリックします。

  2. [ Select data sourceドロップダウンからクラスターを選択し、[ Go to Atlas Search ] をクリックします。

    Atlas Searchページが表示されます。

  1. クラスターの [Browse Collections] ボタンをクリックします。

  2. データベースを展開し、コレクションを選択します。

  3. コレクションのSearch Indexesタブをクリックします。

    Atlas Searchページが表示されます。

  1. クラスタの名前をクリックします。

  2. [Atlas Search] タブをクリックします。

    Atlas Searchページが表示されます。

3
4
  • ガイドを利用する場合は、Atlas Search Visual Editor を選択します。

  • Raw インデックス定義を編集するには、Atlas Search JSON Editor を選択します。

5
  1. Index Nameフィールドにautocomplete-tutorialと入力します。

    インデックスにdefaultと名付けると、 $searchパイプライン ステージでindexパラメータを指定する必要がなくなります。 インデックスにカスタム名を付ける場合は、 indexパラメータでこの名前を指定する必要があります。

  2. Database and Collectionセクションで、 sample_mflixデータベースを検索し、 moviesコレクションを選択します。

6

インデックスを作成するには、 インターフェースで または を使用できます。Atlas SearchVisual EditorAtlas SearchJSON EditorAtlas user

  1. [Next] をクリックします。

  2. [Refine Your Index] をクリックします。

  3. Field Mappings セクションで [Add Field] をクリックします。

  4. まだ選択されていない場合は [ Quick Start for Text Fields ] をクリックし、ドロップダウンから [ Search-as-you-typeテンプレート] を選択します。

  5. Field Nameドロップダウンからtitleを選択します。

  6. [Add] をクリックします。

  7. plotフィールドに対してステップcからeを繰り返します。

  8. [Save Changes] をクリックします。

  1. デフォルトの定義を、以下のインデックス定義で置き換えます。

    {
    "mappings": {
    "dynamic": false,
    "fields": {
    "title": {
    "type": "autocomplete",
    "tokenization": "edgeGram",
    "foldDiacritics": true,
    "minGrams": 2,
    "maxGrams": 15
    },
    "plot": {
    "type": "autocomplete",
    "tokenization": "edgeGram",
    "foldDiacritics": true,
    "minGrams": 2,
    "maxGrams": 15
    }
    }
    }
    }
  2. [Next] をクリックします。

7
8

インデックスが作成中であることを知らせるモーダル ウィンドウが表示されます。Close ボタンをクリックします。

9

インデックスの構築には約 1 分かかります。 作成している間、 Status列にはBuild in Progressと表示されます。 作成が完了すると、 Status列にはActiveと表示されます。


➤ [言語の選択] ドロップダウン メニューを使用して、このページの例の言語を設定します。


autocomplete演算子は、不完全な入力 string からの文字シーケンスを含む単語またはフレーズを検索します。 autocomplete演算子を使用してクエリするフィールドは、コレクションのインデックス定義の オートコンプリートデータ 型でインデックス化する必要があります。 オートコンプリート用にインデックスを構成する方法については、「オートコンプリート用にフィールドをインデックスする方法 」を参照してください。

このセクションでは、Atlas クラスターに接続し、 autocomplete演算子を使用して、 sample_mflix.moviesコレクションのtitleフィールドに対してサンプル クエリを実行します。 このサンプル クエリでは、文字のシーケンスを使用して、入力文字 string で始まる単語を含む映画タイトルを検索します。

1
  1. まだ表示されていない場合は、希望するプロジェクトを含む組織を選択しますナビゲーション バーのOrganizationsメニュー

  2. まだ表示されていない場合は、ナビゲーション バーのProjectsメニューから目的のプロジェクトを選択します。

  3. Clusters ページがまだ表示されていない場合は、サイドバーの Database をクリックします。

    [ Clusters (クラスター) ] ページが表示されます。

2

GoAtlas Searchページには、サイドバー、Data Explorer 、またはクラスターの詳細ページから できます。

  1. サイドバーで、 Services見出しの下のAtlas Searchをクリックします。

  2. [ Select data sourceドロップダウンからクラスターを選択し、[ Go to Atlas Search ] をクリックします。

    Atlas Searchページが表示されます。

  1. クラスターの [Browse Collections] ボタンをクリックします。

  2. データベースを展開し、コレクションを選択します。

  3. コレクションのSearch Indexesタブをクリックします。

    Atlas Searchページが表示されます。

  1. クラスタの名前をクリックします。

  2. [Atlas Search] タブをクリックします。

    Atlas Searchページが表示されます。

3

クエリするインデックスの右側にある [ Query ] ボタンをクリックします。

4

Edit Queryをクリックすると、 JSON形式のデフォルトのクエリ構文サンプルが表示されます。

5

次のクエリをコピーして、 Query Editorに貼り付け、 Query EditorSearchボタンをクリックします。

[
{
$search: {
index: "autocomplete-tutorial",
autocomplete: {
query: "ger",
path: "title"
}
}
}
]
SCORE: 6.085907459259033 _id: "573a1390f29313caabcd50e5"
plot: "The cartoonist, Winsor McCay, brings the Dinosaurus back to life in th…"
genre: Array
runtime: 12
SCORE: 6.085907459259033 _id: "573a1393f29313caabcddae1"
plot: "Edmund, a young boy who lives in war-devastated Germany after the Seco…"
genres: Array
runtime: 78
SCORE: 6.085907459259033 _id: "573a1397f29313caabce6b75"
plot: "Germany in Autumn does not have a plot per se; it mixes documentary fo…"
genres: Array
runtime: 123
SCORE: 6.085907459259033 _id: "573a1397f29313caabce77b5"
plot: "Germany 1939. Hans and Lene marry the day before the war breaks out, a…"
genres: Array
runtime: 123
SCORE: 6.085907459259033 _id: "573a13d4f29313caabd99fa2"
plot: "A documentary on the German artist that includes glimpses at his studi…"
genres: Array
runtime: 97
SCORE: 6.046686172485352 _id: "573a1399f29313caabcedb50"
plot: "The story of the Apache chief and his armed resistance to the US Gover…"
genres: Array
runtime: 115
SCORE: 5.8947296142578125 _id: "573a13a5f29313caabd15dae"
num_mflix_comments: 1
genres: Array
runtime: 83
SCORE: 5.826231956481934 _id: "573a139bf29313caabcf36bd"
plot: "Geri sets up a chess game to play his greatest opponent - himself."
genres: Array
runtime: 4
SCORE: 5.772464752197266 _id: "573a13d2f29313caabd922de"
plot: "The true story of an Argentine family who lived with Josef Mengele wit…"
genres: Array
runtime: 93
SCORE: 5.772464752197266 _id: "573a13b4f29313caabd41bb7"
plot: "In 1928, Dr. Max Gerson, a German-Jewish researcher, stumbled upon a t…"
genres: Array
countries: Array
6

Search Testerでは、返されるドキュメント内のすべてのフィールドが表示されない場合があります。 クエリパスで指定したフィールドを含むすべてのフィールドを表示するには、結果内のドキュメントを展開します。

これらの結果では、すべてのタイトルの単語の先頭に文字gerが表示されます。 Atlas Searchでは、title フィールドが edgeGram トークン化戦略を使用してインデックス化されているため、指定されたクエリstringで始まる結果が返されます。 Atlas Search では、 foldDiacriticstrueに設定しているため、結果にGèraldineRece do gèryが含まれます。

このセクションでは、Atlas クラスターに接続し、title 演算子とplot 演算子を使用して、sample_mflix.movies コレクションの フィールドと フィールドに対してサンプルautocomplete compoundクエリを実行します。このサンプルクエリでは、文字のシーケンスを使用して、同じ 入力文字stringで始まる単語で始まる映画タイトルと対応するプロットを検索します。

1
  1. まだ表示されていない場合は、希望するプロジェクトを含む組織を選択しますナビゲーション バーのOrganizationsメニュー

  2. まだ表示されていない場合は、ナビゲーション バーのProjectsメニューから目的のプロジェクトを選択します。

  3. Clusters ページがまだ表示されていない場合は、サイドバーの Database をクリックします。

    [ Clusters (クラスター) ] ページが表示されます。

2

GoAtlas Searchページには、サイドバー、Data Explorer 、またはクラスターの詳細ページから できます。

  1. サイドバーで、 Services見出しの下のAtlas Searchをクリックします。

  2. [ Select data sourceドロップダウンからクラスターを選択し、[ Go to Atlas Search ] をクリックします。

    Atlas Searchページが表示されます。

  1. クラスターの [Browse Collections] ボタンをクリックします。

  2. データベースを展開し、コレクションを選択します。

  3. コレクションのSearch Indexesタブをクリックします。

    Atlas Searchページが表示されます。

  1. クラスタの名前をクリックします。

  2. [Atlas Search] タブをクリックします。

    Atlas Searchページが表示されます。

3

クエリするインデックスの右側にある [ Query ] ボタンをクリックします。

4

[ Edit Queryをクリックすると、 JSON形式のデフォルトのクエリ構文サンプルが表示されます。

5

次のクエリをコピーして、 Query Editorに貼り付け、 Query EditorSearchボタンをクリックします。

[
{
$search: {
index: "autocomplete-tutorial",
compound: {
should: [{
autocomplete: {
query: "pri",
path: "title"
}
},
{
autocomplete: {
query: "pri",
path: "plot"
}
}],
minimumShouldMatch: 1
}
}
}
]
SCORE: 7.52535343170166 _id: "573a13e7f29313caabdc80cd"
plot: "Prison Terminal: The Last Days of Private Jack Hall is a moving cinema…"
genre: Array
runtime: 40
SCORE: 7.235145568847656 _id: "573a13adf29313caabd2b504"
plot: "Now settled in Genovia, Princess Mia faces a new revelation: she is be…"
genres: Array
runtime: 113
SCORE: 7.202958106994629 _id: "573a13b5f29313caabd43816"
plot: "A young fugitive prince and princess must stop a villain who unknowing…"
genres: Array
runtime: 116
SCORE: 7.201740264892578 _id: "573a139af29313caabcf0d54"
plot: "The first wedding anniversary of Princess Odette and Prince Derek is d…"
genres: Array
runtime: 71
SCORE: 7.174992561340332 _id: "573a1399f29313caabceeead"
plot: "Jane Austen's classic novel about the prejudice that occurred between …"
genres: Array
runtime: 327
SCORE: 7.173888206481934 _id: "573a13c1f29313caabd63a21"
plot: "A princess whose country has been invaded goes into hiding in Louisian…"
genres: Array
countries: Array
SCORE: 7.163987159729004 _id: "573a13eef29313caabdd51a6"
plot: "Follows the people racing to bring the hot new 3D printing technology …"
genres: Array
runtime: 100
SCORE: 7.155245780944824 _id: "573a13a5f29313caabd14adf"
plot: "When her father is captured by The Sheriff of Nottingham and Prince Jo…"
genres: Array
runtime: 88
SCORE: 7.146618843078613 _id: "573a139af29313caabcf0efc"
plot: "An Egyptian prince learns of his identity as a Hebrew and, later his d…"
genres: Array
runtime: 99
SCORE: 7.132328987121582 _id: "573a139af29313caabcf003b"
plot: "Two Russian soldiers, one battle-seasoned and the other barely into hi…"
genres: Array
runtime: 99
6

Search Testerでは、返されるドキュメント内のすべてのフィールドが表示されない場合があります。 クエリパスで指定したフィールドを含むすべてのフィールドを表示するには、結果内のドキュメントを展開します。

これらの結果では、すべてのタイトルとプロットの単語の先頭に文字priが表示されます。 Atlas Searchでは、title フィールドと plot フィールドは edgeGram トークン化戦略を使用してインデックス化されているため、指定されたクエリstringで始まる結果が返されます。

このセクションでは、Atlas クラスターに接続し、 autocomplete演算子を使用して、 sample_mflix.moviesコレクションのtitleフィールドに対してサンプル クエリを実行します。 このサンプル クエリでは、文字のシーケンスを使用して、入力文字 string で始まる単語を含む映画タイトルを検索します。

1

ターミナル ウィンドウでmongoshを開き、クラスターに接続します。 接続の詳細な手順については、「 mongosh経由での接続 」を参照してください。

2

mongoshプロンプトで次のコマンドを実行します。

use sample_mflix
3

次のクエリは、 titleフィールドにgerの文字が含まれる映画を検索します。 クエリには、出力を20の結果に制限する$limitステージと、 titleを除くすべてのフィールドを除外する$projectステージが含まれています。

db.movies.aggregate([
{
$search: {
"index": "autocomplete-tutorial",
"autocomplete": {
"path": "title",
"query": "ger"
}
}
},
{
$limit: 20
},
{
$project: {
"_id": 0,
"title": 1
}
}
])
{ title: "Gertie the Dinosaur" },
{ title: "Germany Year Zero" },
{ title: "Germany in Autumn" },
{ title: "Germany Pale Mother" },
{ title: "Gerhard Richter - Painting" },
{ title: "Geronimo: An American Legend" },
{ title: "How to Live in the German Federal Republic" },
{ title: "Geri's Game" },
{ title: "The Gerson Miracle" },
{ title: "The German Doctor" },
{ title: "From Caligari to Hitler: German Cinema in the Age of the Masse"},
{ title: "From Caligari to Hitler: German Cinema in the Age of the Masses"},
{ title: "Gèraldine" },
{ title: "Gervaise" },
{ title: "Gertrud" },
{ title: "Germinal" },
{ title: "Gerry" },
{ title: "Gerontophilia" },
{ title: "Pionery-geroi" },
{ title: "The Good German" }

これらの結果では、すべてのタイトルの単語の先頭に文字gerが表示されます。 Atlas Searchでは、title フィールドが edgeGram トークン化戦略を使用してインデックス化されているため、指定されたクエリstringで始まる結果が返されます。 Atlas Search では、 foldDiacriticstrueに設定しているため、結果にGèraldineRece do gèryが含まれます。

このセクションでは、Atlas クラスターに接続し、title 演算子とplot 演算子を使用して、sample_mflix.movies コレクションの フィールドと フィールドに対してサンプルautocomplete compoundクエリを実行します。このサンプルクエリでは、文字のシーケンスを使用して、同じ 入力文字stringで始まる単語で始まる映画タイトルと対応するプロットを検索します。

1

ターミナル ウィンドウでmongoshを開き、クラスターに接続します。 接続の詳細な手順については、「 mongosh経由での接続 」を参照してください。

2

mongoshプロンプトで次のコマンドを実行します。

use sample_mflix
3

次のクエリは、pri titleplotフィールドと フィールドに の文字が含まれる映画を検索します。クエリには、出力を 5 つの結果に制限する$limitステージと、 titleplotを除くすべてのフィールドを除外する$projectステージが含まれています。

1db.movies.aggregate([
2 {
3 "$search": {
4 "index": "autocomplete-tutorial",
5 "compound": {
6 "should": [{
7 "autocomplete": {
8 "query": "pri",
9 "path": "title"
10 }
11 },
12 {
13 "autocomplete": {
14 "query": "pri",
15 "path": "plot"
16 }
17 }],
18 "minimumShouldMatch": 1
19 }
20 }
21 },
22 {
23 "$limit": 5
24 },
25 {
26 "$project": {
27 "_id": 0,
28 "title": 1,
29 "plot": 1
30 }
31 }
32])
{
plot: 'Prison Terminal: The Last Days of Private Jack Hall is a moving cinema verite documentary that breaks through the walls of one of Americas oldest maximum security prisons to tell the story ...',
title: 'Prison Terminal: The Last Days of Private Jack Hall'
}
{
plot: 'Now settled in Genovia, Princess Mia faces a new revelation: she is being primed for an arranged marriage to an English suitor.',
title: 'The Princess Diaries 2: Royal Engagement'
}
{
plot: 'A young fugitive prince and princess must stop a villain who unknowingly threatens to destroy the world with a special dagger that enables the magic sand inside to reverse time.',
title: 'Prince of Persia: The Sands of Time'
}
{
plot: 'The first wedding anniversary of Princess Odette and Prince Derek is distracted by field fires set by Knuckles. His master Clavius, wants to conquer the world, and he needs to capture a ...',
title: 'The Swan Princess: Escape from Castle Mountain'
}
{
plot: "Jane Austen's classic novel about the prejudice that occurred between the 19th century classes and the pride which would keep lovers apart.",
title: 'Pride and Prejudice'
}

これらの結果では、すべてのタイトルとプロットの単語の先頭に文字priが表示されます。 Atlas Searchでは、title フィールドと plot フィールドは edgeGram トークン化戦略を使用してインデックス化されているため、指定されたクエリstringで始まる結果が返されます。

このセクションでは、Atlas クラスターに接続し、 autocomplete演算子を使用して、 sample_mflix.moviesコレクションのtitleフィールドに対してサンプル クエリを実行します。 このサンプル クエリでは、文字のシーケンスを使用して、入力文字 string で始まる単語を含む映画タイトルを検索します。

1

MongoDB Compass を開き、クラスターに接続します。 接続の詳細な手順については、「 Compass 経由での接続 」を参照してください。

2

Database画面で、 sample_mflixデータベースをクリックし、 moviesコレクションをクリックします。

3

クエリは、次のパイプライン ステージを使用します。

  • $searchは、 autocomplete演算子を使用してtitleフィールドで、 gerの文字で始まる単語を検索します。

  • 出力を20の結果に制限する$limitステージ

  • $projectステージでは、 titleを除くすべてのフィールドが除外されます。

MongoDB Compass でこのクエリを実行するには:

  1. [Aggregations] タブをクリックします。

  2. Select...をクリックし、ドロップダウンからステージを選択し、そのステージのクエリを追加して、次の各パイプライン ステージを構成します。 ステージを追加するには、 Add Stageをクリックします。

    moviesコレクションのAggregationsタブで、ドロップダウンからステージを選択し、そのステージのクエリを追加して、次の各パイプライン ステージを構成します。 ステージを追加するには、 Add Stageをクリックします。

    パイプラインステージ
    クエリ
    $search
    {
    "index": "autocomplete-tutorial",
    "autocomplete": {
    "query": "ger",
    "path": "title"
    }
    }
    $limit
    20
    $project
    {
    "_id": 0,
    "title": 1,
    }

Auto Previewを有効にした場合、MongoDB Compass は$autocompleteパイプライン ステージの横に次のドキュメントを表示します。

1{ title: "Gertie the Dinosaur" },
2{ title: "Germany Year Zero" },
3{ title: "Germany in Autumn" },
4{ title: "Germany Pale Mother" },
5{ title: "Gerhard Richter - Painting" },
6{ title: "Geronimo: An American Legend" },
7{ title: "How to Live in the German Federal Republic" },
8{ title: "Geri's Game" },
9{ title: "The Gerson Miracle" },
10{ title: "The German Doctor" },
11{ title: "From Caligari to Hitler: German Cinema in the Age of the Masse"},
12{ title: "From Caligari to Hitler: German Cinema in the Age of the Masses"},
13{ title: "Gèraldine" },
14{ title: "Gervaise" },
15{ title: "Gertrud" },
16{ title: "Germinal" },
17{ title: "Gerry" },
18{ title: "Gerontophilia" },
19{ title: "Pionery-geroi" },
20{ title: "The Good German" }

これらの結果では、すべてのタイトルの単語の先頭に文字gerが表示されます。 Atlas Searchでは、title フィールドが edgeGram トークン化戦略を使用してインデックス化されているため、指定されたクエリstringで始まる結果が返されます。 Atlas Search では、 foldDiacriticstrueに設定しているため、結果にGèraldineRece do gèryが含まれます。

このセクションでは、Atlas クラスターに接続し、title 演算子とplot 演算子を使用して、sample_mflix.movies コレクションの フィールドと フィールドに対してサンプルautocomplete compoundクエリを実行します。このサンプルクエリでは、文字のシーケンスを使用して、同じ 入力文字stringで始まる単語で始まる映画タイトルと対応するプロットを検索します。

1

MongoDB Compass を開き、クラスターに接続します。 接続の詳細な手順については、「 Compass 経由での接続 」を参照してください。

2

Database画面で、 sample_mflixデータベースをクリックし、 moviesコレクションをクリックします。

3

クエリは、次のパイプライン ステージを使用します。

  • $searchtitleplotは、autocomplete 演算子を使用して フィールドと フィールドで、 文字で始まる単語を検索します。pri

  • 出力を5の結果に制限する$limitステージ

  • $project ステージでは、titleplotを除くすべてのフィールドを除外します。

MongoDB Compass でこのクエリを実行するには:

  1. [Aggregations] タブをクリックします。

  2. Select...をクリックし、ドロップダウンからステージを選択し、そのステージのクエリを追加して、次の各パイプライン ステージを構成します。 ステージを追加するには、 Add Stageをクリックします。

    moviesコレクションのAggregationsタブで、ドロップダウンからステージを選択し、そのステージのクエリを追加して、次の各パイプライン ステージを構成します。 ステージを追加するには、 Add Stageをクリックします。

    パイプラインステージ
    クエリ
    $search
    {
    "index": "autocomplete-tutorial",
    "compound": {
    "should": [{
    "autocomplete": {
    "query": "pri",
    "path": "title"
    }
    },
    {
    "autocomplete": {
    "query": "pri",
    "path": "plot"
    }
    }],
    "minimumShouldMatch": 1
    }
    }
    $limit
    5
    $project
    {
    "_id": 0,
    "title": 1,
    "plot": 1
    }

Auto Previewを有効にした場合、MongoDB Compass は$autocompleteパイプライン ステージの横に次のドキュメントを表示します。

1 {
2 plot: 'Prison Terminal: The Last Days of Private Jack Hall is a moving cinema verite documentary that breaks through the walls of one of Americas oldest maximum security prisons to tell the story ...',
3 title: 'Prison Terminal: The Last Days of Private Jack Hall'
4 }
5 {
6 plot: 'Now settled in Genovia, Princess Mia faces a new revelation: she is being primed for an arranged marriage to an English suitor.',
7 title: 'The Princess Diaries 2: Royal Engagement'
8 }
9 {
10 plot: 'A young fugitive prince and princess must stop a villain who unknowingly threatens to destroy the world with a special dagger that enables the magic sand inside to reverse time.',
11 title: 'Prince of Persia: The Sands of Time'
12 }
13 {
14 plot: 'The first wedding anniversary of Princess Odette and Prince Derek is distracted by field fires set by Knuckles. His master Clavius, wants to conquer the world, and he needs to capture a ...',
15 title: 'The Swan Princess: Escape from Castle Mountain'
16 }
17 {
18 plot: "Jane Austen's classic novel about the prejudice that occurred between the 19th century classes and the pride which would keep lovers apart.",
19 title: 'Pride and Prejudice'
20 }

これらの結果では、すべてのタイトルとプロットの単語の先頭に文字priが表示されます。 Atlas Searchでは、title フィールドと plot フィールドは edgeGram トークン化戦略を使用してインデックス化されているため、指定されたクエリstringで始まる結果が返されます。

このセクションでは、Atlas クラスターに接続し、 autocomplete演算子を使用して、 sample_mflix.moviesコレクションのtitleフィールドに対してサンプル クエリを実行します。 このサンプル クエリでは、文字のシーケンスを使用して、入力文字 string で始まる単語を含む映画タイトルを検索します。

1
  1. basic-autocomplete-example という新しいディレクトリを作成し、dotnet new コマンドでプロジェクトを初期化します。

    mkdir basic-autocomplete-example
    cd basic-autocomplete-example
    dotnet new console
  2. .NET/C# ドライバーを依存関係としてプロジェクトに追加します。

    dotnet add package MongoDB.Driver
2
  1. Program.cs ファイルの内容を、次のコードで置き換えます。

    このコード例では、次のタスクを実行します。

    • mongodb パッケージと依存関係をインポートします。

    • Atlas クラスターへの接続を確立します。

    • 次のパイプライン ステージを使用します。

      • $searchは、 autocomplete演算子を使用してtitleフィールドで、 gerの文字で始まる単語を検索します。

      • 出力を20の結果に制限する$limitステージ

      • $projectステージでは、 titleを除くすべてのフィールドが除外されます。

    • カーソルを反復処理して、クエリに一致するドキュメントを出力します。

    1using MongoDB.Bson;
    2using MongoDB.Bson.Serialization.Attributes;
    3using MongoDB.Bson.Serialization.Conventions;
    4using MongoDB.Driver;
    5using MongoDB.Driver.Search;
    6
    7public class AutocompleteBasicExample
    8{
    9 private const string MongoConnectionString = "<connection-string>";
    10
    11 public static void Main(string[] args)
    12 {
    13 // allow automapping of the camelCase database fields to our MovieDocument
    14 var camelCaseConvention = new ConventionPack { new CamelCaseElementNameConvention() };
    15 ConventionRegistry.Register("CamelCase", camelCaseConvention, type => true);
    16
    17 // connect to your Atlas cluster
    18 var mongoClient = new MongoClient(MongoConnectionString);
    19 var mflixDatabase = mongoClient.GetDatabase("sample_mflix");
    20 var moviesCollection = mflixDatabase.GetCollection<MovieDocument>("movies");
    21
    22 // define and run pipeline
    23 var results = moviesCollection.Aggregate()
    24 .Search(Builders<MovieDocument>.Search.Autocomplete(movie => movie.Title, "ger"), indexName: "autocomplete-tutorial")
    25 .Project<MovieDocument>(Builders<MovieDocument>.Projection
    26 .Include(movie => movie.Title)
    27 .Exclude(movie => movie.Id))
    28 .Limit(20)
    29 .ToList();
    30
    31 // print results
    32 foreach (var movie in results)
    33 {
    34 Console.WriteLine(movie.ToJson());
    35 }
    36 }
    37}
    38
    39[BsonIgnoreExtraElements]
    40public class MovieDocument
    41{
    42 [BsonIgnoreIfDefault]
    43 public ObjectId Id { get; set; }
    44 public string Title { get; set; }
    45}
  2. サンプルを実行する前に、<connection-string> をAtlas接続stringに置き換えます。 接続stringにデータベースユーザーの認証情報が含まれていることを確認します。 詳しくは、「ドライバーによる接続 」を参照してください。

3
dotnet run basic-autocomplete-example.csproj
{ "title" : "Gertie the Dinosaur" }
{ "title" : "Germany Year Zero" }
{ "title" : "Germany in Autumn" }
{ "title" : "Germany Pale Mother" }
{ "title" : "Gerhard Richter - Painting" }
{ "title" : "Geronimo: An American Legend" }
{ "title" : "How to Live in the German Federal Republic" }
{ "title" : "Geri's Game" }
{ "title" : "The Gerson Miracle" }
{ "title" : "The German Doctor" }
{ "title" : "From Caligari to Hitler: German Cinema in the Age of the Masses" }
{ "title" : "From Caligari to Hitler: German Cinema in the Age of the Masses" }
{ "title" : "Gèraldine" }
{ "title" : "Gervaise" }
{ "title" : "Gertrud" }
{ "title" : "Germinal" }
{ "title" : "Gerry" }
{ "title" : "Gerontophilia" }
{ "title" : "Pionery-geroi" }
{ "title" : "The Good German" }

これらの結果では、すべてのタイトルの単語の先頭に文字gerが表示されます。 Atlas Searchでは、title フィールドが edgeGram トークン化戦略を使用してインデックス化されているため、指定されたクエリstringで始まる結果が返されます。 Atlas Search では、 foldDiacriticstrueに設定しているため、結果にGèraldineRece do gèryが含まれます。

このセクションでは、Atlas クラスターに接続し、title 演算子とplot 演算子を使用して、sample_mflix.movies コレクションの フィールドと フィールドに対してサンプルautocomplete compoundクエリを実行します。このサンプルクエリでは、文字のシーケンスを使用して、同じ 入力文字stringで始まる単語で始まる映画タイトルと対応するプロットを検索します。

1
  1. advanced-autocomplete-example という新しいディレクトリを作成し、dotnet new コマンドでプロジェクトを初期化します。

    mkdir advanced-autocomplete-example
    cd advanced-autocomplete-example
    dotnet new console
  2. .NET/C# ドライバーを依存関係としてプロジェクトに追加します。

    dotnet add package MongoDB.Driver
2
  1. Program.cs ファイルの内容を、次のコードで置き換えます。

    このコード例では、次のタスクを実行します。

    • mongodb パッケージと依存関係をインポートします。

    • Atlas クラスターへの接続を確立します。

    • 次のパイプライン ステージを使用します。

      • $searchtitleplotは、autocomplete 演算子を使用して フィールドと フィールドで、 文字で始まる単語を検索します。pri

      • 出力を5の結果に制限する$limitステージ

      • $project ステージでは、titleplotを除くすべてのフィールドを除外します。

    • カーソルを反復処理して、クエリに一致するドキュメントを出力します。

    1using MongoDB.Bson;
    2using MongoDB.Bson.Serialization.Attributes;
    3using MongoDB.Bson.Serialization.Conventions;
    4using MongoDB.Driver;
    5using MongoDB.Driver.Search;
    6
    7public class AutocompleteAdvancedExample
    8{
    9 private const string MongoConnectionString = "<connection-string>";
    10
    11 public static void Main(string[] args)
    12 {
    13 // allow automapping of the camelCase database fields to our MovieDocument
    14 var camelCaseConvention = new ConventionPack { new CamelCaseElementNameConvention() };
    15 ConventionRegistry.Register("CamelCase", camelCaseConvention, type => true);
    16
    17 // connect to your Atlas cluster
    18 var mongoClient = new MongoClient(MongoConnectionString);
    19 var mflixDatabase = mongoClient.GetDatabase("sample_mflix");
    20 var moviesCollection = mflixDatabase.GetCollection<MovieDocument>("movies");
    21
    22 // define and run pipeline
    23 var results = moviesCollection.Aggregate()
    24 .Search(Builders<MovieDocument>.Search.Compound()
    25 .Should(Builders<MovieDocument>.Search.Autocomplete(movie => movie.Title, "pri"))
    26 .Should(Builders<MovieDocument>.Search.Autocomplete(movie => movie.Plot, "pri"))
    27 .MinimumShouldMatch(1),
    28 indexName: "autocomplete-tutorial")
    29 .Project<MovieDocument>(Builders<MovieDocument>.Projection
    30 .Include(movie => movie.Plot)
    31 .Include(movie => movie.Title)
    32 .Exclude(movie => movie.Id))
    33 .Limit(5)
    34 .ToList();
    35
    36 // print results
    37 foreach (var movie in results)
    38 {
    39 Console.WriteLine(movie.ToJson());
    40 }
    41 }
    42}
    43
    44[BsonIgnoreExtraElements]
    45public class MovieDocument
    46{
    47 [BsonIgnoreIfDefault]
    48 public ObjectId Id { get; set; }
    49 public string Plot { get; set; }
    50 public string Title { get; set; }
    51}
  2. サンプルを実行する前に、<connection-string> をAtlas接続stringに置き換えます。 接続stringにデータベースユーザーの認証情報が含まれていることを確認します。 詳しくは、「ドライバーによる接続 」を参照してください。

3
dotnet run advanced-autocomplete-example.csproj
{
"plot" : "Prison Terminal: The Last Days of Private Jack
Hall is a moving cinema verite documentary that breaks
through the walls of one of Americas oldest maximum
security prisons to tell the story ...",
"title" : "Prison Terminal: The Last Days of Private Jack Hall"
}
{
"plot" : "Now settled in Genovia, Princess Mia faces a new
revelation: she is being primed for an arranged marriage to
an English suitor.",
"title" : "The Princess Diaries 2: Royal Engagement"
}
{
"plot" : "A young fugitive prince and princess must stop a
villain who unknowingly threatens to destroy the world with
a special dagger that enables the magic sand inside to
reverse time.",
"title" : "Prince of Persia: The Sands of Time"
}
{
"plot" : "The first wedding anniversary of Princess Odette
and Prince Derek is distracted by field fires set by
Knuckles. His master Clavius, wants to conquer the world,
and he needs to capture a ...",
"title" : "The Swan Princess: Escape from Castle Mountain"
}
{
"plot" : "Jane Austen's classic novel about the prejudice
that occurred between the 19th century classes and the
pride which would keep lovers apart.",
"title" : "Pride and Prejudice"
}

これらの結果では、すべてのタイトルとプロットの単語の先頭に文字priが表示されます。 Atlas Searchでは、title フィールドと plot フィールドは edgeGram トークン化戦略を使用してインデックス化されているため、指定されたクエリstringで始まる結果が返されます。

このセクションでは、Atlas クラスターに接続し、 autocomplete演算子を使用して、 sample_mflix.moviesコレクションのtitleフィールドに対してサンプル クエリを実行します。 このサンプル クエリでは、文字のシーケンスを使用して、入力文字 string で始まる単語を含む映画タイトルを検索します。

1
  1. autocomplete-query.goという名前のファイルを作成します。

  2. 次のコードをコピーして、 autocomplete-query.goファイルに貼り付けます。

    このコード例では、次のタスクを実行します。

    • mongodb パッケージと依存関係をインポートします。

    • Atlas クラスターへの接続を確立します。

    • 次のパイプライン ステージを使用します。

      • $searchは、 autocomplete演算子を使用してtitleフィールドで、 gerの文字で始まる単語を検索します。

      • 出力を20の結果に制限する$limitステージ

      • $projectステージでは、 titleを除くすべてのフィールドが除外されます。

    • カーソルを反復処理して、クエリに一致するドキュメントを出力します。

    1package main
    2
    3import (
    4 "context"
    5 "fmt"
    6
    7 "go.mongodb.org/mongo-driver/bson"
    8 "go.mongodb.org/mongo-driver/mongo"
    9 "go.mongodb.org/mongo-driver/mongo/options"
    10)
    11
    12func main() {
    13 // connect to your Atlas cluster
    14 client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI("<connection-string>"))
    15 if err != nil {
    16 panic(err)
    17 }
    18 defer client.Disconnect(context.TODO())
    19
    20 // set namespace
    21 collection := client.Database("sample_mflix").Collection("movies")
    22
    23 // define pipeline stages
    24 searchStage := bson.D{{"$search", bson.D{{"index", "autocomplete-tutorial"}, {"autocomplete", bson.D{{"query", "ger"}, {"path", "title"}}}}}}
    25 limitStage := bson.D{{"$limit", 20}}
    26 projectStage := bson.D{{"$project", bson.D{{"title", 1}, {"_id", 0}}}}
    27 // run pipeline
    28 cursor, err := collection.Aggregate(context.TODO(), mongo.Pipeline{searchStage, limitStage, projectStage})
    29 if err != nil {
    30 panic(err)
    31 }
    32
    33 // print results
    34 var results []bson.D
    35 if err = cursor.All(context.TODO(), &results); err != nil {
    36 panic(err)
    37 }
    38 for _, result := range results {
    39 fmt.Println(result)
    40 }
    41}
  3. サンプルを実行する前に、<connection-string> をAtlas接続stringに置き換えます。 接続stringにデータベースユーザーの認証情報が含まれていることを確認します。 詳しくは、「ドライバーによる接続 」を参照してください。

  4. 次のコマンドを実行して、コレクションをクエリします。

    go run autocomplete-query.go
    [{title Gertie the Dinosaur}]
    [{title Germany Year Zero}]
    [{title Germany in Autumn}]
    [{title Germany Pale Mother}]
    [{title Gerhard Richter - Painting}]
    [{title Geronimo: An American Legend}]
    [{title How to Live in the German Federal Republic}]
    [{title Geri's Game}]
    [{title The Gerson Miracle}]
    [{title The German Doctor}]
    [{title From Caligari to Hitler: German Cinema in the Age of the Masses}]
    [{title From Caligari to Hitler: German Cinema in the Age of the Masses}]
    [{title Gèraldine}]
    [{title Gervaise}]
    [{title Gertrud}]
    [{title Germinal}]
    [{title Gerry}]
    [{title Gerontophilia}]
    [{title Pionery-geroi}]
    [{title The Good German}]

これらの結果では、すべてのタイトルの単語の先頭に文字gerが表示されます。 Atlas Searchでは、title フィールドが edgeGram トークン化戦略を使用してインデックス化されているため、指定されたクエリstringで始まる結果が返されます。 Atlas Search では、 foldDiacriticstrueに設定しているため、結果にGèraldineRece do gèryが含まれます。

このセクションでは、Atlas クラスターに接続し、title 演算子とplot 演算子を使用して、sample_mflix.movies コレクションの フィールドと フィールドに対してサンプルautocomplete compoundクエリを実行します。このサンプルクエリでは、文字のシーケンスを使用して、同じ 入力文字stringで始まる単語で始まる映画タイトルと対応するプロットを検索します。

1
  1. autocomplete-query.goという名前のファイルを作成します。

  2. 次のコードをコピーして、 autocomplete-query.goファイルに貼り付けます。

    このコード例では、次のタスクを実行します。

    • mongodb パッケージと依存関係をインポートします。

    • Atlas クラスターへの接続を確立します。

    • 次のパイプライン ステージを使用します。

      • $searchtitleplotは、autocomplete 演算子を使用して フィールドと フィールドで、 文字で始まる単語を検索します。pri

      • 出力を5の結果に制限する$limitステージ

      • $project ステージでは、titleplotを除くすべてのフィールドを除外します。

    • カーソルを反復処理して、クエリに一致するドキュメントを出力します。

    1package main
    2
    3import (
    4 "context"
    5 "fmt"
    6
    7 "go.mongodb.org/mongo-driver/bson"
    8 "go.mongodb.org/mongo-driver/mongo"
    9 "go.mongodb.org/mongo-driver/mongo/options"
    10)
    11
    12func main() {
    13 // connect to your Atlas cluster
    14 client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI("<connection-string>"))
    15 if err != nil {
    16 panic(err)
    17 }
    18 defer client.Disconnect(context.TODO())
    19
    20 // set namespace
    21 collection := client.Database("sample_mflix").Collection("movies")
    22
    23 // define pipeline stages
    24 searchStage := bson.D{
    25 {"$search", bson.D{
    26 {"index", "autocomplete-tutorial"},
    27 {"compound", bson.D{
    28 {"should", bson.A{
    29 bson.D{
    30 {"autocomplete", bson.D{{"query", "pri"}, {"path", "title"}}},
    31 },
    32 bson.D{
    33 {"autocomplete", bson.D{{"query", "pri"}, {"path", "plot"}}},
    34 },
    35 }},
    36 {"minimumShouldMatch", 1},
    37 }},
    38 }},
    39 }
    40 limitStage := bson.D{{"$limit", 5}}
    41 projectStage := bson.D{{"$project", bson.D{{"title", 1}, {"plot", 1}, {"_id", 0}}}}
    42 // run pipeline
    43 cursor, err := collection.Aggregate(context.TODO(), mongo.Pipeline{searchStage, limitStage, projectStage})
    44 if err != nil {
    45 panic(err)
    46 }
    47
    48 // print results
    49 var results []bson.D
    50 if err = cursor.All(context.TODO(), &results); err != nil {
    51 panic(err)
    52 }
    53 for _, result := range results {
    54 fmt.Println(result)
    55 }
    56}
  3. サンプルを実行する前に、<connection-string> をAtlas接続stringに置き換えます。 接続stringにデータベースユーザーの認証情報が含まれていることを確認します。 詳しくは、「ドライバーによる接続 」を参照してください。

  4. 次のコマンドを実行して、コレクションをクエリします。

    go run autocomplete-query.go
    [
    {plot Prison Terminal: The Last Days of Private Jack Hall is a moving cinema verite documentary that breaks through the walls of one of Americas oldest maximum security prisons to tell the story ...}
    {title Prison Terminal: The Last Days of Private Jack Hall}
    ]
    [
    {plot Now settled in Genovia, Princess Mia faces a new revelation: she is being primed for an arranged marriage to an English suitor.}
    {title The Princess Diaries 2: Royal Engagement}
    ]
    [
    {plot A young fugitive prince and princess must stop a villain who unknowingly threatens to destroy the world with a special dagger that enables the magic sand inside to reverse time.}
    {title Prince of Persia: The Sands of Time}
    ]
    [
    {plot The first wedding anniversary of Princess Odette and Prince Derek is distracted by field fires set by Knuckles. His master Clavius, wants to conquer the world, and he needs to capture a ...}
    {title The Swan Princess: Escape from Castle Mountain}
    ]
    [
    {plot Jane Austen's classic novel about the prejudice that occurred between the 19th century classes and the pride which would keep lovers apart.}
    {title Pride and Prejudice}
    ]

これらの結果では、すべてのタイトルとプロットの単語の先頭に文字priが表示されます。 Atlas Searchでは、title フィールドと plot フィールドは edgeGram トークン化戦略を使用してインデックス化されているため、指定されたクエリstringで始まる結果が返されます。

このセクションでは、Atlas クラスターに接続し、 autocomplete演算子を使用して、 sample_mflix.moviesコレクションのtitleフィールドに対してサンプル クエリを実行します。 このサンプル クエリでは、文字のシーケンスを使用して、入力文字 string で始まる単語を含む映画タイトルを検索します。

1
junit
4.11以降のバージョン
mongodb-driver-sync
4.3.0以降のバージョン
slf4j-log4j12
1.7.30以降のバージョン
2
  1. AutocompleteQuery.javaという名前のファイルを作成します。

  2. 次のコードをコピーして、 AutocompleteQuery.javaファイルに貼り付けます。

    このコード例では、次のタスクを実行します。

    • mongodb パッケージと依存関係をインポートします。

    • Atlas クラスターへの接続を確立します。

    • 次のパイプライン ステージを使用します。

      • $searchは、 autocomplete演算子を使用してtitleフィールドで、 gerの文字で始まる単語を検索します。

      • 出力を20の結果に制限する$limitステージ

      • $projectステージでは、 titleを除くすべてのフィールドが除外されます。

    • カーソルを反復処理して、クエリに一致するドキュメントを出力します。

    1import static com.mongodb.client.model.Aggregates.limit;
    2import static com.mongodb.client.model.Aggregates.project;
    3import static com.mongodb.client.model.Projections.excludeId;
    4import static com.mongodb.client.model.Projections.fields;
    5import static com.mongodb.client.model.Projections.include;
    6import com.mongodb.client.MongoClient;
    7import com.mongodb.client.MongoClients;
    8import com.mongodb.client.MongoCollection;
    9import com.mongodb.client.MongoDatabase;
    10import org.bson.Document;
    11import java.util.Arrays;
    12
    13public class AutocompleteQuery {
    14
    15 public static void main(String[] args) {
    16 // connect to your Atlas cluster
    17 String uri = "<connection-string>";
    18
    19 try (MongoClient mongoClient = MongoClients.create(uri)) {
    20 // set namespace
    21 MongoDatabase database = mongoClient.getDatabase("sample_mflix");
    22 MongoCollection<Document> collection = database.getCollection("movies");
    23
    24 // define pipeline
    25 Document agg = new Document("$search",
    26 new Document("index", "autocomplete-tutorial")
    27 .append("autocomplete", new Document("query", "ger").append("path", "title")));
    28 // run pipeline and print results
    29 collection.aggregate(Arrays.asList(agg,
    30 limit(20),
    31 project(fields(excludeId(), include("title"))))).forEach(doc -> System.out.println(doc.toJson()));
    32 }
    33 }
    34}

    注意

    Maven 環境でサンプル コードを実行するには、 ファイルのインポート ステートメントの上に以下を追加します。

    package com.mongodb.drivers;
  3. サンプルを実行する前に、<connection-string> をAtlas接続stringに置き換えます。 接続stringにデータベースユーザーの認証情報が含まれていることを確認します。 詳しくは、「ドライバーによる接続 」を参照してください。

  4. AutocompleteQuery.javaファイルをコンパイルして実行します。

    javac AutocompleteQuery.java
    java AutocompleteQuery
    {"title": "Gertie the Dinosaur"}
    {"title": "Germany Year Zero"}
    {"title": "Germany in Autumn"}
    {"title": "Germany Pale Mother"}
    {"title": "Gerhard Richter - Painting"}
    {"title": "Geronimo: An American Legend"}
    {"title": "How to Live in the German Federal Republic"}
    {"title": "Geri's Game"}
    {"title": "The Gerson Miracle"}
    {"title": "The German Doctor"}
    {"title": "From Caligari to Hitler: German Cinema in the Age of the Masses"}
    {"title": "From Caligari to Hitler: German Cinema in the Age of the Masses"}
    {"title": "Gèraldine"}
    {"title": "Gervaise"}
    {"title": "Gertrud"}
    {"title": "Germinal"}
    {"title": "Gerry"}
    {"title": "Gerontophilia"}
    {"title": "Pionery-geroi"}
    {"title": "The Good German"}

これらの結果では、すべてのタイトルの単語の先頭に文字gerが表示されます。 Atlas Searchでは、title フィールドが edgeGram トークン化戦略を使用してインデックス化されているため、指定されたクエリstringで始まる結果が返されます。 Atlas Search では、 foldDiacriticstrueに設定しているため、結果にGèraldineRece do gèryが含まれます。

このセクションでは、Atlas クラスターに接続し、title 演算子とplot 演算子を使用して、sample_mflix.movies コレクションの フィールドと フィールドに対してサンプルautocomplete compoundクエリを実行します。このサンプルクエリでは、文字のシーケンスを使用して、同じ 入力文字stringで始まる単語で始まる映画タイトルと対応するプロットを検索します。

1
junit
4.11以降のバージョン
mongodb-driver-sync
4.3.0以降のバージョン
slf4j-log4j12
1.7.30以降のバージョン
2
  1. AutocompleteQuery.javaという名前のファイルを作成します。

  2. 次のコードをコピーして、 AutocompleteQuery.javaファイルに貼り付けます。

    このコード例では、次のタスクを実行します。

    • mongodb パッケージと依存関係をインポートします。

    • Atlas クラスターへの接続を確立します。

    • 次のパイプライン ステージを使用します。

      • $searchtitleplotは、autocomplete 演算子を使用して フィールドと フィールドで、 文字で始まる単語を検索します。pri

      • 出力を5の結果に制限する$limitステージ

      • $project ステージでは、titleplotを除くすべてのフィールドを除外します。

    • カーソルを反復処理して、クエリに一致するドキュメントを出力します。

    1import static com.mongodb.client.model.Aggregates.limit;
    2import static com.mongodb.client.model.Aggregates.project;
    3import static com.mongodb.client.model.Projections.excludeId;
    4import static com.mongodb.client.model.Projections.fields;
    5import static com.mongodb.client.model.Projections.include;
    6import com.mongodb.client.MongoClient;
    7import com.mongodb.client.MongoClients;
    8import com.mongodb.client.MongoCollection;
    9import com.mongodb.client.MongoDatabase;
    10import org.bson.Document;
    11import java.util.Arrays;
    12
    13public class AutocompleteQuery {
    14
    15 public static void main(String[] args) {
    16 // connect to your Atlas cluster
    17 String uri = "<connection-string>";
    18
    19 try (MongoClient mongoClient = MongoClients.create(uri)) {
    20 // set namespace
    21 MongoDatabase database = mongoClient.getDatabase("sample_mflix");
    22 MongoCollection<Document> collection = database.getCollection("movies");
    23
    24 // define pipeline
    25 Document agg = new Document("$search",
    26 new Document("index", "autocomplete-tutorial")
    27 .append("compound",
    28 new Document("should", Arrays.asList(new Document("autocomplete",
    29 new Document("query", "pri")
    30 .append("path", "title")),
    31 new Document("autocomplete",
    32 new Document("query", "pri")
    33 .append("path", "plot"))))
    34 .append("minimumShouldMatch", 1L)));
    35 // run pipeline and print results
    36 collection.aggregate(Arrays.asList(agg,
    37 limit(5),
    38 project(fields(excludeId(), include("title"))))).forEach(doc -> System.out.println(doc.toJson()));
    39 }
    40 }
    41}

    注意

    Maven 環境でサンプル コードを実行するには、 ファイルのインポート ステートメントの上に以下を追加します。

    package com.mongodb.drivers;
  3. サンプルを実行する前に、<connection-string> をAtlas接続stringに置き換えます。 接続stringにデータベースユーザーの認証情報が含まれていることを確認します。 詳しくは、「ドライバーによる接続 」を参照してください。

  4. AutocompleteQuery.javaファイルをコンパイルして実行します。

    javac AutocompleteQuery.java
    java AutocompleteQuery
    {
    plot: 'Prison Terminal: The Last Days of Private Jack Hall is a moving cinema verite documentary that breaks through the walls of one of Americas oldest maximum security prisons to tell the story ...',
    title: 'Prison Terminal: The Last Days of Private Jack Hall'
    }
    {
    plot: 'Now settled in Genovia, Princess Mia faces a new revelation: she is being primed for an arranged marriage to an English suitor.',
    title: 'The Princess Diaries 2: Royal Engagement'
    }
    {
    plot: 'A young fugitive prince and princess must stop a villain who unknowingly threatens to destroy the world with a special dagger that enables the magic sand inside to reverse time.',
    title: 'Prince of Persia: The Sands of Time'
    }
    {
    plot: 'The first wedding anniversary of Princess Odette and Prince Derek is distracted by field fires set by Knuckles. His master Clavius, wants to conquer the world, and he needs to capture a ...',
    title: 'The Swan Princess: Escape from Castle Mountain'
    }
    {
    plot: "Jane Austen's classic novel about the prejudice that occurred between the 19th century classes and the pride which would keep lovers apart.",
    title: 'Pride and Prejudice'
    }

これらの結果では、すべてのタイトルとプロットの単語の先頭に文字priが表示されます。 Atlas Searchでは、title フィールドと plot フィールドは edgeGram トークン化戦略を使用してインデックス化されているため、指定されたクエリstringで始まる結果が返されます。

このセクションでは、Atlas クラスターに接続し、 autocomplete演算子を使用して、 sample_mflix.moviesコレクションのtitleフィールドに対してサンプル クエリを実行します。 このサンプル クエリでは、文字のシーケンスを使用して、入力文字 string で始まる単語を含む映画タイトルを検索します。

1
mongodb-driver-kotlin-coroutine
4.10.0以降のバージョン
2
  1. AutocompleteQuery.ktという名前のファイルを作成します。

  2. 次のコードをコピーして、 AutocompleteQuery.ktファイルに貼り付けます。

    このコード例では、次のタスクを実行します。

    • mongodb パッケージと依存関係をインポートします。

    • Atlas クラスターへの接続を確立します。

    • 次のパイプライン ステージを使用します。

      • $searchは、 autocomplete演算子を使用してtitleフィールドで、 gerの文字で始まる単語を検索します。

      • 出力を20の結果に制限する$limitステージ

      • $projectステージでは、 titleを除くすべてのフィールドが除外されます。

    • カーソルを反復処理して、クエリに一致するドキュメントを出力します。

    1import com.mongodb.client.model.Aggregates.limit
    2import com.mongodb.client.model.Aggregates.project
    3import com.mongodb.client.model.Projections.*
    4import com.mongodb.kotlin.client.coroutine.MongoClient
    5import kotlinx.coroutines.runBlocking
    6import org.bson.Document
    7
    8fun main() {
    9 // connect to your Atlas cluster
    10 val uri = "<connection-string>"
    11 val mongoClient = MongoClient.create(uri)
    12
    13 // set namespace
    14 val database = mongoClient.getDatabase("sample_mflix")
    15 val collection = database.getCollection<Document>("movies")
    16
    17 runBlocking {
    18 // define pipeline
    19 val agg = Document(
    20 "\$search",
    21 Document("index", "autocomplete-tutorial")
    22 .append("autocomplete", Document("query", "ger").append("path", "title"))
    23 )
    24
    25 // run pipeline and print results
    26 val resultsFlow = collection.aggregate<Document>(
    27 listOf(
    28 agg,
    29 limit(20),
    30 project(fields(excludeId(), include("title")))
    31 )
    32 )
    33 resultsFlow.collect { println(it) }
    34 }
    35 mongoClient.close()
    36}
  3. サンプルを実行する前に、<connection-string> をAtlas接続stringに置き換えます。 接続stringにデータベースユーザーの認証情報が含まれていることを確認します。 詳しくは、「ドライバーによる接続 」を参照してください。

  4. AutocompleteQuery.ktファイルを実行します。

    IDE でAutocompleteQuery.ktプログラムを実行すると、次のドキュメントが出力されます。

    Document{{title=Germany in Autumn}}
    Document{{title=Germany Pale Mother}}
    Document{{title=Gertie the Dinosaur}}
    Document{{title=Geronimo: An American Legend}}
    Document{{title=How to Live in the German Federal Republic}}
    Document{{title=Geri's Game}}
    Document{{title=The Gerson Miracle}}
    Document{{title=The German Doctor}}
    Document{{title=From Caligari to Hitler: German Cinema in the Age of the Masses}}
    Document{{title=From Caligari to Hitler: German Cinema in the Age of the Masses}}
    Document{{title=Gervaise}}
    Document{{title=Germinal}}
    Document{{title=Gerry}}
    Document{{title=Gèraldine}}
    Document{{title=Pionery-geroi}}
    Document{{title=Rece do gèry}}
    Document{{title=The Good German}}
    Document{{title=Berlin Is in Germany}}
    Document{{title=Almanya: Welcome to Germany}}
    Document{{title=Hitler: A Film from Germany}}

これらの結果では、すべてのタイトルの単語の先頭に文字gerが表示されます。 Atlas Searchでは、title フィールドが edgeGram トークン化戦略を使用してインデックス化されているため、指定されたクエリstringで始まる結果が返されます。 Atlas Search では、 foldDiacriticstrueに設定しているため、結果にGèraldineRece do gèryが含まれます。

このセクションでは、Atlas クラスターに接続し、title 演算子とplot 演算子を使用して、sample_mflix.movies コレクションの フィールドと フィールドに対してサンプルautocomplete compoundクエリを実行します。このサンプルクエリでは、文字のシーケンスを使用して、同じ 入力文字stringで始まる単語で始まる映画タイトルと対応するプロットを検索します。

1
mongodb-driver-kotlin-coroutine
4.10.0以降のバージョン
2
  1. AutocompleteQuery.ktという名前のファイルを作成します。

  2. 次のコードをコピーして、 AutocompleteQuery.ktファイルに貼り付けます。

    このコード例では、次のタスクを実行します。

    • mongodb パッケージと依存関係をインポートします。

    • Atlas クラスターへの接続を確立します。

    • 次のパイプライン ステージを使用します。

      • $searchtitleplotは、autocomplete 演算子を使用して フィールドと フィールドで、 文字で始まる単語を検索します。pri

      • 出力を5の結果に制限する$limitステージ

      • $project ステージでは、titleplotを除くすべてのフィールドを除外します。

    • カーソルを反復処理して、クエリに一致するドキュメントを出力します。

    1import com.mongodb.client.model.Aggregates.limit
    2import com.mongodb.client.model.Aggregates.project
    3import com.mongodb.client.model.Projections.*
    4import com.mongodb.kotlin.client.coroutine.MongoClient
    5import kotlinx.coroutines.runBlocking
    6import org.bson.Document
    7
    8fun main() {
    9 // connect to your Atlas cluster
    10 val uri = "<connection-string>"
    11 val mongoClient = MongoClient.create(uri)
    12
    13 // set namespace
    14 val database = mongoClient.getDatabase("sample_mflix")
    15 val collection = database.getCollection<Document>("movies")
    16
    17 runBlocking {
    18 // define pipeline
    19 val agg = Document(
    20 "\$search",
    21 Document("index", "autocomplete-tutorial")
    22 .append(
    23 "compound",
    24 Document(
    25 "should", listOf(
    26 Document(
    27 "autocomplete",
    28 Document("query", "pri")
    29 .append("path", "title")
    30 ),
    31 Document(
    32 "autocomplete",
    33 Document("query", "pri")
    34 .append("path", "plot")
    35 )
    36 )
    37 )
    38 .append("minimumShouldMatch", 1L)
    39 )
    40 )
    41
    42 // run pipeline and print results
    43 val resultsFlow = collection.aggregate<Document>(
    44 listOf(
    45 agg,
    46 limit(5),
    47 project(fields(excludeId(), include("title", "plot")))
    48 )
    49 )
    50 resultsFlow.collect { println(it) }
    51 }
    52 mongoClient.close()
    53}
  3. サンプルを実行する前に、<connection-string> をAtlas接続stringに置き換えます。 接続stringにデータベースユーザーの認証情報が含まれていることを確認します。 詳しくは、「ドライバーによる接続 」を参照してください。

  4. AutocompleteQuery.ktファイルを実行します。

    IDE でAutocompleteQuery.ktプログラムを実行すると、次のドキュメントが出力されます。

    Document{{plot=Prison Terminal: The Last Days of Private Jack Hall is a moving cinema verite documentary that breaks through the walls of one of Americas oldest maximum security prisons to tell the story ..., title=Prison Terminal: The Last Days of Private Jack Hall}}
    Document{{plot=Now settled in Genovia, Princess Mia faces a new revelation: she is being primed for an arranged marriage to an English suitor., title=The Princess Diaries 2: Royal Engagement}}
    Document{{plot=A young fugitive prince and princess must stop a villain who unknowingly threatens to destroy the world with a special dagger that enables the magic sand inside to reverse time., title=Prince of Persia: The Sands of Time}}
    Document{{plot=The first wedding anniversary of Princess Odette and Prince Derek is distracted by field fires set by Knuckles. His master Clavius, wants to conquer the world, and he needs to capture a ..., title=The Swan Princess: Escape from Castle Mountain}}
    Document{{plot=Jane Austen's classic novel about the prejudice that occurred between the 19th century classes and the pride which would keep lovers apart., title=Pride and Prejudice}}

これらの結果では、すべてのタイトルとプロットの単語の先頭に文字priが表示されます。 Atlas Searchでは、title フィールドと plot フィールドは edgeGram トークン化戦略を使用してインデックス化されているため、指定されたクエリstringで始まる結果が返されます。

このセクションでは、Atlas クラスターに接続し、 autocomplete演算子を使用して、 sample_mflix.moviesコレクションのtitleフィールドに対してサンプル クエリを実行します。 このサンプル クエリでは、文字のシーケンスを使用して、入力文字 string で始まる単語を含む映画タイトルを検索します。

1
  1. autocomplete-query.jsという名前のファイルを作成します。

  2. 次のコードをコピーして、 autocomplete-query.jsファイルに貼り付けます。

    このコード例では、次のタスクを実行します。

    • MongoDB の Node.js ドライバーであるmongodbをインポートします。

    • Atlas クラスターへの接続を確立するためのMongoClientクラスのインスタンスを作成します。

    • 次のパイプライン ステージを使用します。

      • $searchは、 autocomplete演算子を使用してtitleフィールドで、 gerの文字で始まる単語を検索します。

      • 出力を20の結果に制限する$limitステージ

      • $projectステージでは、 titleを除くすべてのフィールドが除外されます。

    • カーソルを反復処理して、クエリに一致するドキュメントを出力します。

    1const { MongoClient } = require("mongodb");
    2
    3// connect to your Atlas cluster
    4const uri =
    5 "<connection-string>";
    6
    7const client = new MongoClient(uri);
    8
    9async function run() {
    10 try {
    11 await client.connect();
    12
    13 // set namespace
    14 const database = client.db("sample_mflix");
    15 const coll = database.collection("movies");
    16
    17 // define pipeline
    18 const agg = [
    19 {$search: {index: "autocomplete-tutorial", autocomplete: {query: "ger", path: "title"}}},
    20 {$limit: 20},
    21 {$project: {_id: 0,title: 1}}
    22 ];
    23 // run pipeline
    24 const result = await coll.aggregate(agg);
    25
    26 // print results
    27 await result.forEach((doc) => console.log(doc));
    28 } finally {
    29 await client.close();
    30 }
    31}
    32run().catch(console.dir);
  3. サンプルを実行する前に、<connection-string> をAtlas接続stringに置き換えます。 接続stringにデータベースユーザーの認証情報が含まれていることを確認します。 詳しくは、「ドライバーによる接続 」を参照してください。

  4. 次のコマンドを実行して、コレクションをクエリします。

    node autocompelte-query.js
    { title: 'Gertie the Dinosaur' }
    { title: 'Germany Year Zero' }
    { title: 'Germany in Autumn' }
    { title: 'Germany Pale Mother' }
    { title: 'Gerhard Richter - Painting' }
    { title: 'Geronimo: An American Legend' }
    { title: 'How to Live in the German Federal Republic' }
    { title: "Geri's Game" }
    { title: 'The Gerson Miracle' }
    { title: 'The German Doctor' }
    { title: 'From Caligari to Hitler: German Cinema in the Age of the Masses' }
    { title: 'From Caligari to Hitler: German Cinema in the Age of the Masses' }
    { title: 'Gèraldine' }
    { title: 'Gervaise' }
    { title: 'Gertrud' }
    { title: 'Germinal' }
    { title: 'Gerry' }
    { title: 'Gerontophilia' }
    { title: 'Pionery-geroi' }
    { title: 'The Good German' }

これらの結果では、すべてのタイトルの単語の先頭に文字gerが表示されます。 Atlas Searchでは、title フィールドが edgeGram トークン化戦略を使用してインデックス化されているため、指定されたクエリstringで始まる結果が返されます。 Atlas Search では、 foldDiacriticstrueに設定しているため、結果にGèraldineRece do gèryが含まれます。

このセクションでは、Atlas クラスターに接続し、title 演算子とplot 演算子を使用して、sample_mflix.movies コレクションの フィールドと フィールドに対してサンプルautocomplete compoundクエリを実行します。このサンプルクエリでは、文字のシーケンスを使用して、同じ 入力文字stringで始まる単語で始まる映画タイトルと対応するプロットを検索します。

1
  1. autocomplete-query.jsという名前のファイルを作成します。

  2. 次のコードをコピーして、 autocomplete-query.jsファイルに貼り付けます。

    このコード例では、次のタスクを実行します。

    • MongoDB の Node.js ドライバーであるmongodbをインポートします。

    • Atlas クラスターへの接続を確立するためのMongoClientクラスのインスタンスを作成します。

    • 次のパイプライン ステージを使用します。

      • $searchtitleplotは、autocomplete 演算子を使用して フィールドと フィールドで、 文字で始まる単語を検索します。pri

      • 出力を5の結果に制限する$limitステージ

      • $project ステージでは、titleplotを除くすべてのフィールドを除外します。

    • カーソルを反復処理して、クエリに一致するドキュメントを出力します。

    1const { MongoClient } = require("mongodb");
    2
    3// connect to your Atlas cluster
    4const uri =
    5 "<connection-string>";
    6
    7const client = new MongoClient(uri);
    8
    9async function run() {
    10 try {
    11 await client.connect();
    12
    13 // set namespace
    14 const database = client.db("sample_mflix");
    15 const coll = database.collection("movies");
    16
    17 // define pipeline
    18 const agg = [
    19 {
    20 '$search': {
    21 'index': 'autocomplete-tutorial',
    22 'compound': {
    23 'should': [
    24 {
    25 'autocomplete': {
    26 'query': 'pri',
    27 'path': 'title'
    28 }
    29 },
    30 {
    31 'autocomplete': {
    32 'query': 'pri',
    33 'path': 'plot'
    34 }
    35 }
    36 ],
    37 'minimumShouldMatch': 1
    38 }
    39 }
    40 },
    41 {
    42 '$limit': 5
    43 },
    44 {
    45 '$project': {
    46 '_id': 0,
    47 'title': 1,
    48 'plot': 1
    49 }
    50 }
    51 ];
    52 // run pipelines
    53 const result = await coll.aggregate(agg);
    54
    55 // print results
    56 await result.forEach((doc) => console.log(doc));
    57 } finally {
    58 await client.close();
    59 }
    60}
    61run().catch(console.dir);
  3. サンプルを実行する前に、<connection-string> をAtlas接続stringに置き換えます。 接続stringにデータベースユーザーの認証情報が含まれていることを確認します。 詳しくは、「ドライバーによる接続 」を参照してください。

  4. 次のコマンドを実行して、コレクションをクエリします。

    node autocomplete-query.js
    {
    plot: 'Prison Terminal: The Last Days of Private Jack Hall is a moving cinema verite documentary that breaks through the walls of one of Americas oldest maximum security prisons to tell the story ...',
    title: 'Prison Terminal: The Last Days of Private Jack Hall'
    }
    {
    plot: 'Now settled in Genovia, Princess Mia faces a new revelation: she is being primed for an arranged marriage to an English suitor.',
    title: 'The Princess Diaries 2: Royal Engagement'
    }
    {
    plot: 'A young fugitive prince and princess must stop a villain who unknowingly threatens to destroy the world with a special dagger that enables the magic sand inside to reverse time.',
    title: 'Prince of Persia: The Sands of Time'
    }
    {
    plot: 'The first wedding anniversary of Princess Odette and Prince Derek is distracted by field fires set by Knuckles. His master Clavius, wants to conquer the world, and he needs to capture a ...',
    title: 'The Swan Princess: Escape from Castle Mountain'
    }
    {
    plot: "Jane Austen's classic novel about the prejudice that occurred between the 19th century classes and the pride which would keep lovers apart.",
    title: 'Pride and Prejudice'
    }

これらの結果では、すべてのタイトルとプロットの単語の先頭に文字priが表示されます。 Atlas Searchでは、title フィールドと plot フィールドは edgeGram トークン化戦略を使用してインデックス化されているため、指定されたクエリstringで始まる結果が返されます。

このセクションでは、Atlas クラスターに接続し、 autocomplete演算子を使用して、 sample_mflix.moviesコレクションのtitleフィールドに対してサンプル クエリを実行します。 このサンプル クエリでは、文字のシーケンスを使用して、入力文字 string で始まる単語を含む映画タイトルを検索します。

1
  1. autocomplete-query.pyという名前のファイルを作成します。

  2. 次のコードをコピーして、 autocomplete.pyファイルに貼り付けます。

    次のコード例では、次を行います。

    • pymongo、MongoDB の Python ドライバー、およびDNSシード リスト接続文字列を使用してpymongoAtlas に接続するために必要なdns モジュールをインポートします。

    • Atlas クラスターへの接続を確立するためのMongoClientクラスのインスタンスを作成します。

    • 次のパイプライン ステージを使用します。

      • $searchは、 autocomplete演算子を使用してtitleフィールドで、 gerの文字で始まる単語を検索します。

      • 出力を20の結果に制限する$limitステージ

      • $projectステージでは、 titleを除くすべてのフィールドが除外されます。

    • カーソルを反復処理して、クエリに一致するドキュメントを出力します。

    1import pymongo
    2
    3# connect to your Atlas cluster
    4client = pymongo.MongoClient('<connection-string>')
    5
    6# define pipeline
    7pipeline = [
    8 {"$search": {"index": "autocomplete-tutorial", "autocomplete": {"query": "ger", "path": "title"}}},
    9 {"$limit": 20},
    10 {"$project": {"_id": 0, "title": 1}},
    11]
    12# run pipeline
    13result = client["sample_mflix"]["movies"].aggregate(pipeline)
    14
    15# print results
    16for i in result:
    17 print(i)
  3. サンプルを実行する前に、<connection-string> をAtlas接続stringに置き換えます。 接続stringにデータベースユーザーの認証情報が含まれていることを確認します。 詳しくは、「ドライバーによる接続 」を参照してください。

  4. 次のコマンドを実行して、コレクションをクエリします。

    python autocomplete-query.py
    {'title': 'Gertie the Dinosaur'}
    {'title': 'Germany Year Zero'}
    {'title': 'Germany in Autumn'}
    {'title': 'Germany Pale Mother'}
    {'title': 'Gerhard Richter - Painting'}
    {'title': 'Geronimo: An American Legend'}
    {'title': 'How to Live in the German Federal Republic'}
    {'title': "Geri's Game"}
    {'title': 'The Gerson Miracle'}
    {'title': 'The German Doctor'}
    {'title': 'From Caligari to Hitler: German Cinema in the Age of the Masses'}
    {'title': 'From Caligari to Hitler: German Cinema in the Age of the Masses'}
    {'title': 'G\xe8raldine'}
    {'title': 'Gervaise'}
    {'title': 'Gertrud'}
    {'title': 'Germinal'}
    {'title': 'Gerry'}
    {'title': 'Gerontophilia'}
    {'title': 'Pionery-geroi'}
    {'title': 'The Good German'}

これらの結果では、すべてのタイトルの単語の先頭に文字gerが表示されます。 Atlas Searchでは、title フィールドが edgeGram トークン化戦略を使用してインデックス化されているため、指定されたクエリstringで始まる結果が返されます。 Atlas Search では、 foldDiacriticstrueに設定しているため、結果にGèraldineRece do gèryが含まれます。

このセクションでは、Atlas クラスターに接続し、title 演算子とplot 演算子を使用して、sample_mflix.movies コレクションの フィールドと フィールドに対してサンプルautocomplete compoundクエリを実行します。このサンプルクエリでは、文字のシーケンスを使用して、同じ 入力文字stringで始まる単語で始まる映画タイトルと対応するプロットを検索します。

1
  1. autocomplete-query.pyという名前のファイルを作成します。

  2. 次のコードをコピーして、 autocomplete.pyファイルに貼り付けます。

    次のコード例では、次を行います。

    • pymongo、MongoDB の Python ドライバー、およびDNSシード リスト接続文字列を使用してpymongoAtlas に接続するために必要なdns モジュールをインポートします。

    • Atlas クラスターへの接続を確立するためのMongoClientクラスのインスタンスを作成します。

    • 次のパイプライン ステージを使用します。

      • $searchtitleplotは、autocomplete 演算子を使用して フィールドと フィールドで、 文字で始まる単語を検索します。pri

      • 出力を5の結果に制限する$limitステージ

      • $project ステージでは、titleplotを除くすべてのフィールドを除外します。

    • カーソルを反復処理して、クエリに一致するドキュメントを出力します。

    1import pymongo
    2
    3# connect to your Atlas cluster
    4client = pymongo.MongoClient('<connection-string>')
    5
    6# define pipeline
    7pipeline = [
    8 {
    9 '$search': {
    10 'index': 'autocomplete-tutorial',
    11 'compound': {
    12 'should': [
    13 {
    14 'autocomplete': {
    15 'query': 'pri',
    16 'path': 'title'
    17 }
    18 }, {
    19 'autocomplete': {
    20 'query': 'pri',
    21 'path': 'plot'
    22 }
    23 }
    24 ],
    25 'minimumShouldMatch': 1
    26 }
    27 }
    28 },
    29 {
    30 '$limit': 5
    31 },
    32 {
    33 '$project': {
    34 '_id': 0, 'title': 1, 'plot': 1
    35 }
    36 }
    37]
    38# run pipeline
    39result = client["sample_mflix"]["movies"].aggregate(pipeline)
    40
    41# print results
    42for i in result:
    43 print(i)
  3. サンプルを実行する前に、<connection-string> をAtlas接続stringに置き換えます。 接続stringにデータベースユーザーの認証情報が含まれていることを確認します。 詳しくは、「ドライバーによる接続 」を参照してください。

  4. 次のコマンドを実行して、コレクションをクエリします。

    python autocomplete-query.py
    {
    plot: 'Prison Terminal: The Last Days of Private Jack Hall is a moving cinema verite documentary that breaks through the walls of one of Americas oldest maximum security prisons to tell the story ...',
    title: 'Prison Terminal: The Last Days of Private Jack Hall'
    }
    {
    plot: 'Now settled in Genovia, Princess Mia faces a new revelation: she is being primed for an arranged marriage to an English suitor.',
    title: 'The Princess Diaries 2: Royal Engagement'
    }
    {
    plot: 'A young fugitive prince and princess must stop a villain who unknowingly threatens to destroy the world with a special dagger that enables the magic sand inside to reverse time.',
    title: 'Prince of Persia: The Sands of Time'
    }
    {
    plot: 'The first wedding anniversary of Princess Odette and Prince Derek is distracted by field fires set by Knuckles. His master Clavius, wants to conquer the world, and he needs to capture a ...',
    title: 'The Swan Princess: Escape from Castle Mountain'
    }
    {
    plot: "Jane Austen's classic novel about the prejudice that occurred between the 19th century classes and the pride which would keep lovers apart.",
    title: 'Pride and Prejudice'
    }

これらの結果では、すべてのタイトルとプロットの単語の先頭に文字priが表示されます。 Atlas Searchでは、title フィールドと plot フィールドは edgeGram トークン化戦略を使用してインデックス化されているため、指定されたクエリstringで始まる結果が返されます。

戻る

Atlas Search 結果を並べ替える方法