Alternative and User-defined Scoring

You can use query templating to specify alternative scoring algorithms to use, other than the default, to customize how CONTAINS is scored, and to enable SDATA to be used as part of the scoring expressions. In this way, you can mathematically define the scoring expression using not only pre-defined scoring components, but also SDATA components.

With alternative user-defined scoring, you can:

  • Specify the scoring expressions of terms by defining arithmetic expressions that define how the query should be scored, using

    • predefined scoring algorithms: DISCRETE, OCCURRENCE, RELEVANCE, and COMPLETION;

    • arithmetic operations: plus, minus, multiply, divide;

    • arithmetic functions: ABS(n), finding the absolute value of n ; LOG(n), finding the base-10 logarithmic value of n;

    • Numeric literals.

  • Specify the scoring expressions at the term level.

  • Specify terms that should not be taken into account when calculating the score.

  • Specify how the score from child elements of OR and AND operators should be merged.

  • Use SDATA that stores numeric or DATETIME values to affect the final score of the document.

The following example specifies an alternative scoring algorithm:

select id from docs where CONTAINS (text,
'<query>        
 <textquery grammar="CONTEXT" lang="english"> mustang  </textquery>     
 <score datatype="float" algorithm="DEFAULT"/>     
</query>')>0

The following query templating example includes SDATA values as part of the final score:

select id from docs where CONTAINS (text,
'<query>
<textquery grammar="CONTEXT" lang="english"> mustang </textquery>
<score datatype="float" algorithm="DEFAULT" normalization_expr ="doc_score+SDATA(price)"/>
</query>')>0"