Full-text index functions¶
Use the following GQL functions with full-text indexes.
To use these functions, you need to create a full-text index first. For more information, see CREATE FULLTEXT INDEX.
ftscore()¶
Returns the score of BM25 relevance between a STRING value stored by an indexed property and a given query string.
The score is a non-negative floating-point number in the range [0, +∞). A higher score indicates greater relevance to the query string.
Null behavior: error
This function must be used together with one of the following clauses:
- A WHERE clause that filters results by score (for example,
score > 0). - A LIMIT clause that limits the number of results returned.
For more information, see the Examples below.
Function signature¶
ftscore(property_value_expression String, query String) -> DOUBLE
property_value_expression: The property value expression that references aSTRINGproperty of a node type or edge type. A full-text index must already be created on this property.query: The query string against which the property value is compared to calculate the relevance score.
Examples¶
The following examples assume the full-text index ft_movie introduced in CREATE FULLTEXT INDEX is already created.
Filter by relevance score¶
'''
USE movie
MATCH (v@Movie)
LET score= ftscore(v.name, 'Uncle')
FILTER WHERE score > 0
RETURN v.name AS movie_name, score
'''
Return:
+------------+--------------------+
| movie_name | score |
+------------+--------------------+
| My Uncle | 3.1877928754939955 |
+------------+--------------------+
Limit the number of results returned¶
'''
USE movie
MATCH (v@Movie)
LET score= ftscore(v.name, 'Star')
RETURN v.name AS movie_name, score
ORDER BY score ASC
LIMIT 3
'''
Return:
+-------------------------------------+--------------------+
| movie_name | score |
+-------------------------------------+--------------------+
| Star Trek III: The Search for Spock | 1.1281776534864079 |
| Star Trek: The Motion Picture | 1.2483069947936236 |
| Star Trek: Generations | 1.4253784613321967 |
+-------------------------------------+--------------------+