Mỗi tài liệu được trả về bởi truy vấn Tìm kiếm Atlas được chỉ định một số điểm dựa trên mức độ liên quan và các tài liệu có trong tập kết quả được trả về theo thứ tự từ điểm cao nhất đến thấp nhất
Sửa Điểm
Nhiều yếu tố có thể ảnh hưởng đến điểm số của tài liệu, bao gồm
Vị trí của thuật ngữ tìm kiếm trong tài liệu,
Tần suất xuất hiện của cụm từ tìm kiếm trong tài liệu,
Loại truy vấn sử dụng,
Loại truy vấn sử dụng
Điểm được gán cho tài liệu được trả về là một phần của siêu dữ liệu của tài liệu. Bạn có thể bao gồm điểm số của từng tài liệu được trả về cùng với kết quả đã đặt bằng cách sử dụng
trong đường ống tổng hợp của bạn. Sau một giai đoạn, bạn không cần bao gồm giảm dần vì Tìm kiếm Atlas trả về các tài liệu từ điểm cao nhất đến thấp nhất theo mặc địnhTruy vấn ví dụ sau sử dụng một giai đoạn để thêm trường có tên
1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
6 vào tài liệu được trả về1db.movies.aggregate[[2 {3 $search: {4 "text": {5 "query": "Helsinki",6 "path": "plot"7 }8 }9 },10 {11 $project: {12 plot: 1,13 title: 1,14 score: { $meta: "searchScore" }15 }16 }17]]
Bạn có thể tìm thêm thông tin về thuật toán tính điểm Lucene trong Tài liệu về Lucene.
Các tùy chọn sửa đổi điểm sau đây có sẵn cho tất cả các nhà khai thác. Để biết chi tiết và ví dụ, hãy nhấp vào bất kỳ tùy chọn nào sau đây
boost
Tùy chọn boost
nhân điểm cơ sở của kết quả với một số đã cho hoặc giá trị của trường số trong tài liệu. Ví dụ: bạn có thể sử dụng boost
để tăng tầm quan trọng của một số tài liệu phù hợp trong kết quả
Ghi chú
Không thể sử dụng các tùy chọn
boost
vàconstant
cùng nhauTùy chọn ________ 83 _______ với
7 cũng giống như phép nhân bằng cách sử dụng tùy chọn với một1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score: 8.154602050781256 },7 {8 plot: "When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score: 511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score: 516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score: 521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score: 526 }27]
Lĩnh vực
Tùy chọn boost
có các trường sau
Đồng ruộng
Loại
sự cần thiết
Sự miêu tả
01db.transactions.aggregate[{2 "$search": {3 "embeddedDocument": {4 "path": "transactions",5 "operator": {6 "compound": {7 "must": [8 {9 "text": {10 "path": "transactions.symbol",11 "query": "amd"12 }13 },14 {15 "text": {16 "path": "transactions.transaction_code",17 "query": "buy"18 }19 }20 ],21 "score": {22 "function": {23 "path": {24 "value": "transactions.amount",25 "undefined": 1.026 }27 }28 }29 }30 },31 "score": {32 "embedded": {33 "aggregate": "maximum",34 "outerScore": {35 "function": {36 "multiply": [37 {38 "log1p": {39 "path": {40 "value": "transaction_count"41 }42 }43 },44 {45 "score": "relevance"46 }47 ]48 }49 }50 }51 }52 }53 }54},55{ "$limit": 10 },56{57 "$project": {58 "_id": 0,59 "account_id": 1,60 "transaction_count": 1,61 "score": { $meta: "searchScore" }62 }63}]
trôi nổi
có điều kiện
Số để nhân điểm cơ bản mặc định với. Giá trị phải là một số dương. Yêu cầu phải có
0 hoặc 1db.transactions.aggregate[{2 "$search": {3 "embeddedDocument": {4 "path": "transactions",5 "operator": {6 "compound": {7 "must": [8 {9 "text": {10 "path": "transactions.symbol",11 "query": "amd"12 }13 },14 {15 "text": {16 "path": "transactions.transaction_code",17 "query": "buy"18 }19 }20 ],21 "score": {22 "function": {23 "path": {24 "value": "transactions.amount",25 "undefined": 1.026 }27 }28 }29 }30 },31 "score": {32 "embedded": {33 "aggregate": "maximum",34 "outerScore": {35 "function": {36 "multiply": [37 {38 "log1p": {39 "path": {40 "value": "transaction_count"41 }42 }43 },44 {45 "score": "relevance"46 }47 ]48 }49 }50 }51 }52 }53 }54},55{ "$limit": 10 },56{57 "$project": {58 "_id": 0,59 "account_id": 1,60 "transaction_count": 1,61 "score": { $meta: "searchScore" }62 }63}]
7, nhưng bạn không thể chỉ định cả hai1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score: 8.154602050781256 },7 {8 plot: "When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score: 511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score: 516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score: 521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score: 526 }27]
71[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score: 8.154602050781256 },7 {8 plot: "When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score: 511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score: 516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score: 521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score: 526 }27]
chuỗi
có điều kiện
Tên của trường số có giá trị để nhân điểm cơ sở mặc định với. Phải có
7 hoặc 1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score: 8.154602050781256 },7 {8 plot: "When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score: 511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score: 516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score: 521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score: 526 }27]
0, nhưng bạn không thể chỉ định cả hai1db.transactions.aggregate[{2 "$search": {3 "embeddedDocument": {4 "path": "transactions",5 "operator": {6 "compound": {7 "must": [8 {9 "text": {10 "path": "transactions.symbol",11 "query": "amd"12 }13 },14 {15 "text": {16 "path": "transactions.transaction_code",17 "query": "buy"18 }19 }20 ],21 "score": {22 "function": {23 "path": {24 "value": "transactions.amount",25 "undefined": 1.026 }27 }28 }29 }30 },31 "score": {32 "embedded": {33 "aggregate": "maximum",34 "outerScore": {35 "function": {36 "multiply": [37 {38 "log1p": {39 "path": {40 "value": "transaction_count"41 }42 }43 },44 {45 "score": "relevance"46 }47 ]48 }49 }50 }51 }52 }53 }54},55{ "$limit": 10 },56{57 "$project": {58 "_id": 0,59 "account_id": 1,60 "transaction_count": 1,61 "score": { $meta: "searchScore" }62 }63}]
61db.transactions.aggregate[{2 "$search": {3 "embeddedDocument": {4 "path": "transactions",5 "operator": {6 "compound": {7 "must": [8 {9 "text": {10 "path": "transactions.symbol",11 "query": "amd"12 }13 },14 {15 "text": {16 "path": "transactions.transaction_code",17 "query": "buy"18 }19 }20 ],21 "score": {22 "function": {23 "path": {24 "value": "transactions.amount",25 "undefined": 1.026 }27 }28 }29 }30 },31 "score": {32 "embedded": {33 "aggregate": "maximum",34 "outerScore": {35 "function": {36 "multiply": [37 {38 "log1p": {39 "path": {40 "value": "transaction_count"41 }42 }43 },44 {45 "score": "relevance"46 }47 ]48 }49 }50 }51 }52 }53 }54},55{ "$limit": 10 },56{57 "$project": {58 "_id": 0,59 "account_id": 1,60 "transaction_count": 1,61 "score": { $meta: "searchScore" }62 }63}]
trôi nổi
Không bắt buộc
Giá trị số để thay thế cho
7 nếu trường số được chỉ định thông qua 1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score: 8.154602050781256 },7 {8 plot: "When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score: 511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score: 516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score: 521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score: 526 }27]
7 không được tìm thấy trong tài liệu. Nếu bỏ qua, mặc định là 1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score: 8.154602050781256 },7 {8 plot: "When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score: 511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score: 516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score: 521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score: 526 }27]
9. Bạn chỉ có thể chỉ định điều này nếu bạn chỉ định 1db.transactions.aggregate[{2 "$search": {3 "embeddedDocument": {4 "path": "transactions",5 "operator": {6 "compound": {7 "must": [8 {9 "text": {10 "path": "transactions.symbol",11 "query": "amd"12 }13 },14 {15 "text": {16 "path": "transactions.transaction_code",17 "query": "buy"18 }19 }20 ],21 "score": {22 "function": {23 "path": {24 "value": "transactions.amount",25 "undefined": 1.026 }27 }28 }29 }30 },31 "score": {32 "embedded": {33 "aggregate": "maximum",34 "outerScore": {35 "function": {36 "multiply": [37 {38 "log1p": {39 "path": {40 "value": "transaction_count"41 }42 }43 },44 {45 "score": "relevance"46 }47 ]48 }49 }50 }51 }52 }53 }54},55{ "$limit": 10 },56{57 "$project": {58 "_id": 0,59 "account_id": 1,60 "transaction_count": 1,61 "score": { $meta: "searchScore" }62 }63}]
71[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score: 8.154602050781256 },7 {8 plot: "When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score: 511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score: 516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score: 521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score: 526 }27]
ví dụ
Các ví dụ sau sử dụng bộ sưu tập
1[2 { account_id: 467651, transaction_count: 99, score: 19982 },3 { account_id: 271554, transaction_count: 96, score: 19851.822265625 },4 { account_id: 71148, transaction_count: 99, score: 19840 },5 { account_id: 408143, transaction_count: 100, score: 19836.76953125 },6 { account_id: 977774, transaction_count: 98, score: 19822.64453125 },7 { account_id: 187107, transaction_count: 96, score: 19754.470703125 },8 { account_id: 492843, transaction_count: 97, score: 19744.998046875 },9 { account_id: 373169, transaction_count: 93, score: 19553.697265625 },10 { account_id: 249078, transaction_count: 89, score: 19436.896484375 },11 { account_id: 77690, transaction_count: 90, score: 19418.017578125 }12]
1 trong cơ sở dữ liệu 1[2 { account_id: 467651, transaction_count: 99, score: 19982 },3 { account_id: 271554, transaction_count: 96, score: 19851.822265625 },4 { account_id: 71148, transaction_count: 99, score: 19840 },5 { account_id: 408143, transaction_count: 100, score: 19836.76953125 },6 { account_id: 977774, transaction_count: 98, score: 19822.64453125 },7 { account_id: 187107, transaction_count: 96, score: 19754.470703125 },8 { account_id: 492843, transaction_count: 97, score: 19744.998046875 },9 { account_id: 373169, transaction_count: 93, score: 19553.697265625 },10 { account_id: 249078, transaction_count: 89, score: 19436.896484375 },11 { account_id: 77690, transaction_count: 90, score: 19418.017578125 }12]
2. Nếu bạn có cụm của mình, bạn có thể tạo chỉ mục Tìm kiếm Atlas 1[2 { account_id: 467651, transaction_count: 99, score: 19982 },3 { account_id: 271554, transaction_count: 96, score: 19851.822265625 },4 { account_id: 71148, transaction_count: 99, score: 19840 },5 { account_id: 408143, transaction_count: 100, score: 19836.76953125 },6 { account_id: 977774, transaction_count: 98, score: 19822.64453125 },7 { account_id: 187107, transaction_count: 96, score: 19754.470703125 },8 { account_id: 492843, transaction_count: 97, score: 19744.998046875 },9 { account_id: 373169, transaction_count: 93, score: 19553.697265625 },10 { account_id: 249078, transaction_count: 89, score: 19436.896484375 },11 { account_id: 77690, transaction_count: 90, score: 19418.017578125 }12]
3 và chạy các truy vấn mẫu trên cụm của bạnCác truy vấn mẫu minh họa cách tăng tầm quan trọng của một tiêu chí tìm kiếm so với tiêu chí tìm kiếm khác. Các truy vấn bao gồm một giai đoạn
1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
2 để loại trừ tất cả các trường ngoại trừ 1[2 { account_id: 467651, transaction_count: 99, score: 19982 },3 { account_id: 271554, transaction_count: 96, score: 19851.822265625 },4 { account_id: 71148, transaction_count: 99, score: 19840 },5 { account_id: 408143, transaction_count: 100, score: 19836.76953125 },6 { account_id: 977774, transaction_count: 98, score: 19822.64453125 },7 { account_id: 187107, transaction_count: 96, score: 19754.470703125 },8 { account_id: 492843, transaction_count: 97, score: 19744.998046875 },9 { account_id: 373169, transaction_count: 93, score: 19553.697265625 },10 { account_id: 249078, transaction_count: 89, score: 19436.896484375 },11 { account_id: 77690, transaction_count: 90, score: 19418.017578125 }12]
5 và 1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
6constant
Tùy chọn constant
thay thế điểm cơ sở bằng một số cụ thể
Ghi chú
Các tùy chọn constant
và boost
có thể không được sử dụng cùng nhau
ví dụ
Ví dụ sau sử dụng chỉ mục mặc định trên bộ sưu tập
{ "$addFields": { "score": { "$meta": "searchScore" } }}
1 để truy vấn các trường { "$addFields": { "score": { "$meta": "searchScore" } }}
2 và 1[2 { account_id: 467651, transaction_count: 99, score: 19982 },3 { account_id: 271554, transaction_count: 96, score: 19851.822265625 },4 { account_id: 71148, transaction_count: 99, score: 19840 },5 { account_id: 408143, transaction_count: 100, score: 19836.76953125 },6 { account_id: 977774, transaction_count: 98, score: 19822.64453125 },7 { account_id: 187107, transaction_count: 96, score: 19754.470703125 },8 { account_id: 492843, transaction_count: 97, score: 19744.998046875 },9 { account_id: 373169, transaction_count: 93, score: 19553.697265625 },10 { account_id: 249078, transaction_count: 89, score: 19436.896484375 },11 { account_id: 77690, transaction_count: 90, score: 19418.017578125 }12]
5 bằng cách sử dụng toán tử. Trong truy vấn, người điều hành sử dụng 1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
6 với tùy chọn constant
để thay thế tất cả các kết quả điểm bằng { "$addFields": { "score": { "$meta": "searchScore" } }}
6 đối với các kết quả chỉ khớp với truy vấn đối với trường 1[2 { account_id: 467651, transaction_count: 99, score: 19982 },3 { account_id: 271554, transaction_count: 96, score: 19851.822265625 },4 { account_id: 71148, transaction_count: 99, score: 19840 },5 { account_id: 408143, transaction_count: 100, score: 19836.76953125 },6 { account_id: 977774, transaction_count: 98, score: 19822.64453125 },7 { account_id: 187107, transaction_count: 96, score: 19754.470703125 },8 { account_id: 492843, transaction_count: 97, score: 19744.998046875 },9 { account_id: 373169, transaction_count: 93, score: 19553.697265625 },10 { account_id: 249078, transaction_count: 89, score: 19436.896484375 },11 { account_id: 77690, transaction_count: 90, score: 19418.017578125 }12]
51db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
Truy vấn trên trả về các kết quả sau, trong đó điểm cho các tài liệu chỉ khớp với truy vấn đối với trường
1[2 { account_id: 467651, transaction_count: 99, score: 19982 },3 { account_id: 271554, transaction_count: 96, score: 19851.822265625 },4 { account_id: 71148, transaction_count: 99, score: 19840 },5 { account_id: 408143, transaction_count: 100, score: 19836.76953125 },6 { account_id: 977774, transaction_count: 98, score: 19822.64453125 },7 { account_id: 187107, transaction_count: 96, score: 19754.470703125 },8 { account_id: 492843, transaction_count: 97, score: 19744.998046875 },9 { account_id: 373169, transaction_count: 93, score: 19553.697265625 },10 { account_id: 249078, transaction_count: 89, score: 19436.896484375 },11 { account_id: 77690, transaction_count: 90, score: 19418.017578125 }12]
5 được thay thế bằng giá trị constant
được chỉ định1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score: 8.154602050781256 },7 {8 plot: "When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score: 511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score: 516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score: 521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score: 526 }27]
1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
0
1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
Ghi chú
Tùy chọn này chỉ có thể được sử dụng với người vận hành
Tùy chọn
1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
0 cho phép bạn định cấu hình cáchĐiểm tổng hợp của nhiều tài liệu nhúng phù hợp
Sửa đổi điểm của một toán tử sau khi tổng hợp điểm từ các tài liệu được nhúng phù hợp
Ghi chú
Tùy chọn chỉ mục, toán tử và tùy chọn tính điểm của Tìm kiếm bản đồ đang ở chế độ xem trước. Khi một chỉ mục Tìm kiếm Atlas trên một bộ bản sao hoặc một phân đoạn MongoDB đạt đến giới hạn hai tỷ tài liệu của Lucene, Tìm kiếm Atlas sẽ không lập chỉ mục các tài liệu mới hoặc áp dụng các bản cập nhật cho các tài liệu hiện có cho chỉ mục đó. Một giải pháp để khắc phục hạn chế này sẽ được áp dụng khi chúng tôi cung cấp tính năng này rộng rãi. Trong khi đó, nhóm Hỗ trợ đám mây MongoDB sẽ giúp khắc phục mọi sự cố liên quan đến việc sử dụng tính năng này như một phần trong hợp đồng của bạn
Lĩnh vực
Tùy chọn
1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
0 có các trường sauĐồng ruộng
Loại
sự cần thiết
Sự miêu tả
4{ "$setWindowFields": { "output": { "maxScore": { "$max": "$score" } } }}
chuỗi
Không bắt buộc
Định cấu hình cách kết hợp điểm của các tài liệu được nhúng phù hợp. Giá trị phải là một trong các chiến lược tổng hợp sau
5 - [Mặc định] Tổng điểm của tất cả các tài liệu được nhúng phù hợp{ "$setWindowFields": { "output": { "maxScore": { "$max": "$score" } } }}
{ "$setWindowFields": { "output": { "maxScore": { "$max": "$score" } } }}
6 - Chọn điểm cao nhất trong tất cả các tài liệu được nhúng phù hợp{ "$setWindowFields": { "output": { "maxScore": { "$max": "$score" } } }}
7 - Chọn điểm số thấp nhất trong tất cả các tài liệu được nhúng phù hợp{ "$setWindowFields": { "output": { "maxScore": { "$max": "$score" } } }}
8 - Chọn điểm trung bình [trung bình cộng] của tất cả các tài liệu được nhúng phù hợp. Tìm kiếm Atlas chỉ bao gồm điểm số của các tài liệu được nhúng phù hợp khi tính toán mức trung bình. Tìm kiếm Atlas không tính các tài liệu được nhúng không đáp ứng các vị từ truy vấn là tài liệu có điểm số bằng 0Nếu bỏ qua, mặc định là
{ "$setWindowFields": { "output": { "maxScore": { "$max": "$score" } } }}
5
0{ "$addFields": { "normalizedScore": { "$divide": [ "$score", "$maxScore" ] } }}
Không bắt buộc
Chỉ định sửa đổi điểm để áp dụng sau khi áp dụng chiến lược tổng hợp
ví dụ
Truy vấn mẫu sau đây sử dụng một chỉ mục có tên là
1[2 { account_id: 467651, transaction_count: 99, score: 19982 },3 { account_id: 271554, transaction_count: 96, score: 19851.822265625 },4 { account_id: 71148, transaction_count: 99, score: 19840 },5 { account_id: 408143, transaction_count: 100, score: 19836.76953125 },6 { account_id: 977774, transaction_count: 98, score: 19822.64453125 },7 { account_id: 187107, transaction_count: 96, score: 19754.470703125 },8 { account_id: 492843, transaction_count: 97, score: 19744.998046875 },9 { account_id: 373169, transaction_count: 93, score: 19553.697265625 },10 { account_id: 249078, transaction_count: 89, score: 19436.896484375 },11 { account_id: 77690, transaction_count: 90, score: 19418.017578125 }12]
3 trên bộ sưu tập { "$addFields": { "normalizedScore": { "$divide": [ "$score", "$maxScore" ] } }}
2. Chỉ mục định cấu hình trường { "$addFields": { "normalizedScore": { "$divide": [ "$score", "$maxScore" ] } }}
3 trên các tài liệu trong mảng { "$addFields": { "normalizedScore": { "$divide": [ "$score", "$maxScore" ] } }}
4, trường { "$addFields": { "normalizedScore": { "$divide": [ "$score", "$maxScore" ] } }}
5 cho trường { "$addFields": { "normalizedScore": { "$divide": [ "$score", "$maxScore" ] } }}
6 và { "$addFields": { "normalizedScore": { "$divide": [ "$score", "$maxScore" ] } }}
7 và trường { "$addFields": { "normalizedScore": { "$divide": [ "$score", "$maxScore" ] } }}
8 trên trường { "$addFields": { "normalizedScore": { "$divide": [ "$score", "$maxScore" ] } }}
9Truy vấn mẫu trên trường
{ "$addFields": { "normalizedScore": { "$divide": [ "$score", "$maxScore" ] } }}
4, chứa một mảng tài liệu, bao gồm giai đoạn boost
1 để giới hạn kết quả đầu ra ở mức boost
2 kết quả và giai đoạn 1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
2 đểLoại trừ tất cả các trường ngoại trừ
boost
4 và
9{ "$addFields": { "normalizedScore": { "$divide": [ "$score", "$maxScore" ] } }}
Thêm trường có tên
6 áp dụng chiến lược tổng hợp và sửa đổi thêm điểm số sau1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
Ghi chú
Bạn có thể sử dụng bên trong tùy chọn
6 của nhà điều hành1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
boost
9. Tuy nhiên, đối với điểm số của hàm yêu cầu tùy chọn
7, trường số mà bạn chỉ định là1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score: 8.154602050781256 },7 {8 plot: "When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score: 511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score: 516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score: 521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score: 526 }27]
7 cho biểu thức phải nằm trong toán tử1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score: 8.154602050781256 },7 {8 plot: "When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score: 511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score: 516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score: 521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score: 526 }27]
7. Ví dụ: trong truy vấn mẫu bên dưới, trường1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score: 8.154602050781256 },7 {8 plot: "When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score: 511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score: 516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score: 521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score: 526 }27]
constant
3 được chỉ định bên trong tùy chọn
6 của toán tử1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
constant
5 trên dòng 24 nằm bên trong đường dẫn của toán tửconstant
6
4 trên dòng 4{ "$addFields": { "normalizedScore": { "$divide": [ "$score", "$maxScore" ] } }}
Truy vấn tìm kiếm các tài khoản đã mua constant
8 và nhân lần mua constant
8 lớn nhất [theo số lượng cổ phần] với giá trị
1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
00 của số lượng giao dịch mà tài khoản đã thực hiện trong khoảng thời gian này. Nó xếp hạng các tài khoản dựa trên những điều sau đâySố lượng
constant
8 đã mua trong một giao dịchSố giao dịch kỳ trước
1db.transactions.aggregate[{2 "$search": {3 "embeddedDocument": {4 "path": "transactions",5 "operator": {6 "compound": {7 "must": [8 {9 "text": {10 "path": "transactions.symbol",11 "query": "amd"12 }13 },14 {15 "text": {16 "path": "transactions.transaction_code",17 "query": "buy"18 }19 }20 ],21 "score": {22 "function": {23 "path": {24 "value": "transactions.amount",25 "undefined": 1.026 }27 }28 }29 }30 },31 "score": {32 "embedded": {33 "aggregate": "maximum",34 "outerScore": {35 "function": {36 "multiply": [37 {38 "log1p": {39 "path": {40 "value": "transaction_count"41 }42 }43 },44 {45 "score": "relevance"46 }47 ]48 }49 }50 }51 }52 }53 }54},55{ "$limit": 10 },56{57 "$project": {58 "_id": 0,59 "account_id": 1,60 "transaction_count": 1,61 "score": { $meta: "searchScore" }62 }63}]
Atlas Search xếp hạng cao các tài khoản đã thực hiện nhiều giao dịch trong giai đoạn trước và mua nhiều constant
8 trong một giao dịch
1[2 { account_id: 467651, transaction_count: 99, score: 19982 },3 { account_id: 271554, transaction_count: 96, score: 19851.822265625 },4 { account_id: 71148, transaction_count: 99, score: 19840 },5 { account_id: 408143, transaction_count: 100, score: 19836.76953125 },6 { account_id: 977774, transaction_count: 98, score: 19822.64453125 },7 { account_id: 187107, transaction_count: 96, score: 19754.470703125 },8 { account_id: 492843, transaction_count: 97, score: 19744.998046875 },9 { account_id: 373169, transaction_count: 93, score: 19553.697265625 },10 { account_id: 249078, transaction_count: 89, score: 19436.896484375 },11 { account_id: 77690, transaction_count: 90, score: 19418.017578125 }12]
1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
1
1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
Tùy chọn
1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
1 cho phép bạn thay đổi điểm số cuối cùng của tài liệu bằng trường số. Bạn có thể chỉ định trường số để tính điểm cuối cùng thông qua một. Nếu kết quả cuối cùng của điểm chức năng nhỏ hơn 1db.transactions.aggregate[{2 "$search": {3 "embeddedDocument": {4 "path": "transactions",5 "operator": {6 "compound": {7 "must": [8 {9 "text": {10 "path": "transactions.symbol",11 "query": "amd"12 }13 },14 {15 "text": {16 "path": "transactions.transaction_code",17 "query": "buy"18 }19 }20 ],21 "score": {22 "function": {23 "path": {24 "value": "transactions.amount",25 "undefined": 1.026 }27 }28 }29 }30 },31 "score": {32 "embedded": {33 "aggregate": "maximum",34 "outerScore": {35 "function": {36 "multiply": [37 {38 "log1p": {39 "path": {40 "value": "transaction_count"41 }42 }43 },44 {45 "score": "relevance"46 }47 ]48 }49 }50 }51 }52 }53 }54},55{ "$limit": 10 },56{57 "$project": {58 "_id": 0,59 "account_id": 1,60 "transaction_count": 1,61 "score": { $meta: "searchScore" }62 }63}]
9, Atlas Search sẽ thay thế điểm bằng 1db.transactions.aggregate[{2 "$search": {3 "embeddedDocument": {4 "path": "transactions",5 "operator": {6 "compound": {7 "must": [8 {9 "text": {10 "path": "transactions.symbol",11 "query": "amd"12 }13 },14 {15 "text": {16 "path": "transactions.transaction_code",17 "query": "buy"18 }19 }20 ],21 "score": {22 "function": {23 "path": {24 "value": "transactions.amount",25 "undefined": 1.026 }27 }28 }29 }30 },31 "score": {32 "embedded": {33 "aggregate": "maximum",34 "outerScore": {35 "function": {36 "multiply": [37 {38 "log1p": {39 "path": {40 "value": "transaction_count"41 }42 }43 },44 {45 "score": "relevance"46 }47 ]48 }49 }50 }51 }52 }53 }54},55{ "$limit": 10 },56{57 "$project": {58 "_id": 0,59 "account_id": 1,60 "transaction_count": 1,61 "score": { $meta: "searchScore" }62 }63}]
9Ghi chú
Bạn có thể sử dụng
1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
1 bên trong tùy chọn 1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
6 của nhà điều hành boost
9. Tuy nhiên, đối với các biểu thức điểm số của hàm yêu cầu tùy chọn 1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score: 8.154602050781256 },7 {8 plot: "When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score: 511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score: 516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score: 521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score: 526 }27]
7, trường số mà bạn chỉ định là 1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score: 8.154602050781256 },7 {8 plot: "When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score: 511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score: 516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score: 521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score: 526 }27]
7 cho biểu thức phải nằm trong toán tử 1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score: 8.154602050781256 },7 {8 plot: "When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score: 511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score: 516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score: 521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score: 526 }27]
7Biểu thức
Sử dụng các biểu thức sau với tùy chọn
1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
1 để thay đổi điểm số cuối cùng của tài liệuCác biểu thức số học, cộng hoặc nhân một dãy số
Các biểu thức không đổi, cho phép một số trong điểm số của hàm
Các biểu thức phân rã Gaussian, phân rã hoặc giảm điểm bằng cách nhân với tốc độ xác định
Biểu thức đường dẫn, kết hợp giá trị trường số được lập chỉ mục vào điểm hàm
Biểu thức điểm, trả về điểm phù hợp do Tìm kiếm Atlas chỉ định
Biểu thức đơn nguyên, là biểu thức nhận một đối số duy nhất. Trong Atlas Search, bạn có thể tính toán log10[x] hoặc log10[x+1] của một số cụ thể
ví dụ
Các ví dụ sau sử dụng chỉ mục mặc định trên bộ sưu tập
{ "$addFields": { "score": { "$meta": "searchScore" } }}
1 để truy vấn trường 1[2 { account_id: 467651, transaction_count: 99, score: 19982 },3 { account_id: 271554, transaction_count: 96, score: 19851.822265625 },4 { account_id: 71148, transaction_count: 99, score: 19840 },5 { account_id: 408143, transaction_count: 100, score: 19836.76953125 },6 { account_id: 977774, transaction_count: 98, score: 19822.64453125 },7 { account_id: 187107, transaction_count: 96, score: 19754.470703125 },8 { account_id: 492843, transaction_count: 97, score: 19744.998046875 },9 { account_id: 373169, transaction_count: 93, score: 19553.697265625 },10 { account_id: 249078, transaction_count: 89, score: 19436.896484375 },11 { account_id: 77690, transaction_count: 90, score: 19418.017578125 }12]
5. Các truy vấn mẫu bao gồm giai đoạn boost
1 để giới hạn đầu ra ở kết quả { "$addFields": { "score": { "$meta": "searchScore" } }}
6 và giai đoạn 1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
2 để loại trừ tất cả các trường ngoại trừ 1[2 { account_id: 467651, transaction_count: 99, score: 19982 },3 { account_id: 271554, transaction_count: 96, score: 19851.822265625 },4 { account_id: 71148, transaction_count: 99, score: 19840 },5 { account_id: 408143, transaction_count: 100, score: 19836.76953125 },6 { account_id: 977774, transaction_count: 98, score: 19822.64453125 },7 { account_id: 187107, transaction_count: 96, score: 19754.470703125 },8 { account_id: 492843, transaction_count: 97, score: 19744.998046875 },9 { account_id: 373169, transaction_count: 93, score: 19553.697265625 },10 { account_id: 249078, transaction_count: 89, score: 19436.896484375 },11 { account_id: 77690, transaction_count: 90, score: 19418.017578125 }12]
5 và 1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
6Bình thường hóa Điểm số
Bạn có thể bình thường hóa điểm truy vấn của mình trong phạm vi từ
1db.transactions.aggregate[{2 "$search": {3 "embeddedDocument": {4 "path": "transactions",5 "operator": {6 "compound": {7 "must": [8 {9 "text": {10 "path": "transactions.symbol",11 "query": "amd"12 }13 },14 {15 "text": {16 "path": "transactions.transaction_code",17 "query": "buy"18 }19 }20 ],21 "score": {22 "function": {23 "path": {24 "value": "transactions.amount",25 "undefined": 1.026 }27 }28 }29 }30 },31 "score": {32 "embedded": {33 "aggregate": "maximum",34 "outerScore": {35 "function": {36 "multiply": [37 {38 "log1p": {39 "path": {40 "value": "transaction_count"41 }42 }43 },44 {45 "score": "relevance"46 }47 ]48 }49 }50 }51 }52 }53 }54},55{ "$limit": 10 },56{57 "$project": {58 "_id": 0,59 "account_id": 1,60 "transaction_count": 1,61 "score": { $meta: "searchScore" }62 }63}]
9 đến 1db.movies.aggregate[[2 {3 $search: {4 "compound": {5 "should": [{6 "text": {7 "query": "tower",8 "path": "plot"9 }10 },11 {12 "text": {13 "query": "tower",14 "path": "title",15 "score": { "constant": { "value": 5 } }16 }17 }]18 }19 }20 },21 {22 $project: {23 "_id": 0,24 "title": 1,25 "score": { "$meta": "searchScore" }26 }27 }28]]
23 trong các giai đoạn tiếp theo của quy trình tổng hợp của bạn. Bạn có thể sử dụng các giai đoạn sau sau giai đoạn của mình theo thứ tự sau để bình thường hóa điểm số{ "$addFields": { "score": { "$meta": "searchScore" } }}
{ "$setWindowFields": { "output": { "maxScore": { "$max": "$score" } } }}
{ "$addFields": { "normalizedScore": { "$divide": [ "$score", "$maxScore" ] } }}
ví dụ
Các ví dụ sau minh họa cách chuẩn hóa điểm số cho một số truy vấn đối với bộ sưu tập
{ "$addFields": { "score": { "$meta": "searchScore" } }}
1 ở phần trước bằng cách sử dụng các giai đoạn và sau giai đoạn