Neo4j APOC触发器,手动索引-小写属性值

时间:2018-12-07 12:33:30

标签: neo4j triggers cypher neo4j-apoc

我创建了以下Neo4j APOC触发器,该触发器将节点属性添加到手动索引中:

CALL apoc.trigger.add('CREATE_NODES_TRIGGER', "UNWIND {createdNodes} AS n 
WITH n WHERE labels(n)[1] IN ['Title','Name','Character'] 
CALL apoc.index.addNodeByName(labels(n)[1], n, keys(n)) 
RETURN true", {phase:'before'})

当我执行以下查询时:

CALL apoc.index.nodes('Character','name:An*') YIELD node AS c, weight 
RETURN c.name, weight LIMIT 10

它正确返回数据:

c.name  weight
"Annette Porter"    1.0
"Anke Bauernfeind"  1.0
"Angel's Henchman"  1.0
"Anna Slovatzka Marshall"   1.0
"Andrew Horvath"    1.0
"Angela Somes"  1.0
"An-Soo 'Alison' Kim"   1.0
"Annette Holman"    1.0
"Anita Wilcox"  1.0
"Anna Cerdick"  1.0

但对于小写查询name:an*

CALL apoc.index.nodes('Character','name:an*') YIELD node AS c, weight 
RETURN c.name, weight LIMIT 10

结果为空。

我认为我应该在将属性值添加到索引之前将其小写。我说的对吗?

如果是这样,请您帮忙改进触发器以小写属性值:

CALL apoc.trigger.add('CREATE_NODES_TRIGGER', "UNWIND {createdNodes} AS n 
WITH n WHERE labels(n)[1] IN ['Title','Name','Character'] 
CALL apoc.index.addNodeByName(labels(n)[1], n, keys(n)) 
RETURN true", {phase:'before'})

或者,请提出另一种解决此问题的方法。谢谢!

已更新

我在neo4j.conf中发现了以下属性:

apoc.autoIndex.enabled=true

并将所有节点添加到索引:

CALL apoc.index.addAllNodes('movies',{
  Title: ["primaryTitle", "originalTitle"],
  Name:  ["primaryName"],
  Character: ["name"]}, {autoUpdate:true})

所以,现在我有一个问题:apoc.autoIndex.enabled=true将仅跟踪并反映已添加到索引的节点上的更改(使用apoc.index.addAllNodes),或者还将添加新创建的{{1 }},TitleName节点也指向索引?

0 个答案:

没有答案