Inserting Array Types as Properties in Neo4j from PHP

569 views
Skip to first unread message

Neo

unread,
Jul 13, 2012, 10:30:06 AM7/13/12
to ne...@googlegroups.com
In Neo4J we can store arrays of primitive types as Properties, we can even index them. But this is done is JAVA. I am using PHP Everyman library to interact with Neo4J. How can I insert and query these arrays from PHP (other than JAVA). I also want to know how can I add Arrays to Index.
Following is from Neo4J documentation.
Properties are key-value pairs. The keys are always strings. Valid property value types are all the Java primitives (intbytefloat, etc), java.lang.Strings and arrays of primitives and Strings. 

Josh Adell

unread,
Jul 13, 2012, 2:00:29 PM7/13/12
to ne...@googlegroups.com
Have you tried just setting a property as an array?  If it doesn't work, file an issue for it and I'll try to work it in when I get a chance (and if the REST API supports it.)

-- Josh

Josh Adell

unread,
Jul 13, 2012, 7:12:43 PM7/13/12
to ne...@googlegroups.com
Based on a brief experiment, it seems that the REST API only allows arrays as properties if they are numerically indexed (so no PHP associative arrays), do not contain nulls, every element is the same type, and every element is an integer, string or boolean.

These work:

$props = array(1,2,3);
$props = array("foo","bar","baz");
$props = array(true, false);
$props = array(1.2, 2.3);

These do not work:

$props = array("foo"=>"bar", "baz"=>"qux");
$props = array(null);
$props = array(1, "foo");
$props = array(1.0, 1.2);

In the experiment, neo4jphp correctly JSON encoded and sent the property, and the server returned either a 400, or in the case of the null, a 500.

Probably something to do with Java arrays needing to have every element the same type and no null elements.

The last "not working" example is interesting. It fails because PHP's json_encoding turns floats with no fractional part into an integer, which of course makes the array a mixed type array.

-- Josh

Neo

unread,
Jul 14, 2012, 12:19:42 AM7/14/12
to ne...@googlegroups.com
Thanks Josh. I converted them to Delimited strings. Now I can store them as arrays from PHP.
 I am curious how Neo4J stores these arrays, since we can insert from both PHP and Java.
Reply all
Reply to author
Forward
0 new messages