怎样使用lable与apoc索引混合查找
发布于 5 年前 作者 prolights 1901 次浏览 来自 问答

普通的lable筛选 match (e:A) where e:人物 where e.name =~’.德.’ return e limit 100; 使用apoc对name建立全文索引 CALL apoc.index.addAllNodes(‘name_index’, { A:[“name”]}, {autoUpdate:true}); 查询的语句是 CALL apoc.index.nodes(‘name_index’,’+A.name:’) YIELD node AS airport, weight RETURN airport, weight LIMIT 10; 此时怎样使用’人物‘作为初步筛选,然后使用apoc根据全文索引进行查找呢? 还是说需要对每一个需要用到的标签一同建立全文索引才可以,比如 CALL apoc.index.addAllNodes(‘name_index’, { A:[“name”], 人物:[“name”]}, {autoUpdate:true}); 但这么做似乎并不能通过更多的标签筛选来加快查询吧,比如标签是A_人物_电影呢? Thank you!

7 回复

创建全文索引时可以指定标签和属性集合。

另外,在3.5以后全文索引成为数据库模式索引一部分,可以使用dbms.index.fulltext.createNodeIndex

@graphway 请问 CALL apoc.index.search(‘name_index’,‘Entity.name:刘福*’) YIELD node AS e with e match(e:人物) RETURN e order by e.score DESC limit 10; 这么用是可以的,但无法对查询加速

但这么用 match(e:Entity) where e:人物 and e.type = 2 with e CALL apoc.index.search(‘name_index’,‘Entity.name:刘福*’) YIELD node AS ee RETURN ee order by ee.score DESC limit 10; 好像不行。 我该怎样把with e的e传递给apoc.index.search呢? (我希望在模糊搜索前进行筛选(标签筛选和模式索引都很快),以加快查询速度,)

对于查询结果是不能再应用索引了的,因为结果已经在内存里面。

@graphway 那么with e match(e:人物) RETURN e order by e.score DESC limit 10; 纯粹是根据用户的输入对结果进行筛选是吧(无法起到加快查询速度的作用)?

3.5以后使用ORDER BY是可以走索引的。

3.5升级之后的全文检索还是比较好用的

CALL db.index.fulltext.createNodeIndex('test',["Label",...],["name",....])
CALL db.index.fulltext.queryNodes('test', "香港") YIELD node, score
RETURN node.name, score
回到顶部