CREATE FULLTEXT INDEX statement¶
The CREATE FULLTEXT INDEX statement creates a full-text index on a specific graph.
To specify the graph, use either of the following methods:
- Add a USE clause before this statement to set the working graph.
- Use SESSION SET to set the graph for the current session in advance.
If both methods are used, the one specified in the USE clause takes precedence. If neither is used, an error occurs.
You can create a full-text index based on a STRING property of a node type or edge type. Full-text indexes enable you to efficiently search for specific words or phrases within the indexed properties.
After a full-text index is created, you can use the ftscore() function to calculate the score of relevance between the STRING value stored by the indexed property and a given query string.
To create other types of indexes, see CREATE NORMAL INDEX, CREATE VECTOR INDEX, and CREATE SPATIAL INDEX.
Note
An operation involving a non-default schema or an object in it requires access to the schema, either implicitly or through an explicit USAGE grant, as well as the privilege required for the operation. The schema access check and the privilege check for the requested operation are independent; satisfying one does not satisfy the other. Schema access control does not apply to temporary graphs or built-in procedures and functions. For more information, see Schema access control.
Prerequisites¶
- A graph is created. For more information, see CREATE GRAPH.
- To create a full-text index, you must either be the owner of the graph, be granted to perform the action
INDEXon the graph, or be granted to perform the actionCREATE INDEXon the used schema. For more information, see Roles and privileges.
Syntax¶
- create_fulltext_index_statement
create_fulltext_index_statement ::=
'CREATE' 'FULLTEXT' 'INDEX' ('IF NOT EXISTS')? index_name 'ON' ( ( ('NODE' | 'VERTEX') 'TYPE'? node_type_name) | ( ('EDGE'|'RELATIONSHIP') 'TYPE'? edge_type_name) ) '(' property_name ')'
Parameters¶
IF NOT EXISTS¶
This clause checks if an index with the same name already exists. If it already exists, the index is not created and no exception is thrown.
If you do not specify this clause, an exception is thrown if an index with the same name already exists.
index_name¶
The name of the full-text index to be created. The name is a regular identifier, and must be unique among all types of indexes within the same graph.
For more information about identifiers, see Rules for naming identifiers.
node_type_name¶
The name of the node type on which the full-text index is created. The node type must have at least one property whose value type is STRING.
edge_type_name¶
The name of the edge type on which the full-text index is created. The edge type must have at least one property whose value type is STRING.
property_name¶
The name of the property of the node type or edge type on which the full-text index is created. The value type of the property must be STRING. For more information, see String type.
Note that only one property can be specified for each full-text index.
Examples¶
The following examples are based on the example dataset.
Create a full-text index on a node type¶
USE movie CREATE FULLTEXT INDEX IF NOT EXISTS ft_movie ON NODE Movie(name)