Neo4j使用通配符搜索属性进行索引

时间:2016-01-12 13:35:43

标签: performance indexing neo4j lucene cypher

我们正在使用Neo4j Community Edition 2.3.1,并且有很多使用通配符的查询。例如,我们搜索所有用户'有“汽车'在几个较大的属性:简介和生物(即:句子或小段落)。

app.controller('ProductDetailsController', function(){
    var vm = this;
    //also added the property to $scope to see if i could access it there
    $scope.prodAttribs = vm.prodAttribs = {
            name: '',
            description: '',
            price: [0.0],
            condition: null
    }
    vm.all_attributes = [
        {
          "attribute_id": 1210,
          "attribute_display_name": "Product Type",
          "attribute_code": "product_type",
          "attribute_field_type": "Textfield",
          "cvl_option_values": [],
          "validation_rules": {}
        },
        {
          "attribute_id": 902,
          "attribute_display_name": "VAT",
          "attribute_code": "vat",
          "attribute_field_type": "dropdown",
          "cvl_option_values": [
            {
              "option_id": "5",
              "value": "5%"
            },
            {
              "option_id": "6",
              "value": "Exempt"
            }
          ],
          "validation_rules": {}
    }];
})

'用户'节点超过160万。

查询相对较慢,尽管我们知道这一点,因为Neo4j使用AllNodesScan,因为属性上没有索引。我们想为此查询创建一个索引,但Neo4j' new'索引不适用于通配符。

我们正在考虑使用旧的'全文Neo4j与Lucene一起索引。 还考虑将Bio和Profile制作成标记的节点,而不是属性,然后在它们上使用Schema索引。

我关注的是实施'遗产'索引,因为它们,很好的遗产'我想是否可以在某个时候弃用它们。

关于提高上述通配符搜索性能的建议?

2 个答案:

答案 0 :(得分:1)

关于使用' CONTAINS',根据Neo4j docs,它不能与新的架构索引一起使用。但是感谢你的建议。

我要回答,并将其标记为已回答&#39;。我们的团队在Neo4j中实施了Legacy Indexing,它正在创造奇迹。简单查询执行时间从大约6秒到<100毫秒。

答案 1 :(得分:0)

更新:建议使用CONTAINS,但只有STARTS WITH当前使用架构索引。这可能会在将来的版本中发生变化。

您是否尝试过使用Neo4j 2.3中添加的新CONTAINS运算符?

MATCH (user:User) 
WHERE user.Profile CONTAINS "cars" OR user.Bio CONTAINS "cars"
RETURN user SKIP 0 LIMIT 20;

您应该对要对其进行字符串过滤的每个String属性进行架构索引。