コード例 #1
0
ファイル: Neo4jInspector.php プロジェクト: Tolerance/Viewer
 /**
  * {@inheritdoc}
  */
 public function inspect(InspectionRequest $request) : Inspection
 {
     $query = 'MATCH (parent:Message {identifier: {messageIdentifier}})-[:PARENT_MESSAGE*0..]-(message:Message) ' . 'OPTIONAL MATCH (message)<-[received:RECEIVED_MESSAGE]-(p:Peer) ' . 'OPTIONAL MATCH (message)-[sent:SENT_MESSAGE]-(sender:Peer) ' . 'OPTIONAL MATCH (message)-[:PARENT_MESSAGE*1]->(directParent:Message) ' . 'WITH message, count(p) AS c, collect(p) AS peers, sender, collect(received) as receivedCollection, sent, directParent ' . 'RETURN message, sender, head(receivedCollection) AS received, sent, directParent AS parent, ' . 'CASE c WHEN 1 THEN peers[0] ELSE head(filter(x in peers where x.virtual IS NULL)) END AS receiver ' . 'ORDER BY received.start ASC';
     $response = $this->getResponse($this->client->sendCypherQuery($query, ['messageIdentifier' => (string) $request->getMessageIdentifier()]));
     $profiles = array_map(function (array $row) {
         return $this->createProfile($row);
     }, $response);
     return new Inspection($profiles);
 }
コード例 #2
0
 public function getPostsExtended($limit = 10, $skip = 0)
 {
     $cql = "\n        MATCH (post:Post)-[:TAGGED_WITH]->(t:Tag),\n        (post)-[:CATEGORIZED_AS]->(c:Category),\n        (post)-[:AUTHORED_BY]->(author:Author)\n        RETURN post, COLLECT(DISTINCT t) as tags, COLLECT(DISTINCT c) as categories, author\n        ORDER BY post.date\n        SKIP {$skip}\n        LIMIT {$limit};\n        ";
     $response = $this->client->sendCypherQuery($cql);
     $result = $response->getResult();
     if ($result->getNodesCount() > 0) {
         return $this->postExtendedTableFormatToModels($result->getTableFormat());
     }
     return null;
 }
コード例 #3
0
 public function testPushMultipleInTransaction()
 {
     $q = 'MATCH (n:MultiplePersonNode) DELETE n';
     $this->client->sendCypherQuery($q);
     $statements = [];
     $statement = 'CREATE (n:MultiplePersonNode {id:{myId} })';
     for ($i = 0; $i <= 2000; $i++) {
         $statements[] = ['statement' => $statement, 'parameters' => ['myId' => uniqid()]];
     }
     $this->client->sendMultiple($statements);
     $q = 'MATCH (n:MultiplePersonNode) RETURN count(n)';
     $r = $this->client->sendCypherQuery($q);
     $count = $r->getRows()['count(n)'][0];
     $this->assertEquals(2001, $count);
 }
コード例 #4
0
 public function assertSameGraph($expectedCypherGraph, Client $client)
 {
     $currentGraphQuery = 'MATCH (n) OPTIONAL MATCH (n)-[r]-() RETURN n,r';
     $currentGraphResult = $client->sendCypherQuery($currentGraphQuery)->getResult();
     $expectedResult = $this->getExpectedGraphResult($expectedCypherGraph, $client);
     return array($this->formatGraphResultAsComparableFormat($expectedResult), $this->formatGraphResultAsComparableFormat($currentGraphResult));
 }
コード例 #5
0
 private function exportToDB($graph, OutputInterface $output, Client $client)
 {
     $converter = new CypherStatementsConverter();
     $converter->convert($graph);
     try {
         $constraints = 0;
         foreach ($converter->getConstraintStatements() as $statement) {
             $client->sendCypherQuery($statement['statement']);
             $constraints++;
         }
         $output->writeln('<info>Created ' . $constraints . ' constraint(s)</info>');
         $nodes = 0;
         foreach ($converter->getNodeStatements() as $ns) {
             $client->sendCypherQuery($ns['statement'], $ns['parameters']);
             $nodes += count($ns['parameters']['props']);
         }
         $output->writeln('<info>Created ' . $nodes . ' node(s)</info>');
         $edges = 0;
         foreach ($converter->getEdgeStatements() as $es) {
             $params = isset($es['parameters']) ? $es['parameters'] : ['pairs' => []];
             $client->sendCypherQuery($es['statement'], $params);
             $edges += count($params['pairs']);
         }
         $output->writeln('<info>Created ' . $edges . ' relationship(s)</info>');
     } catch (HttpException $e) {
         $output->writeln('<error>Unable to connect to the database' . PHP_EOL . $e->getMessage() . PHP_EOL . '</error>');
     }
 }
コード例 #6
0
require_once 'vendor/autoload.php';
use Neoxygen\NeoClient\Client;
$logger = new \Monolog\Logger("neoclient");
$logger->pushHandler(new \Monolog\Handler\ErrorLogHandler());
$client = new Client();
/**
* Specific for Heroku
*/
$db1_password = getenv('DEFAULTDB__PASSWORD');
$db2_password = getenv('TESTDB2__PASSWORD');
$client->getServiceContainer()->setParameter('defaultdb_password', $db1_password);
$client->getServiceContainer()->setParameter('testdb2_password', $db2_password);
/** End of heroku specific config
*/
$client->loadConfigurationFile(__DIR__ . '/neoclient.yml')->createDefaultChromePHPLogger('browserlog')->setLogger('neolog', $logger)->build();
$query = 'MATCH (actor:Actor) RETURN actor.name ORDER BY actor.name';
$actors = json_decode($client->sendCypherQuery($query), true);
?>
<html>
<body>
<h1>Neo4j connection fallback example using <a href="https://github.com/neoxygen/neo4j-neoclient" title="NeoClient">NeoClient</a>.</h1>

<h2>Simple heroku app using 2 db instances from <a href="http://www.graphenedb.com/" title="Graphene DB">Graphene DB</a></h2>
<p>The two instances are loaded with the MovieDB example from <a href="http://neo4j.org" title="Neo4j">Neo4j</a>, one of the databases 
has been shutdowned and the app automatically fallback on the second configured connection. If you have ChromePHP, you can see logs in the 
browser. The query used is "<b>MATCH (actor:Actor) RETURN actor.name ORDER BY actor.name</b>"</p>

<?php 
echo '<pre>';
print_r($actors);