Neo4jNeo4jNeo4j

Neo4j全文检索

2019-02-19  本文已影响8人  OhBonsai

全文检索基本概念

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"

环境准备

Neo4j全文检索

Neo4j全文检索有以下特性,不过用下来最重要的我感觉是创建索引的语句实际上只是创建于给命名控件. Neo4j从2.2.x时代开始就默认开启node_auto_indexing=true. 倒排索引在数据插入时候已经创建了. 创建索引/删除索引代价是非常小的

索引创建与删除

建立两个索引, 一个是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
上一篇 下一篇

猜你喜欢

热点阅读