无法在 Neo4j php 中使用 https post 请求将节点添加到空间层


Failed to add a node to spatial layer with https post request in Neo4j php

我正在尝试将节点添加到索引空间。

 $path = '/db/data/index/node/'.$layer;
    $nodePath = DbConfig::getFullDatabaseServerUrl() . '/db/data/node/' . $nodeId;
    $data = array("key" => "dummy", "value" => "dummy","uri"=>$nodePath);
    $data =json_encode($data);
    DbRestManager::send($path,$data);

public  static function send($path, $data) {
        $url = DbConfig::getFullDatabaseServerUrl() . $path;
        $auth=DbConfig::getUserName().':'.DbConfig::getPassword();
        $authEcoded=base64_encode($auth);
        $headers = array('Accept: application/json; charset=UTF-8','Authorization: Basic '.$authEcoded,'Content-Type: application/json');
        // Open connection
        $ch = curl_init();
        // Set the url, number of POST vars, POST data
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        // Execute post
        $result = curl_exec($ch);
        // Close connection
        curl_close($ch);
    }

$data={"key":"dummy","value":"dummy","uri":"dev_db.pico-app.com:7473/db/data/node/11"}

一切似乎都很好,但操作不起作用。由于某种原因,我也看不到错误。

根据空间服务器文档,将节点添加到索引具有要发送的完全不同的 json 有效负载,以及发送到不同的终结点。

您必须先创建空间图层,然后创建空间索引

,然后仅将节点添加到空间索引。

Example request
POST http://localhost:7575/db/data/ext/SpatialPlugin/graphdb/addNodeToLayer
Accept: application/json; charset=UTF-8
Content-Type: application/json
{
  "layer" : "geom",
  "node" : "http://localhost:7575/db/data/node/54"
}

与其在原始中使用 curl,您可能希望使用 neoclient 和它的空间扩展,这将消除 http 请求的所有负担并提供有用的 methdods,一个简单的例子:

<?php
require_once(__DIR__.'/vendor/autoload.php');
use Neoxygen'NeoClient'ClientBuilder;
$client = ClientBuilder::create()
    ->addConnection('default', 'https', 'localhost', 7474, true, 'neo4j', 'password')
    ->setAutoFormatResponse(true)
    ->registerExtension('spatial', 'Neoxygen''NeoClientExtension''Spatial''SpatialExtension')
    ->build();

$client->createSpatialIndex();
$client->createSimplePointLayer();
// Create first some nodes with lat and lon values
// Retrieve them and add them to the spatial index
$q = $client->sendCypherQuery('MATCH (n:Step) RETURN n');
$steps = $q->getResult()->getNodes();
foreach ($steps as $step) {
    $client->addNodeToSpatialIndex($step->getId());
}