MongoDB Search 또는 MongoDB Vector Search 쿼리 에서 반환된 모든 문서 에는 관련성에 따라 점수가 할당되며, 결과 설정하다 에 포함된 문서는 가장 높은 점수부터 가장 낮은 점수 순으로 반환됩니다.
사용법
검색 결과에 각 문서의 점수를 포함하려면 집계 파이프라인에서 $project 단계를 사용하세요.
For the
$searchstage, thescorefield takes the$metaexpression, which requires thesearchScorevalue. You can also specify thesearchScoreDetailsvalue for thescoreDetailsfield$metaexpression for a detailed breakdown of the score.For the
$vectorSearchstage, thescorefield takes the$metaexpression, which requires thevectorSearchScorevalue to return the score of each document in your vector search results.
참고
다음 기능도 있습니다.
searchScore$search쿼리에서만 사용 가능vectorSearchScore$vectorSearch쿼리에서만 사용 가능.
다른 쿼리에서 searchScore 및 vectorSearchScore를 사용하는 경우, MongoDB는 v8.2부터 경고를 로그합니다.
예시
다음 쿼리는 $project 단계를 사용하여 반환된 문서에 score라는 이름의 필드를 추가합니다.
1 db.movies.aggregate([ 2 { 3 "$search": { 4 "text": { 5 <operator-specification> 6 } 7 } 8 }, 9 { 10 "$project": { 11 "<field-to-include>": 1, 12 "<field-to-exclude>": 0, 13 "score": { "$meta": "searchScore" } 14 } 15 } 16 ])
1 db.movies.aggregate([ 2 { 3 "$search": { 4 "text": { 5 <operator-specification> 6 }, 7 "scoreDetails": true 8 } 9 }, 10 { 11 "$project": { 12 "<field-to-include>": 1, 13 "<field-to-exclude>": 0, 14 "scoreDetails": { "$meta": "searchScoreDetails" } 15 } 16 } 17 ])
자세한 내용은 점수 상세 정보 반환을 참조하세요.
1 db.movies.aggregate([ 2 { 3 "$vectorSearch": { 4 <query-syntax> 5 } 6 }, 7 { 8 "$project": { 9 "<field-to-include>": 1, 10 "<field-to-exclude>": 0, 11 "score": { "$meta": "vectorSearchScore" } 12 } 13 } 14 ])
자세한 학습 은 MongoDB 벡터 검색 점수 산정을 참조하세요.
행동
반환된 문서에 할당된 점수는 문서 메타데이터의 일부입니다. 집계 파이프라인에서 $project 단계를 사용하여 반환된 각 문서의 점수를 결과 집합과 함께 포함할 수 있습니다. 문서는 가장 높은 점수부터 가장 낮은 점수 순으로 반환됩니다. 문서의 점수에 영향을 미치는 요소는 다음과 같이 다양합니다.
루센 점수 알고리즘에 대해 자세히 학습하려면 루센 문서를 참조하세요.
추가 옵션
기본값 채점 동작 외에도 MongoDB Search는 다음 옵션을 지원합니다.
고려 사항
결과의 여러 문서에 동일한 점수가 있는 경우 결과의 문서 순서는 비결정적입니다. MongoDB Search 결과가 정해진 순서를 갖도록 하려면 단계에 $search 정렬 옵션을 포함하여 고유한 필드 기준으로 결과를 정렬합니다. 정렬 옵션을 사용하여 결과를 점수별로 오름차순으로 정렬하여 반환할 수도 있습니다. 자세히 학습 MongoDB 검색 결과 정렬 및 점수별 정렬 예시를 참조하세요.
On separate Search Nodes, each node assigns documents different internal Lucene IDs used for sorting when scores are identical. When sorting and paginating results, the mongot process on the node that is processing the query might include documents from other nodes if their internal IDs have greater pagination order than the token. To prevent this, use $match after $search to exclude documents by their _id.
배열 값을 쿼리할 때 MongoDB Search는 배열 에서 쿼리 와 일치하는 값이 더 많을수록 더 높은 점수를 할당합니다.