从Neo4j查询获取列表

时间:2016-04-04 11:26:47

标签: java neo4j cypher

我想创建一个节点子节点的json。我正在使用此命令获取特定节点的所有子节点:

.green

我的结果是这样的:

<script>
function getHashFilter() {
    // get filter=filterName
    var matches = location.hash.match( /filter=([^&]+)/i );
    var hashFilter = matches && matches[1];
    return hashFilter && decodeURIComponent( hashFilter );
}

$( function() {
    var $container = $('.isotope');

    // bind filter button click
    var $filterButtonGroup = $('.filter-button-group');
    $filterButtonGroup.on( 'click', 'button', function() {
        var filterAttr = $( this ).attr('data-filter');
        // set filter in hash
        location.hash = 'filter=' + encodeURIComponent( filterAttr );

        var $chofval = $(".changeMe").html(filterAttr);

        // search if it contains these strings
        if ($chofval.indexOf("*") >= 0) {
            $(".changeMe").html("All Apples");
        } else if ($chofval.indexOf(".green") >= 0) {
            $(".changeMe").html("Green Apples");
        }
    });

    // bind filter on select change
    $('.filters-select').on( 'change', function() {
        // get filter value from option value
        var filterValue = this.value;
        // use filterFn if matches value
        filterValue = filterFns[ filterValue ] || filterValue;
        $container.isotope({ filter: filterValue });
    });

    var isIsotopeInit = false;

    function onHashchange() {
        var hashFilter = getHashFilter();
        if ( !hashFilter && isIsotopeInit ) {
            return;
        }
        isIsotopeInit = true;
        // filter isotope
        $container.isotope({
            itemSelector: '.offer-type',
            layoutMode: 'fitRows',

            // use filterFns
            filter: filterFns[ hashFilter ] || hashFilter
        });
        // set selected class on button
        if ( hashFilter ) {
            $filterButtonGroup.find('.is-checked').removeClass('is-checked');
            $filterButtonGroup.find('[data-filter="' + hashFilter + '"]').addClass('is-checked');
        }
    }

    $(window).on( 'hashchange', onHashchange );

    // trigger event handler to init Isotope
    onHashchange();
});
//@ sourceURL=pen.js
</script>

我现在想要访问java中的子项列表。

match(t:TAG)<-[children:CHILD_OF]-(subtag:TAG) where t.name="brand" 
return t.eid as parent, collect(subtag.eid) as child

我现在应该拆分孩子的字符串吗?或者是否有一种方法可以直接给我一个孩子的列表,或者是一个直接给我孩子作为json的方法?

1 个答案:

答案 0 :(得分:1)

。您的“子”字段应该是字符串列表。 。您应该为标记名称使用参数,例如{name} 。你可以结合迭代和查询

String query = "match(t:TAG)<-[children:CHILD_OF]-(subtag:TAG) where t.name={name} "+
               "return t.name as parent, collect(subtag.name) as children";
for(Map row : Neo4j.queryLagData(query, singletonMap("name","brand"))) {
    String parent = (String)row.get("parent");
    List<String> children = (List<String>)row.get("children");
}