FULLTEXTSCORE - Query language in Cosmos DB (in Azure and Fabric)

The FULLTEXTSCORE function returns a BM25 score value used to filter, sort, or project full-text search relevance.

Syntax

FULLTEXTSCORE(<property_path>, <string_expr1>, <string_expr2>, ...)

Arguments

Description
property_path The property path to search.
string_expr1 The first term to find.
string_expr2 The second term to find.

Return types

Returns a BM25 score that you can use to filter, sort, or project results by full-text search relevance.

Examples

This section contains examples of how to use this query language construct.

Full text score with ORDER BY RANK

In this example, the FULLTEXTSCORE function is used with ORDER BY RANK to sort from highest relevancy to lowest relevancy.

SELECT TOP 10 c.text
FROM c
ORDER BY RANK FULLTEXTSCORE(c.text, "keyword")

Full text score with WHERE and ORDER BY RANK

In this example, the FULLTEXTSCORE function is used in the ORDER BY RANK clause, and FULLTEXTCONTAINS is used in the WHERE clause.

SELECT TOP 10 c.text
FROM c
WHERE FULLTEXTCONTAINS(c.text, "keyword1")
ORDER BY RANK FULLTEXTSCORE(c.text, "keyword1", "keyword2")

Project a full text score

In this example, the FULLTEXTSCORE function is projected in the SELECT clause, used to filter results in the WHERE clause, and used to sort results in the ORDER BY RANK clause.

SELECT TOP 10
    c.text,
    FULLTEXTSCORE(c.text, "keyword") AS score
FROM c
WHERE FULLTEXTSCORE(c.text, "keyword") > 0
ORDER BY RANK FULLTEXTSCORE(c.text, "keyword")

Remarks

  • This function requires enrollment in the Azure Cosmos DB NoSQL Full Text Search feature.
  • This function requires a Full Text Index.
  • This function can be used in a WHERE clause, in an ORDER BY RANK clause, as an argument in an RRF system function, or in a top-level projection when the query also contains a matching ORDER BY RANK scoring expression.