MarkLogic 12 EA 1 Product Documentation
cts.relevanceInfo

cts.relevanceInfo(
   [node as Node],
   [output-kind as String]
) as Object

Summary

Return the relevance score computation report for a node.

Parameters
node A node. Typically this is an item in the result sequence of a cts.search operation. If this parameter is omitted, the context node is used.
output-kind The output kind. It can be either "object" or "element". With "object", the built-in returns an object. With "element", the built-in returns an XML element node. The default is "object".

Usage Notes

This function returns a JavaScript object that contains details about the score computation only if the following conditions are met: The node parameter or context node is the result of a cts.search call that included the relevance-trace option; and the score is non-zero. For example, you will not get a report if you use the score-zero option on your cts.search, if the search returns no results, or if node is not the result of cts.search.

The score computation reflects the scoring method specified in the cts.search expression, if any. The score-zero and score-random methods do not generate a report.

Collecting score computation details with which to generate this report is costly, so using the relevance-trace option will slow down your search significantly.

Example

const x = cts.search("dog", ["relevance-trace"]);
cts.relevanceInfo(fn.head(x));
=>
{
  "score":{
    "formula":"(256*scoreSum/weightSum)+(256*qualityWeight*documentQuality)",
    "computation":"(256*8/1)+(256*1*0)",
    "value":2048
  },
  "confidence":{
    "formula":"sqrt(score/(256*8*maxlogtf*maxidf))",
    "computation":"sqrt(2048/(256*8*18*log(1)))",
    "value":0
  },
  "fitness":{
    "formula":"sqrt(score/(256*8*maxlogtf*avgidf))",
    "computation":"sqrt(2048/(256*8*18*(0/1)))",
    "value":0.2357023
  },
  "uri":"othello.xml",
  "path":"fn:doc('othello.xml')",
  "term":{
    "weight":0.125,
    "score":{
      "formula":"8*weight*logtf",
      "computation":"1*8",
      "value":8
    },
    "key":"5166487143365525844",
    "annotation":"word(\"dog\")"
  }
}
}

Example

// The BM25 scoring method has additional variables in the score calculation:
//     length: the length of the resultant document
//     bm25lw: the weight of the resultant document's length on the score calculation
//     avgdl: the average length of all documents in the target database
const x = cts.search("dog", ["relevance-trace", "score-bm25", "bm25-length-weight=0.75"]);
cts.relevanceInfo(fn.head(x));
=>
{
  "score": {
    "formula": "(256*scoreSum/weightSum)+(256*qualityWeight*documentQuality)",
    "computation": "(256*252/1)+(256*1*0)",
    "value": 64512
  },
  "confidence": {
    "formula": "sqrt(score/(256*8*maxlogtf*maxidf))",
    "computation": "sqrt(64512/(256*8*18*log(7162)))",
    "value": 0.4440144
  },
  "fitness": {
    "formula": "sqrt(score/(256*8*maxlogtf*avgidf))",
    "computation": "sqrt(64512/(256*8*18*(5.16297/1)))",
    "value": 0.5821959
    },
  "uri": "/GQEYYYADLOGMMAYD/20161171438962/1/283R.xml",
  "path": "fn:doc('/GQEYYYADLOGMMAYD/20161171438962/1/283R.xml')",
  "term": {
    "weight": 5.25,
    "score": {
    "formula": "8*weight*round(logtf/(length/avgdl*bm25lw+(1-bm25lw)))",
    "computation": "42*round(5/(9004/10799.3*0.75+(1-0.75)))",
    "resolution": "42*6",
    "value": 252
    },
  "key": "848360095981220189",
  "annotation": "word(\"dog\")"
  }
}
}
Powered by MarkLogic Server | Terms of Use | Privacy Policy