Retorne os Detalhes da Pontuação
Nesta página
Você pode usar a opção booleana scoreDetails
em seu estágio $search
para um detalhamento detalhado da pontuação para cada documento nos resultados da query. Para visualizar os metadados, você deve utilizar a expressão $meta no estágio $project
.
Sintaxe
{ "$search": { "<operator>": { <operator-specification> }, "scoreDetails": true | false } }, { "$project": { "scoreDetails": {"$meta": "searchScoreDetails"} } }
Opções
No estágio $search, a opção booleana scoreDetails
assume um dos seguintes valores:
true
- para incluir detalhes da pontuação para os documentos nos resultados. Se definido comotrue
, o Atlas Search retorna um detalhamento detalhado da pontuação para cada documento no resultado. Para saber mais, consulte Saída.false
- para excluir detalhes do detalhamento da pontuação dos resultados. (Padrão)
Se omitido, a opção scoreDetails
será padronizada como false
.
No estágio $project, o campo scoreDetails
assume a expressão $meta, que requer o seguinte valor:
| Retorna um detalhamento detalhado da pontuação para cada documento nos resultados. |
Saída
A opção scoreDetails
retorna os seguintes campos na array details
dentro do objeto scoreDetails
para cada documento no resultado:
Campo | Tipo | Descrição |
---|---|---|
| float | Contribuição para a pontuação de um subconjunto da fórmula de pontuação. O A fórmula de pontuação varia de acordo com o operador usado na consulta. Por exemplo, o Atlas Search usa a seguinte fórmula de pontuação para uma consulta composta com operadores de texto e de proximidade: |
| string | Subconjunto da fórmula de pontuação, incluindo detalhes sobre como o documento foi pontuado e os fatores considerados no cálculo da pontuação. O nível superior Para saber mais, consulte Fatores que contribuem para a pontuação. |
| Array de objetos | Detalhamento da pontuação para cada correspondência no documento com base no subconjunto da fórmula de pontuação. O valor é uma array de objetos de detalhes de pontuação, recursivos em estrutura. |
Fatores que contribuem para a pontuação
Para BM25Similarity
, a pontuação é calculada como boost * idf * tf
. O Atlas Search leva em conta os seguintes fatores BM25Similarity
para calcular a pontuação:
| Aumentar a importância do termo. | |
| Frequência do termo da query. | |
| Frequência de documentos inversa da query. Atlas Search calcula a frequência utilizando a seguinte fórmula:
onde:
| |
| Frequência do termo. Atlas Search calcula a frequência utilizando a seguinte fórmula:
onde:
|
Para a função de decaimento da distância, a pontuação é calculada como pivot / (pivot +
abs(fieldValue - origin))
. O Atlas Search leva em conta os seguintes fatores para calcular a pontuação:
| Valor para pesquisar próximo. Este é o ponto de origem do qual a proximidade dos resultados é medida. |
| Valor do campo que você está consultando no documento. Quanto mais próximo o |
| Valor especificado como ponto de referência para tornar a pontuação igual a |
Exemplos
Os exemplos a seguir mostram como recuperar os detalhes das pontuações nos resultados para o seguinte:
A query é executada usando operadores text, near, composto e embeddedDocument .
Query com pontuações modificadas usando expressão de opção
function
.
Dica
Para visualizar detalhes da pontuação recursivamente nas matrizes de objetos, configure as configurações em mongosh
executando o seguinte:
config.set('inspectDepth', Infinity)
Exemplos de operador
Os exemplos a seguir demonstram como recuperar um detalhamento da pontuação usando a opção $search
scoreDetails
para o documento nos resultados da query dos operadores text, near, composta e embeddedDocument .
Exemplos de pontuação personalizada
Os exemplos a seguir demonstram como recuperar um detalhamento da pontuação usando a opção $search
scoreDetails
para o documento nos resultados da query de exemplo de expressão em relação à collection sample_mflix.movies
.
1 db.movies.aggregate([{ 2 "$search": { 3 "text": { 4 "path": "title", 5 "query": "men", 6 "score": { 7 "function":{ 8 "multiply":[ 9 { 10 "path": { 11 "value": "imdb.rating", 12 "undefined": 2 13 } 14 }, 15 { 16 "score": "relevance" 17 } 18 ] 19 } 20 } 21 }, 22 "scoreDetails": true 23 } 24 }, 25 { 26 $limit: 5 27 }, 28 { 29 $project: { 30 "_id": 0, 31 "title": 1, 32 "score": { "$meta": "searchScore" }, 33 "scoreDetails": {"$meta": "searchScoreDetails"} 34 } 35 }])
[ { title: 'Men...', score: 23.431293487548828, scoreDetails: { value: 23.431293487548828, description: 'FunctionScoreQuery($type:string/title:men, scored by (imdb.rating * scores)) [BM25Similarity], result of:', details: [ { value: 23.431293487548828, description: '(imdb.rating * scores)', details: [] } ] } }, { title: '12 Angry Men', score: 22.080968856811523, scoreDetails: { value: 22.080968856811523, description: 'FunctionScoreQuery($type:string/title:men, scored by (imdb.rating * scores)) [BM25Similarity], result of:', details: [ { value: 22.080968856811523, description: '(imdb.rating * scores)', details: [] } ] } }, { title: 'X-Men', score: 21.34803581237793, scoreDetails: { value: 21.34803581237793, description: 'FunctionScoreQuery($type:string/title:men, scored by (imdb.rating * scores)) [BM25Similarity], result of:', details: [ { value: 21.34803581237793, description: '(imdb.rating * scores)', details: [] } ] } }, { title: 'X-Men', score: 21.34803581237793, scoreDetails: { value: 21.34803581237793, description: 'FunctionScoreQuery($type:string/title:men, scored by (imdb.rating * scores)) [BM25Similarity], result of:', details: [ { value: 21.34803581237793, description: '(imdb.rating * scores)', details: [] } ] } }, { title: 'Matchstick Men', score: 21.05954933166504, scoreDetails: { value: 21.05954933166504, description: 'FunctionScoreQuery($type:string/title:men, scored by (imdb.rating * scores)) [BM25Similarity], result of:', details: [ { value: 21.05954933166504, description: '(imdb.rating * scores)', details: [] } ] } } ]
1 db.movies.aggregate([ 2 { 3 "$search": { 4 "text": { 5 "path": "title", 6 "query": "men", 7 "score": { 8 "function":{ 9 "constant": 3 10 } 11 } 12 }, 13 "scoreDetails": true 14 } 15 }, 16 { 17 $limit: 5 18 }, 19 { 20 $project: { 21 "_id": 0, 22 "title": 1, 23 "score": { "$meta": "searchScore" }, 24 "scoreDetails": {"$meta": "searchScoreDetails"} 25 } 26 } 27 ])
[ { title: 'Men Without Women', score: 3, scoreDetails: { value: 3, description: 'FunctionScoreQuery($type:string/title:men, scored by constant(3.0)) [BM25Similarity], result of:', details: [ { value: 3, description: 'constant(3.0)', details: [] } ] } }, { title: 'One Hundred Men and a Girl', score: 3, scoreDetails: { value: 3, description: 'FunctionScoreQuery($type:string/title:men, scored by constant(3.0)) [BM25Similarity], result of:', details: [ { value: 3, description: 'constant(3.0)', details: [] } ] } }, { title: 'Of Mice and Men', score: 3, scoreDetails: { value: 3, description: 'FunctionScoreQuery($type:string/title:men, scored by constant(3.0)) [BM25Similarity], result of:', details: [ { value: 3, description: 'constant(3.0)', details: [] } ] } }, { title: "All the King's Men", score: 3, scoreDetails: { value: 3, description: 'FunctionScoreQuery($type:string/title:men, scored by constant(3.0)) [BM25Similarity], result of:', details: [ { value: 3, description: 'constant(3.0)', details: [] } ] } }, { title: 'The Men', score: 3, scoreDetails: { value: 3, description: 'FunctionScoreQuery($type:string/title:men, scored by constant(3.0)) [BM25Similarity], result of:', details: [ { value: 3, description: 'constant(3.0)', details: [] } ] } } ]
1 db.movies.aggregate([ 2 { 3 "$search": { 4 "text": { 5 "path": "title", 6 "query": "shop", 7 "score": { 8 "function":{ 9 "gauss": { 10 "path": { 11 "value": "imdb.rating", 12 "undefined": 4.6 13 }, 14 "origin": 9.5, 15 "scale": 5, 16 "offset": 0, 17 "decay": 0.5 18 } 19 } 20 } 21 }, 22 "scoreDetails": true 23 } 24 }, 25 { 26 "$limit": 10 27 }, 28 { 29 "$project": { 30 "_id": 0, 31 "title": 1, 32 "score": { "$meta": "searchScore" }, 33 "scoreDetails": {"$meta": "searchScoreDetails"} 34 } 35 } 36 ])
[ { title: 'The Shop Around the Corner', score: 0.9471074342727661, scoreDetails: { value: 0.9471074342727661, description: 'FunctionScoreQuery($type:string/title:shop, scored by exp((max(0, |imdb.rating - 9.5| - 0.0)^2) / 2 * (5.0^2 / 2 * ln(0.5)))) [BM25Similarity], result of:', details: [ { value: 0.9471074342727661, description: 'exp((max(0, |imdb.rating - 9.5| - 0.0)^2) / 2 * (5.0^2 / 2 * ln(0.5)))', details: [] } ] } }, { title: 'Exit Through the Gift Shop', score: 0.9471074342727661, scoreDetails: { value: 0.9471074342727661, description: 'FunctionScoreQuery($type:string/title:shop, scored by exp((max(0, |imdb.rating - 9.5| - 0.0)^2) / 2 * (5.0^2 / 2 * ln(0.5)))) [BM25Similarity], result of:', details: [ { value: 0.9471074342727661, description: 'exp((max(0, |imdb.rating - 9.5| - 0.0)^2) / 2 * (5.0^2 / 2 * ln(0.5)))', details: [] } ] } }, { title: 'The Shop on Main Street', score: 0.9395227432250977, scoreDetails: { value: 0.9395227432250977, description: 'FunctionScoreQuery($type:string/title:shop, scored by exp((max(0, |imdb.rating - 9.5| - 0.0)^2) / 2 * (5.0^2 / 2 * ln(0.5)))) [BM25Similarity], result of:', details: [ { value: 0.9395227432250977, description: 'exp((max(0, |imdb.rating - 9.5| - 0.0)^2) / 2 * (5.0^2 / 2 * ln(0.5)))', details: [] } ] } }, { title: 'Chop Shop', score: 0.8849083781242371, scoreDetails: { value: 0.8849083781242371, description: 'FunctionScoreQuery($type:string/title:shop, scored by exp((max(0, |imdb.rating - 9.5| - 0.0)^2) / 2 * (5.0^2 / 2 * ln(0.5)))) [BM25Similarity], result of:', details: [ { value: 0.8849083781242371, description: 'exp((max(0, |imdb.rating - 9.5| - 0.0)^2) / 2 * (5.0^2 / 2 * ln(0.5)))', details: [] } ] } }, { title: 'Little Shop of Horrors', score: 0.8290896415710449, scoreDetails: { value: 0.8290896415710449, description: 'FunctionScoreQuery($type:string/title:shop, scored by exp((max(0, |imdb.rating - 9.5| - 0.0)^2) / 2 * (5.0^2 / 2 * ln(0.5)))) [BM25Similarity], result of:', details: [ { value: 0.8290896415710449, description: 'exp((max(0, |imdb.rating - 9.5| - 0.0)^2) / 2 * (5.0^2 / 2 * ln(0.5)))', details: [] } ] } }, { title: 'The Suicide Shop', score: 0.7257778644561768, scoreDetails: { value: 0.7257778644561768, description: 'FunctionScoreQuery($type:string/title:shop, scored by exp((max(0, |imdb.rating - 9.5| - 0.0)^2) / 2 * (5.0^2 / 2 * ln(0.5)))) [BM25Similarity], result of:', details: [ { value: 0.7257778644561768, description: 'exp((max(0, |imdb.rating - 9.5| - 0.0)^2) / 2 * (5.0^2 / 2 * ln(0.5)))', details: [] } ] } }, { title: 'A Woman, a Gun and a Noodle Shop', score: 0.6559237241744995, scoreDetails: { value: 0.6559237241744995, description: 'FunctionScoreQuery($type:string/title:shop, scored by exp((max(0, |imdb.rating - 9.5| - 0.0)^2) / 2 * (5.0^2 / 2 * ln(0.5)))) [BM25Similarity], result of:', details: [ { value: 0.6559237241744995, description: 'exp((max(0, |imdb.rating - 9.5| - 0.0)^2) / 2 * (5.0^2 / 2 * ln(0.5)))', details: [] } ] } }, { title: 'Beauty Shop', score: 0.6274620294570923, scoreDetails: { value: 0.6274620294570923, description: 'FunctionScoreQuery($type:string/title:shop, scored by exp((max(0, |imdb.rating - 9.5| - 0.0)^2) / 2 * (5.0^2 / 2 * ln(0.5)))) [BM25Similarity], result of:', details: [ { value: 0.6274620294570923, description: 'exp((max(0, |imdb.rating - 9.5| - 0.0)^2) / 2 * (5.0^2 / 2 * ln(0.5)))', details: [] } ] } } ]
1 db.movies.aggregate([{ 2 "$search": { 3 "text": { 4 "path": "title", 5 "query": "men", 6 "score": { 7 "function":{ 8 "path": { 9 "value": "imdb.rating", 10 "undefined": 4.6 11 } 12 } 13 } 14 }, 15 "scoreDetails": true 16 } 17 }, 18 { 19 $limit: 5 20 }, 21 { 22 $project: { 23 "_id": 0, 24 "title": 1, 25 "score": { "$meta": "searchScore" }, 26 "scoreDetails": {"$meta": "searchScoreDetails"} 27 } 28 }])
[ { title: '12 Angry Men', score: 8.899999618530273, scoreDetails: { value: 8.899999618530273, description: 'FunctionScoreQuery($type:string/title:men, scored by imdb.rating) [BM25Similarity], result of:', details: [ { value: 8.899999618530273, description: 'imdb.rating', details: [] } ] } }, { title: 'The Men Who Built America', score: 8.600000381469727, scoreDetails: { value: 8.600000381469727, description: 'FunctionScoreQuery($type:string/title:men, scored by imdb.rating) [BM25Similarity], result of:', details: [ { value: 8.600000381469727, description: 'imdb.rating', details: [] } ] } }, { title: 'No Country for Old Men', score: 8.100000381469727, scoreDetails: { value: 8.100000381469727, description: 'FunctionScoreQuery($type:string/title:men, scored by imdb.rating) [BM25Similarity], result of:', details: [ { value: 8.100000381469727, description: 'imdb.rating', details: [] } ] } }, { title: 'X-Men: Days of Future Past', score: 8.100000381469727, scoreDetails: { value: 8.100000381469727, description: 'FunctionScoreQuery($type:string/title:men, scored by imdb.rating) [BM25Similarity], result of:', details: [ { value: 8.100000381469727, description: 'imdb.rating', details: [] } ] } }, { title: 'The Best of Men', score: 8.100000381469727, scoreDetails: { value: 8.100000381469727, description: 'FunctionScoreQuery($type:string/title:men, scored by imdb.rating) [BM25Similarity], result of:', details: [ { value: 8.100000381469727, description: 'imdb.rating', details: [] } ] } } ]
1 db.movies.aggregate([{ 2 "$search": { 3 "text": { 4 "path": "title", 5 "query": "men", 6 "score": { 7 "function":{ 8 "score": "relevance" 9 } 10 } 11 }, 12 "scoreDetails": true 13 } 14 }, 15 { 16 $limit: 5 17 }, 18 { 19 $project: { 20 "_id": 0, 21 "title": 1, 22 "score": { "$meta": "searchScore" }, 23 "scoreDetails": {"$meta": "searchScoreDetails"} 24 } 25 }])
[ { title: 'Men...', score: 3.4457783699035645, scoreDetails: { value: 3.4457783699035645, description: 'FunctionScoreQuery($type:string/title:men, scored by scores) [BM25Similarity], result of:', details: [ { value: 3.4457783699035645, description: 'weight($type:string/title:men in 4705) [BM25Similarity], result of:', details: [ { value: 3.4457783699035645, description: 'score(freq=1.0), computed as boost * idf * tf from:', details: [ { value: 5.5606818199157715, description: 'idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:', details: [ { value: 90, description: 'n, number of documents containing term', details: [] }, { value: 23529, description: 'N, total number of documents with field', details: [] } ] }, { value: 0.6196683645248413, description: 'tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:', details: [ { value: 1, description: 'freq, occurrences of term within document', details: [] }, { value: 1.2000000476837158, description: 'k1, term saturation parameter', details: [] }, { value: 0.75, description: 'b, length normalization parameter', details: [] }, { value: 1, description: 'dl, length of field', details: [] }, { value: 2.868375301361084, description: 'avgdl, average length of field', details: [] } ] } ] } ] } ] } }, { title: 'The Men', score: 2.8848698139190674, scoreDetails: { value: 2.8848698139190674, description: 'FunctionScoreQuery($type:string/title:men, scored by scores) [BM25Similarity], result of:', details: [ { value: 2.8848698139190674, description: 'weight($type:string/title:men in 870) [BM25Similarity], result of:', details: [ { value: 2.8848698139190674, description: 'score(freq=1.0), computed as boost * idf * tf from:', details: [ { value: 5.5606818199157715, description: 'idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:', details: [ { value: 90, description: 'n, number of documents containing term', details: [] }, { value: 23529, description: 'N, total number of documents with field', details: [] } ] }, { value: 0.5187978744506836, description: 'tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:', details: [ { value: 1, description: 'freq, occurrences of term within document', details: [] }, { value: 1.2000000476837158, description: 'k1, term saturation parameter', details: [] }, { value: 0.75, description: 'b, length normalization parameter', details: [] }, { value: 2, description: 'dl, length of field', details: [] }, { value: 2.868375301361084, description: 'avgdl, average length of field', details: [] } ] } ] } ] } ] } }, { title: 'Simple Men', score: 2.8848698139190674, scoreDetails: { value: 2.8848698139190674, description: 'FunctionScoreQuery($type:string/title:men, scored by scores) [BM25Similarity], result of:', details: [ { value: 2.8848698139190674, description: 'weight($type:string/title:men in 6371) [BM25Similarity], result of:', details: [ { value: 2.8848698139190674, description: 'score(freq=1.0), computed as boost * idf * tf from:', details: [ { value: 5.5606818199157715, description: 'idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:', details: [ { value: 90, description: 'n, number of documents containing term', details: [] }, { value: 23529, description: 'N, total number of documents with field', details: [] } ] }, { value: 0.5187978744506836, description: 'tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:', details: [ { value: 1, description: 'freq, occurrences of term within document', details: [] }, { value: 1.2000000476837158, description: 'k1, term saturation parameter', details: [] }, { value: 0.75, description: 'b, length normalization parameter', details: [] }, { value: 2, description: 'dl, length of field', details: [] }, { value: 2.868375301361084, description: 'avgdl, average length of field', details: [] } ] } ] } ] } ] } }, { title: 'X-Men', score: 2.8848698139190674, scoreDetails: { value: 2.8848698139190674, description: 'FunctionScoreQuery($type:string/title:men, scored by scores) [BM25Similarity], result of:', details: [ { value: 2.8848698139190674, description: 'weight($type:string/title:men in 8368) [BM25Similarity], result of:', details: [ { value: 2.8848698139190674, description: 'score(freq=1.0), computed as boost * idf * tf from:', details: [ { value: 5.5606818199157715, description: 'idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:', details: [ { value: 90, description: 'n, number of documents containing term', details: [] }, { value: 23529, description: 'N, total number of documents with field', details: [] } ] }, { value: 0.5187978744506836, description: 'tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:', details: [ { value: 1, description: 'freq, occurrences of term within document', details: [] }, { value: 1.2000000476837158, description: 'k1, term saturation parameter', details: [] }, { value: 0.75, description: 'b, length normalization parameter', details: [] }, { value: 2, description: 'dl, length of field', details: [] }, { value: 2.868375301361084, description: 'avgdl, average length of field', details: [] } ] } ] } ] } ] } }, { title: 'Mystery Men', score: 2.8848698139190674, scoreDetails: { value: 2.8848698139190674, description: 'FunctionScoreQuery($type:string/title:men, scored by scores) [BM25Similarity], result of:', details: [ { value: 2.8848698139190674, description: 'weight($type:string/title:men in 8601) [BM25Similarity], result of:', details: [ { value: 2.8848698139190674, description: 'score(freq=1.0), computed as boost * idf * tf from:', details: [ { value: 5.5606818199157715, description: 'idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:', details: [ { value: 90, description: 'n, number of documents containing term', details: [] }, { value: 23529, description: 'N, total number of documents with field', details: [] } ] }, { value: 0.5187978744506836, description: 'tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:', details: [ { value: 1, description: 'freq, occurrences of term within document', details: [] }, { value: 1.2000000476837158, description: 'k1, term saturation parameter', details: [] }, { value: 0.75, description: 'b, length normalization parameter', details: [] }, { value: 2, description: 'dl, length of field', details: [] }, { value: 2.868375301361084, description: 'avgdl, average length of field', details: [] } ] } ] } ] } ] } } ]
1 db.movies.aggregate([{ 2 "$search": { 3 "text": { 4 "path": "title", 5 "query": "men", 6 "score": { 7 "function": { 8 "log": { 9 "path": { 10 "value": "imdb.rating", 11 "undefined": 10 12 } 13 } 14 } 15 } 16 }, 17 "scoreDetails": true 18 } 19 }, 20 { 21 $limit: 5 22 }, 23 { 24 $project: { 25 "_id": 0, 26 "title": 1, 27 "score": { "$meta": "searchScore" }, 28 "scoreDetails": {"$meta": "searchScoreDetails"} 29 } 30 }])
[ { title: '12 Angry Men', score: 0.9493899941444397, scoreDetails: { value: 0.9493899941444397, description: 'FunctionScoreQuery($type:string/title:men, scored by log(imdb.rating)) [BM25Similarity], result of:', details: [ { value: 0.9493899941444397, description: 'log(imdb.rating)', details: [] } ] } }, { title: 'The Men Who Built America', score: 0.9344984292984009, scoreDetails: { value: 0.9344984292984009, description: 'FunctionScoreQuery($type:string/title:men, scored by log(imdb.rating)) [BM25Similarity], result of:', details: [ { value: 0.9344984292984009, description: 'log(imdb.rating)', details: [] } ] } }, { title: 'No Country for Old Men', score: 0.9084849953651428, scoreDetails: { value: 0.9084849953651428, description: 'FunctionScoreQuery($type:string/title:men, scored by log(imdb.rating)) [BM25Similarity], result of:', details: [ { value: 0.9084849953651428, description: 'log(imdb.rating)', details: [] } ] } }, { title: 'X-Men: Days of Future Past', score: 0.9084849953651428, scoreDetails: { value: 0.9084849953651428, description: 'FunctionScoreQuery($type:string/title:men, scored by log(imdb.rating)) [BM25Similarity], result of:', details: [ { value: 0.9084849953651428, description: 'log(imdb.rating)', details: [] } ] } }, { title: 'The Best of Men', score: 0.9084849953651428, scoreDetails: { value: 0.9084849953651428, description: 'FunctionScoreQuery($type:string/title:men, scored by log(imdb.rating)) [BM25Similarity], result of:', details: [ { value: 0.9084849953651428, description: 'log(imdb.rating)', details: [] } ] } } ]