查询数组属性或嵌入属性

时间:2013-07-11 10:23:54

标签: java indexing neo4j

考虑以下课程:

class Basic{
    String id;
    Double val;
    //some other member variables
}

class NodeBO{
    List<String> id;
    Type type;
    // list of id from objects of Basic class in data below

    Map<ChEnum, Basic> data;

    addBeans(NodeBO nodeBO, Node node){
        // in transaction...
        node.setProperty("priperties", nodeBO.toString());
        // is it ok to convert to array? or should be converted to JSON string?
        node.setProperty(GraphElementProps.id,toArray(nodeBO.id));
        node.setProperty(GraphElementProps.type, nodeBO.type);
    }

    @override
    toString(){
        //return json of this object
    }

}

enum ChEnum{
    CH1(1), CH2(2);
    // constructor and some methods
}

使用autoIndexer索引节点:

AutoIndexer<Node> nodeAutoIndexer = GRAPH_DB.index().getNodeAutoIndexer();
nodeAutoIndexer.startAutoIndexingProperty(GraphElementProps.id);
nodeAutoIndexer.setEnabled(true);
GRAPH_NODE_AUTO_INDEX = nodeAutoIndexer.getAutoIndex();

这里我将GraphElementProps.id存储为节点属性(通过转换为数组)。是否将数组(字符串)作为属性?或者我应该将列表转换为JSON字符串,然后存储?

我希望能够使用queryId查询此数组。例如查询node-index以获取node.getProperty(GraphElementProps.id)包含给定queryId的节点?例如:

// how to do this?
GRAPH_NODE_AUTO_INDEX.get(/*Nodes whose id contain queryId*/);

或者(以某种方式)是否可以使id类的Basic属性可索引和可​​搜索?如果可能,如何索引这些属性?以及如何查询它们?

我无法理解,但它与Spring-data-neo4j有关吗?我是Spring-data-neo4j的新手。

1 个答案:

答案 0 :(得分:0)

我认为最好的解决方案是使用Spring-data-neo4j。这将允许索引嵌入字段并对其进行查询。

相关问题