I am unable to get the Index Lookup to work with the PHP API Client.
First, am creating a node and am indexing it. This works fine. Then when I test the lookup
curl -H Accept:application/json http://localhost:7474/db/data/index/node/my_nodes/guid/108
I get:
[ {
"indexed" : "http://localhost:7474/db/data/index/node/my_nodes/guid/108/57",
"outgoing_relationships" : "http://localhost:7474/db/data/node/57/relationships/out",
"data" : {
"guid" : 108,
"title" : "New User ABC",
"owner_guid" : "2"
},
"traverse" : "http://localhost:7474/db/data/node/57/traverse/{returnType}",
"all_typed_relationships" : "http://localhost:7474/db/data/node/57/relationships/all/{-list|&|types}",
"property" : "http://localhost:7474/db/data/node/57/properties/{key}",
"self" : "http://localhost:7474/db/data/node/57", ....
So far so good. However, when I 开发者_开发技巧define a function as follows in the PHP API client to perform a lookup.
public function getNodeByKey ($key, $value)
{
$uri = $this->base_uri . 'index/node/my_nodes/' . $key . '/' . $value ;
list($response, $http_code) = HTTPUtil::jsonGetRequest($uri);
if ($http_code == 200)
return Node::inflateFromResponse($this, $response);
else {
throw new HttpException($http_code);
}
}
and following is how am calling the above function:
$graphDb = new GraphDatabaseService('http://localhost:7474/db/data/');
...
$node = $graphDb->getNodeByKey ('guid', $uid);
$relationship = $node->createRelationshipTo($another_node, 'works with');
$relationship->save();
I get a HTTP response of 200 from getNodeByKey(). However, When I try to save the relationship, I get a 404. I tried using the dump_node () to test and the node I tried to lookup i.e. $node was null. I cannot figure out where am going wrong. Any pointers ?
Thanks in advance, Nanda
Nanda, could you try to get the indexed node out using curl also, according to http://docs.neo4j.org/chunked/snapshot/rest-api.html ?
I was finally able to get this to work using the PHP API client. I had to modify the function inflateFromResponse to the following. I am not sure if its a problem with the version of neo4j am using (viz 1.2)
public static function inflateFromResponse($neo_db, $response)
{
$node = new Node($neo_db);
$node->_is_new = FALSE;
$node->_id = end(explode("/", $response[0]['self']));
$node->setProperties($response[0]['data']);
return $node;
}
精彩评论