使用显式索引进行文本搜索
请注意,在 Neo4j 3.5 中,全文搜索作为 Cypher 存储过程的一部分可用。更多文档请参见此处:https://neo4j.ac.cn/docs/cypher-manual/3.5/schema/index/#schema-index-fulltext-search。 |
截至 Neo4j 3.4.x 版本,模式索引最适合索引精确的属性值,但不支持“模糊”或全文搜索。但是,遗留索引允许针对这些类型的查询进行优化,依赖于自动索引或显式索引。在 Neo4j 3.4 版本中,增加了对使用内置存储过程的显式索引的支持,以便在 Neo4j 中利用文本搜索功能来查找节点和/或关系。
下面是关于如何在节点属性上执行文本搜索的示例。
创建节点并将其添加到索引
match (n:Movie)
with n
call db.index.explicit.addNode("MovieTitle",n,"title",n.title) yield success return count(*)
运行以下命令验证索引是否已创建
call db.index.explicit.list
输出
╒══════╤════════════╤════════════════════════════════════╕ │"type"│"name" │"config" │ ╞══════╪════════════╪════════════════════════════════════╡ │"NODE"│"MovieTitle"│{"type":"exact","provider":"lucene"}│ └──────┴────────────┴────────────────────────────────────┘
运行查询以查找以 The
开头的电影名称
call db.index.explicit.searchNodes('MovieTitle','title:The*')
输出
╒════════════════════════════════════════════════════════════════════════════════════════════════════════════╤════════╕ │"node" │"weight"│ ╞════════════════════════════════════════════════════════════════════════════════════════════════════════════╪════════╡ │{"title":"The Matrix Revolutions","tagline":"Everything that has a beginning has an end","released":2003} │1.0 │ ├────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────┤ │{"title":"The Da Vinci Code","tagline":"Break The Codes","released":2006} │1.0 │ ├────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────┤ │{"title":"The Green Mile","tagline":"Walk a mile you'll never forget.","released":1999} │1.0 │ ├────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────┤ │{"title":"The Devil's Advocate","tagline":"Evil has its winning ways","released":1997} │1.0 │ ├────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────┤ │{"title":"The Polar Express","tagline":"This Holiday Season… Believe","released":2004} │1.0 │ ├────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────┤ │{"title":"The Replacements","tagline":"Pain heals, Chicks dig scars... Glory lasts forever","released":2000}│1.0 │ ├────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────┤ │{"title":"The Matrix","tagline":"Welcome to the Real World","released":1999} │1.0 │ ├────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────┤ │{"title":"The Matrix Reloaded","tagline":"Free your mind","released":2003} │1.0 │ ├────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────┤ │{"title":"The Birdcage","tagline":"Come as you are","released":1996} │1.0 │ └────────────────────────────────────────────────────────────────────────────────────────────────────────────┴────────┘
如果添加了与该索引相关的更多数据,它们不会自动更新到索引中。需要按如下方式将这些额外的节点添加到索引中
match (n:Movie)
with n
call db.index.explicit.addNode("MovieTitle",n,"title",n.title) yield success return count(*)
此页面是否有帮助?