Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
Click here >
Docs Menu
Docs Home
/ /

결과에서 문서 점수 매기기

MongoDB Search 또는 MongoDB Vector Search 쿼리 에서 반환된 모든 문서 에는 관련성에 따라 점수가 할당되며, 결과 설정하다 에 포함된 문서는 가장 높은 점수부터 가장 낮은 점수 순으로 반환됩니다.

검색 결과에 각 문서의 점수를 포함하려면 집계 파이프라인에서 $project 단계를 사용하세요.

  • For the $search stage, the score field takes the $meta expression, which requires the searchScore value. You can also specify the searchScoreDetails value for the scoreDetails field $meta expression for a detailed breakdown of the score.

  • For the $vectorSearch stage, the score field takes the $meta expression, which requires the vectorSearchScore value to return the score of each document in your vector search results.

참고

다음 기능도 있습니다.

  • searchScore $search 쿼리에서만 사용 가능

  • vectorSearchScore $vectorSearch 쿼리에서만 사용 가능.

다른 쿼리에서 searchScorevectorSearchScore를 사용하는 경우, MongoDB는 v8.2부터 경고를 로그합니다.

예시

다음 쿼리는 $project 단계를 사용하여 반환된 문서에 score라는 이름의 필드를 추가합니다.

1db.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])
1db.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])

자세한 내용은 점수 상세 정보 반환을 참조하세요.

1db.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는 다음 옵션을 지원합니다.

  • 특정 문서에 할당된 점수를 수정합니다.

  • 점수 세부 정보 옵션을 사용하여 점수의 세부 분석을 반환합니다.

  • 검색 점수를 정규화합니다.

결과의 여러 문서에 동일한 점수가 있는 경우 결과의 문서 순서는 비결정적입니다. 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는 배열 에서 쿼리 와 일치하는 값이 더 많을수록 더 높은 점수를 할당합니다.

MongoDB Search 쿼리에서 추가 score 옵션을 사용하는 방법에 대한 예는 다음 페이지를 참조하세요.

몇 가지 일반적인 MongoDB Search 쿼리에서 score 필드 사용하는 방법에 대한 예는 다음 페이지를 참조하세요.

돌아가기

검색 옵션

이 페이지의 내용