全文搜索Graph
全文搜索是基于全文索引对值为字符串类型的属性进行前缀搜索、通配符搜索、正则表达式搜索和模糊搜索。
在LOOKUP
或MATCH
语句中,使用WHERE
子句指定字符串的搜索条件。
前提条件Graph
请确保已经部署全文索引。详情请参见Graph。
注意事项Graph
使用全文索引前,请确认您已经了解全文索引的Graph。
自然语言全文搜索Graph
自然语言搜索将搜索的字符串解释为自然人类语言中的短语。搜索不区分大小写。
语法Graph
LOOKUP ON {<tag> | <edge_type>} WHERE <expression> [YIELD <return_list>];
<expression> ::=
PREFIX | WILDCARD | REGEXP | FUZZY
<return_list>
<prop_name> [AS <prop_alias>] [, <prop_name> [AS <prop_alias>] ...]
- PREFIX(schema_name.prop_name, prefix_string, row_limit, timeout)
- WILDCARD(schema_name.prop_name, wildcard_string, row_limit, timeout)
- REGEXP(schema_name.prop_name, regexp_string, row_limit, timeout)
-
FUZZY(schema_name.prop_name, fuzzy_string, fuzziness, operator, row_limit, timeout)
fuzziness
:可选项。允许匹配的最大编辑距离。默认值为AUTO
。查看其他可选值和更多信息,请参见Graph。
operator
:可选项。解释文本的布尔逻辑。可选值为OR
(默认)和and
。
row_limit
:可选项。指定要返回的行数。默认值为100
。
timeout
:可选项。指定超时时间。单位:毫秒(ms)。默认值为200
。
示例Graph
nebula> CREATE SPACE basketballplayer (partition_num=3,replica_factor=1, vid_type=fixed_string(30));
nebula> SIGN IN TEXT SERVICE (127.0.0.1:9200);
nebula> USE basketballplayer;
nebula> ADD LISTENER ELASTICSEARCH 192.168.8.5:46780;
nebula> CREATE TAG player(name string, age int);
nebula> CREATE TAG INDEX name ON player(name(20));
nebula> INSERT VERTEX player(name, age) VALUES \
"Russell Westbrook": ("Russell Westbrook", 30), \
"Chris Paul": ("Chris Paul", 33),\
"Boris Diaw": ("Boris Diaw", 36),\
"David West": ("David West", 38),\
"Danny Green": ("Danny Green", 31),\
"Tim Duncan": ("Tim Duncan", 42),\
"James Harden": ("James Harden", 29),\
"Tony Parker": ("Tony Parker", 36),\
"Aron Baynes": ("Aron Baynes", 32),\
"Ben Simmons": ("Ben Simmons", 22),\
"Blake Griffin": ("Blake Griffin", 30);
nebula> LOOKUP ON player WHERE PREFIX(player.name, "B");
+-----------------+
| _vid |
+-----------------+
| "Boris Diaw" |
+-----------------+
| "Ben Simmons" |
+-----------------+
| "Blake Griffin" |
+-----------------+
nebula> LOOKUP ON player WHERE WILDCARD(player.name, "*ri*") YIELD player.name, player.age;
+-----------------+-----------------+-----+
| _vid | name | age |
+-----------------+-----------------+-----+
| "Chris Paul" | "Chris Paul" | 33 |
+-----------------+-----------------+-----+
| "Boris Diaw" | "Boris Diaw" | 36 |
+-----------------+-----------------+-----+
| "Blake Griffin" | "Blake Griffin" | 30 |
+-----------------+-----------------+-----+
nebula> LOOKUP ON player WHERE WILDCARD(player.name, "*ri*") | YIELD count(*);
+----------+
| COUNT(*) |
+----------+
| 3 |
+----------+
nebula> LOOKUP ON player WHERE REGEXP(player.name, "R.*") YIELD player.name, player.age;
+---------------------+---------------------+-----+
| _vid | name | age |
+---------------------+---------------------+-----+
| "Russell Westbrook" | "Russell Westbrook" | 30 |
+---------------------+---------------------+-----+
nebula> LOOKUP ON player WHERE REGEXP(player.name, ".*");
+---------------------+
| _vid |
+---------------------+
| "Danny Green" |
+---------------------+
| "David West" |
+---------------------+
| "Russell Westbrook" |
+---------------------+
...
nebula> LOOKUP ON player WHERE FUZZY(player.name, "Tim Dunncan", AUTO, OR) YIELD player.name;
+--------------+--------------+
| _vid | name |
+--------------+--------------+
| "Tim Duncan" | "Tim Duncan" |
+--------------+--------------+
最后更新: April 13, 2021