言語アナライザ
言語固有のアナライザ を使用して、特定の言語にカスタマイズされたインデックスを作成します。 各言語アナライザには、その言語の使用パターンに基づくストップワードと単語の除算が組み込まれています。
Atlas Search は、次の言語アナライザを提供します。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 cjk
は、一般的な中国語、日本語、大文字と小文字のアナライザです
2 kuromoji
は、日本語のアナライザです
3 morfologik
は、ポーランド語アナライザです
4 nori
は、 韓国語アナライザ
5 smartcn
は中国語アナライザです
例
次のドキュメントを含むcars
という名前のコレクションについて考えてみます。
{ "_id": 1, "subject": { "en": "It is better to equip our cars to understand the causes of the accident.", "fr": "Mieux équiper nos voitures pour comprendre les causes d'un accident.", "he": "עדיף לצייד את המכוניות שלנו כדי להבין את הגורמים לתאונה." } }
{ "_id": 2, "subject": { "en": "The best time to do this is immediately after you've filled up with fuel", "fr": "Le meilleur moment pour le faire c'est immédiatement après que vous aurez fait le plein de carburant.", "he": "הזמן הטוב ביותר לעשות זאת הוא מיד לאחר שמילאת דלק." } }
組み込み言語アナライザの例
次のインデックス定義の例では、 french
アナライザを使用してsubject.fr
フィールドのインデックスを指定します。
{ "mappings": { "fields": { "subject": { "fields": { "fr": { "analyzer": "lucene.french", "type": "string" } }, "type": "document" } } } }
次のクエリは、 subject.fr
フィールドで string pour
を検索します。
db.cars.aggregate([ { $search: { "text": { "query": "pour", "path": "subject.fr" } } }, { $project: { "_id": 0, "subject.fr": 1 } } ])
上記のクエリでは、 french
アナライザを使用しても結果が返されません。 pour
は組み込みのストップワードであるためです。 standard
アナライザを使用すると、同じクエリで両方のドキュメントが返されます。
次のクエリは、 subject.fr
フィールドで string carburant
を検索します。
db.cars.aggregate([ { $search: { "text": { "query": "carburant", "path": "subject.fr" } } }, { $project: { "_id": 0, "subject.fr": 1 } } ])
{ subject: { fr: "Le meilleur moment pour le faire c'est immédiatement après que vous aurez fait le plein de carburant." } }
Atlas Search では、クエリがlucene.french
アナライザがドキュメント用に作成したトークンと一致したため、結果に_id: 1
を含むドキュメントが返されます。 lucene.french
アナライザは、 _id: 1
を使用してドキュメントのsubject.fr
フィールドに対して次のトークンを作成します。
|
|
|
|
|
|
|
|
|
カスタム言語アナライザの例
また、 icuフォールディング と ストップワード トークン フィルターを使用して カスタムアナライザ を作成し、サポートされていない言語のインデックスを作成することもできます。
次のインデックス定義の例では、 myHebrewAnalyzer
というカスタムアナライザを使用してヘブライ テキストのトークンを分析および作成し、 subject.he
フィールドのインデックスを指定します。
{ "analyzer": "lucene.standard", "mappings": { "dynamic": false, "fields": { "subject": { "fields": { "he": { "analyzer": "myHebrewAnalyzer", "type": "string" } }, "type": "document" } } }, "analyzers": [ { "charFilters": [], "name": "myHebrewAnalyzer", "tokenFilters": [ { "type": "icuFolding" }, { "tokens": [ "אן", "שלנו", "זה", "אל" ], "type": "stopword" } ], "tokenizer": { "type": "standard" } } ] }
次のクエリは、 subject.he
フィールドで string המכוניות
を検索します。
db.cars.aggregate([ { $search: { "text": { "query": "המכוניות", "path": "subject.he" } } }, { $project: { "_id": 0, "subject.he": 1 } } ])
{ subject: { he: 'עדיף לצייד את המכוניות שלנו כדי להבין את הגורמים לתאונה.' } }
Atlas Search では、クエリがmyHebrewAnalyzer
アナライザがドキュメント用に作成したトークンと一致したため、結果に_id: 1
を含むドキュメントが返されます。 myHebrewAnalyzer
アナライザは、 _id: 1
を使用してドキュメントのsubject.he
フィールドに対して次のトークンを作成します。
|
|
|
|
|
|
|
|
|
多言語検索の例
複数の言語アナライザを使用して多言語検索を実行するインデックスを作成することも可能です。
次のインデックス定義の例は、sample_mflix.movies
コレクションに動的マッピングを持つインデックスを指定しています。この定義は、lucene.italian
言語アナライザを適用してfullplot
フィールドをインデックスし、multi オプションを使用して lucene.english
を代替言語アナライザとして指定します。Atlas Search は、movies
コレクション内で動的にインデックスを作成する他のすべてのフィールドに対して、デフォルトの lucene.english
言語アナライザを使用します。
{ "analyzer": "lucene.standard", "mappings": { "dynamic": true, "fields": { "fullplot": { "type": "string", "analyzer": "lucene.italian", "multi": { "fullplot_english": { "type": "string", "analyzer": "lucene.english", } } } } } }
次の Atlas Search クエリは、次の複合演算子句を使用してコレクションをクエリします。
must
句は、text 演算子を使用してBella
という用語を含む英語とイタリア語の映画のプロットを検索しますmustNot
句は、1984 年から 2016 年の間に公開された映画を range 演算子を使用して除外しますshould
句は、text 演算子を使ってComedy
ジャンルの好みを指定します
[ { $search: { "index": "multilingual-tutorial", "compound": { "must": [{ "text": { "query": "Bella", "path": { "value": "fullplot", "multi": "fullplot_english" } } }], "mustNot": [{ "range": { "path": "released", "gt": ISODate("1984-01-01T00:00:00.000Z"), "lt": ISODate("2016-01-01T00:00:00.000Z") } }], "should": [{ "text": { "query": "Comedy", "path": "genres" } }] } } } ]
SCORE: 3.909510850906372 _id: "573a1397f29313caabce8bad" plot: "He is a revenge-obssessed stevedore whose sister was brutally raped an…" genres: 0: "Drama" runtime: 137 fullplot: "In Marseilles, a woman commits suicide after she is raped in an alley.…" released: 1983-05-18T00:00:00.000+00:00 SCORE: 3.4253346920013428 _id: "573a1396f29313caabce5735" plot: "Giovanna e' una bella ragazza, ma ha qualche problema con gli uomini: …" genres: 0: "Comedy" runtime: 100 fullplot: "Giovanna e' una bella ragazza, ma ha qualche problema con gli uomini: …" released: 1974-11-15T00:00:00.000+00:00 SCORE: 3.363344430923462 _id: "573a1395f29313caabce13cf" plot: "Gerardo è un attore o almeno cerca di esserlo, ma il pubblico non è de…" genres: 0: "Comedy" runtime: 95 fullplot: "Gerardo è un attore o almeno cerca di esserlo, ma il pubblico non è de…" released: 1960-02-10T00:00:00.000+00:00 SCORE: 1.9502882957458496 _id: "573a1396f29313caabce5299" plot: "Dr Tremayne is an enigmatic Psychiatrist running a Futuristic asylum h…" genres: 0: "Horror" runtime: 90 fullplot: "Dr Tremayne is an enigmatic Psychiatrist running a Futuristic asylum h…" released: 1973-10-31T00:00:00.000+00:00