Neo4j用的搜索引擎是Lucene

查询索引

  • 查询索引
    :schema
    

属性索引

  • 创建索引

    //对name属性创建索引
    CREATE INDEX ON :student(name)
    //对age属性创建唯一索引
    CREATE CONSTRAINT ON (n:student) ASSERT n.age IS UNIQUE
    
  • 删除索引

    DROP INDEX ON :student(name)
    DROP CONSTRAINT ON (n:student) ASSERT n.age IS UNIQUE
    

全文索引

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

    • 支持关系与节点的索引
    • 支持常用analyzers扩展
    • 可以使用lucene query语句
    • 可以返回查询结果评分
    • 对索引自动更新
    • 单索引文档数量不限
    • 参考:https://www.cnblogs.com/ohbonsai/p/neo4j_fulltext_search.html
  • 创建索引

    // 可以创建全库标签索引
    call db.index.fulltext.createNodeIndex("all",['student', 'teacher'],['name', 'age', 'sex''nick'])
    // 也可以针对某一标签做索引
    call db.index.fulltext.createNodeIndex("student",['student'],['name', 'age', 'sex', 'nick'])
    
  • 删除索引

    call db.index.fulltext.drop("all")
    
  • 查询语句

    call db.index.fulltext.queryNodes(
    		'all',        //这里索引名
    	    '张三'          // lucene查询语句
    	) yield node where node.age contains "12"   // where语句
    	return node 
    	order by node.age  // order 
    	skip 0 //分页
    	limit 1
    

更多推荐