Lucene
Query implementation | Purpose | Example |
---|---|---|
TermQuery | 单词匹配 | neo4j |
PhraseQuery | 短语匹配 | "graph database" |
RangeQuery | 范围匹配 | [A TO Z] {A TO Z} |
WildcardQuery | 正则匹配 | g*p?, d??abase |
PrefixQuery | 前缀匹配 | algo* |
FuzzyQuery | 后缀匹配 | cipher~ |
BooleanQuery | 查询条件聚合 | graph AND "shortest path" |
docker run -p 17687:7687 -p 17474:7474 --name=neo4j-test neo4j:3.5.3
:play northwind-graph
Neo4j全文检索有以下特性,不过用下来最重要的我感觉是创建索引的语句实际上只是创建于给命名控件. Neo4j从2.2.x时代开始就默认开启node_auto_indexing=true
. 倒排索引在数据插入时候已经创建了. 创建索引/删除索引代价是非常小的
analyzers
扩展lucene query
语句建立两个索引, 一个是Product
的该标签的索引. 另外一个全数据库全文检索的索引
call db.index.fulltext.createNodeIndex("all",['Product', 'Category', 'Supplier'],['reorderLevel', 'unitsInStock', 'unitPrice', 'supplierID', 'productID', 'discontinued', 'quantityPerUnit', 'categoryID', 'unitsOnOrder', 'productName', 'description', 'categoryName', 'picture', 'country', 'address', 'contactTitle', 'city', 'phone', 'contactName', 'postalCode', 'companyName', 'fax', 'region', 'homePage'])
call db.index.fulltext.createNodeIndex("product",['Product'],['reorderLevel', 'unitsInStock', 'unitPrice', 'supplierID', 'productID', 'quantityPerUnit', 'discontinued', 'productName', 'unitsOnOrder', 'categoryID'])
删除索引
call db.index.fulltext.drop("all")
可以通过函数获取所有标签和属性
call db.propertyKeys
call db.labels
这里面的查询非常简单.只要记住一个语句就能应付大多数场景
call db.index.fulltext.queryNodes(
'all', //这里索引名
'Av' // lucene查询语句
) yield node
where node.address contains "12" // where语句
return node
order by node.address // order skip limit
skip 0
limit 1
原文:https://www.cnblogs.com/ohbonsai/p/neo4j_fulltext_search.html