Example #1
0
// Initialize the data
if ($cmd == 'init') {
    $keanu = $client->makeNode()->setProperty('name', 'Keanu Reeves')->save();
    $laurence = $client->makeNode()->setProperty('name', 'Laurence Fishburne')->save();
    $jennifer = $client->makeNode()->setProperty('name', 'Jennifer Connelly')->save();
    $kevin = $client->makeNode()->setProperty('name', 'Kevin Bacon')->save();
    $actors->add($keanu, 'name', $keanu->getProperty('name'));
    $actors->add($laurence, 'name', $laurence->getProperty('name'));
    $actors->add($jennifer, 'name', $jennifer->getProperty('name'));
    $actors->add($kevin, 'name', $kevin->getProperty('name'));
    $matrix = $client->makeNode()->setProperty('title', 'The Matrix')->save();
    $higherLearning = $client->makeNode()->setProperty('title', 'Higher Learning')->save();
    $mysticRiver = $client->makeNode()->setProperty('title', 'Mystic River')->save();
    $keanu->relateTo($matrix, 'IN')->save();
    $laurence->relateTo($matrix, 'IN')->save();
    $laurence->relateTo($higherLearning, 'IN')->save();
    $jennifer->relateTo($higherLearning, 'IN')->save();
    $laurence->relateTo($mysticRiver, 'IN')->save();
    $kevin->relateTo($mysticRiver, 'IN')->save();
    // Find all actors in a movie
} else {
    if ($cmd == 'actors') {
        $queryTemplate = "g.V.in(type).dedup.sort{it.name}.toList()";
        $params = array('type' => 'IN');
        $query = new Gremlin\Query($client, $queryTemplate, $params);
        $result = $query->getResultSet();
        foreach ($result as $row) {
            echo "* " . $row[0]->getProperty('name') . "\n";
        }
    }
}
Example #2
0
 /**
  * Raw gremlin query execution. Used by Query\Gremlin.
  *
  * @param string $string The query string.
  * @param array $parameters The arguments to bind with the query.
  * @throws Exception
  * @return \Everyman\Neo4j\Query\ResultSet
  */
 function gremlinQuery($string, $parameters)
 {
     try {
         $start = microtime(true);
         $query = new InternalGremlinQuery($this->client, $string, $parameters);
         $this->dispatchEvent(new Events\PreStmtExecute($query, $parameters));
         $rs = $query->getResultSet();
         $time = microtime(true) - $start;
         $this->dispatchEvent(new Events\PostStmtExecute($query, $parameters, $time));
         if (count($rs) === 1 && is_string($rs[0][0]) && strpos($rs[0][0], 'Exception') !== false) {
             throw new Exception("An error was detected: {$rs[0][0]}", 0, null, $query);
         }
         return $rs;
     } catch (\Everyman\Neo4j\Exception $e) {
         throw new Exception("An error was detected: {$e->getMessage()}", 0, null, $query);
     }
 }
Example #3
0
 function gremlinQuery($string, $parameters)
 {
     try {
         $query = new InternalGremlinQuery($this->client, $string, $parameters);
         $rs = $query->getResultSet();
         if (count($rs) === 1 && is_string($rs[0][0]) && strpos($rs[0][0], 'Exception') !== false) {
             throw new Exception("An error was detected: {$rs[0][0]}");
         }
         return $rs;
     } catch (\Everyman\Neo4j\Exception $e) {
         throw new Exception("An error was detected: {$e->getMessage()}");
     }
 }