コード例 #1
0
ファイル: UserRepository.php プロジェクト: prasol/socialrest
 public function getFriends($level = 1)
 {
     $queryString = 'MATCH (user), (friends), (user)-[:FRIENDSHIP*%d]-(friends) WHERE id(user) = {userId} RETURN DISTINCT friends';
     $queryString = sprintf($queryString, $level);
     $query = new Query(DB::connection()->getClient(), $queryString, ['userId' => $this->model->getKey()]);
     return $this->makeCollection($query->getResultSet())->toArray();
 }
コード例 #2
0
 public function getNotifikasi($id)
 {
     $client = new Client(HelperController::getHost(), HelperController::getPort());
     $client->getTransport()->setAuth(HelperController::getUserNeo4j(), HelperController::getPassNeo4j());
     $status = 'failed';
     $properties = array();
     $result = array();
     if (count($id) > 0) {
         $cypher = 'MATCH (n:Notifikasi) where n.donaturId="' . $id . '" RETURN n LIMIT 100';
         $query = new Query($client, $cypher);
         $nodes = $query->getResultSet();
         if (count($nodes) > 0) {
             $status = 'success';
             foreach ($nodes as $node) {
                 $properties['id'] = $node['r']->getId();
                 $properties['properties'] = $node['r']->getProperties();
                 array_push($result, $properties);
             }
         } else {
             $status = 'failed, return value is empty check your donatur id';
         }
     } else {
         $status = 'failed, notifikasi id is empty please check your parameter';
     }
     return response()->json(array('status' => $status, 'data' => $result));
 }
コード例 #3
0
ファイル: HomeController.php プロジェクト: karwana/penelope
 public function read()
 {
     $view_data = array('title' => $this->_m('home_title'));
     $view_data['node_schemas'] = $this->schema->getNodes();
     // Sort by name.
     usort($view_data['node_schemas'], function ($a, $b) {
         return strcmp($a->getName(), $b->getName());
     });
     $view_data['node_totals'] = array();
     // Initialize totals array with zeroes.
     foreach ($view_data['node_schemas'] as $node_schema) {
         $view_data['node_totals'][$node_schema->getName()] = 0;
     }
     // Get label totals.
     $query = new Neo4j\Cypher\Query($this->client, 'MATCH n RETURN DISTINCT count(labels(n)), labels(n);');
     foreach ($query->getResultSet() as $row) {
         // The query result groups nodes with the same label. For example, a group of nodes will have `array('PERSON', 'DOCUMENT')` and another `array('PERSON')`.
         foreach ($row[1] as $label) {
             if (isset($view_data['node_totals'][$label])) {
                 $view_data['node_totals'][$label] += $row[0];
             }
         }
     }
     $view_data['total_nodes'] = array_sum($view_data['node_totals']);
     $this->app->render('home', $view_data);
 }
コード例 #4
0
ファイル: Neo4jProcessor.php プロジェクト: randak/charlotte
 protected function query($str, $vars = array())
 {
     if (!isset($this->connector)) {
         die("No database is connected. Aborting query.");
     }
     $query = new Query($this->connector, $str, $vars);
     $query->getResultSet();
 }
コード例 #5
0
function enlargeNeoDatabase($unifiedName)
{
    $client = new Everyman\Neo4j\Client('localhost', 7474);
    $client->getTransport()->setAuth('neo4j', 'muresearch');
    //Check if the author exists
    $exist = FALSE;
    $authorExists = "match (u:Person {name: \"" . $unifiedName . "\"}) return u";
    $query = new Query($client, $authorExists);
    $result = $query->getResultSet();
    foreach ($result as $r) {
        $exist = TRUE;
    }
    if (!$exist) {
        //Author does not exists. Must be of Mizzou
        $crawler = new CoauthorNetworkCrawler($unifiedName, $affiliation = "University of Missouri");
        $crawler->insertDB('localhost', 7474, 'neo4j', 'muresearch');
        $setHasSearched = "match (u:Person {name: \"" . $unifiedName . "\"}) set u.hasSearched = 1";
        $query = new Query($client, $setHasSearched);
        $result = $query->getResultSet();
        return;
    }
    //Check if we need to crawl the network for this author while the author already exists.
    $hasSearched = "match (u:Person {name: \"" . $unifiedName . "\"}) return has(u.hasSearched) as hasSearched";
    $query = new Query($client, $hasSearched);
    $result = $query->getResultSet();
    foreach ($result as $r) {
        if ($r['hasSearched']) {
            //The user has been searched before. No need to re-search it
            return;
        } else {
            //The user has NOT been seasrched before.
            //Get the affiliation of this user
            $getAffiliation = "match (u:Person {name: \"" . $unifiedName . "\"}) return u.affiliation as affiliation";
            $query = new Query($client, $getAffiliation);
            $result = $query->getResultSet();
            foreach ($result as $r) {
                if (!empty($r['affiliation'])) {
                    //Affiliation info presented
                    $affiliation = filterAffiliation($r['affiliation']);
                } else {
                    //Affiliation info empty
                    $affiliation = "";
                }
            }
            $setHasSearched = "match (u:Person {name: \"" . $unifiedName . "\"}) set u.hasSearched = 1";
            $query = new Query($client, $setHasSearched);
            $result = $query->getResultSet();
            //echo $affiliation."\n";
            $crawler = new CoauthorNetworkCrawler($unifiedName, $affiliation);
            //print_r($crawler->crawlPubmed());
            $crawler->insertDB('localhost', 7474, 'neo4j', 'muresearch');
            return;
        }
    }
}
コード例 #6
0
 public function getVoteOfUser($classification_id, $user_id)
 {
     $query = "match (person:person)-[r]-(n:productionClassification) where id(n) = {$classification_id} AND id(person) = {$user_id} return r";
     $client = $this->getClient();
     $cypher_query = new Query($client, $query);
     $result = $cypher_query->getResultSet();
     if ($result->count() > 0) {
         return $result->current()->current();
     } else {
         return null;
     }
 }
コード例 #7
0
 public function map(Object $node)
 {
     $mapper = $this->mapper;
     $pair = $mapper($node);
     $property_name = key($pair);
     // Note that because this update bypasses `Node#save`, reindexing will have to be done manually after mapping.
     // This is by design, as you might want to perform multiple mappings and indexing is expensive, so it should be done last.
     $query_string = 'MATCH (n) WHERE id(n) = ' . $node->getId() . ' SET n.`' . $property_name . '` = {value}';
     // If a different property name is returned, remove it.
     if ($property_name !== $this->property_name) {
         $query_string = $query_string . ' REMOVE n.`' . $this->property_name . '`';
     }
     $query_string = $query_string . ' RETURN n';
     $query_params = array('value' => $pair[$property_name]);
     $query = new Neo4j\Cypher\Query($node->getClient(), $query_string, $query_params);
     $query->getResultSet();
 }
コード例 #8
0
 public function createDonatur(Request $request)
 {
     // $Book = Book::create($request->all());
     $client = new Client('localhost', 7474);
     $client->getTransport()->setAuth('neo4j', 'soulmate');
     $transaction = $client->beginTransaction();
     // Add a single query to a transaction, $result is a single ResultSet object
     $label = 'Muzakki';
     $param = 'nanda';
     $cypher = 'CREATE (n:' . $label . ' {username:"******",password:"******"}) return n';
     $query = new Query($client, $cypher);
     $result = $query->getResultSet();
     $status = 'failed';
     if ($transaction->commit()) {
         $status = 'success';
     }
     return response()->json(array('status' => $status));
 }
コード例 #9
0
 /**
  * Show the form for creating a new resource.
  *
  *
  */
 public function familiars(Request $request)
 {
     $depth = $request->query('n', 1);
     $neo4j = DB::connection('neo4j');
     /** @var $neo4j Connection */
     $client = $neo4j->getClient();
     /** @var $client Client */
     //Знаю что так нельзя, но нормально параметр вставить у меня не получилось - матюкается neo4j
     $cql = 'MATCH (x:users)-[friendship*' . $depth . ']-(y) WHERE id(x) = {id} RETURN y';
     $query = new Query($client, $cql, ['id' => Auth::user()->id]);
     $result = $query->getResultSet();
     $results = new Collection();
     foreach ($result as $row) {
         /** @var $row Row */
         $results->add(new User($row['y']->getProperties()));
     }
     return response()->json(['items' => $results->toArray()]);
 }
コード例 #10
0
ファイル: Graph.php プロジェクト: kylephp/wordchains
    /**
     * Get the shortest paths from A to B
     *
     * @param  string $a
     * @param  string $b
     * @return array
     */
    public function getShortestPaths($a, $b)
    {
        $q = new Query($this->db, <<<EOHD
START a=node:words(word='{$a}'), b=node:words(word='{$b}')
MATCH p=allshortestPaths((a)-[:IS_ADJACENT_TO*]->(b))
RETURN p;
EOHD
);
        $resultSet = $q->getResultSet();
        $shortestPaths = array();
        foreach ($resultSet as $row) {
            $path = array();
            foreach ($row['p']->getNodes() as $node) {
                $path[] = $node->getProperty('word');
            }
            $shortestPaths[] = $path;
        }
        return array_unique($shortestPaths, SORT_REGULAR);
    }
コード例 #11
0
ファイル: opinion.php プロジェクト: Toktik/graph-game
function twoStepRelations($neo4j, $relations, $scores, $country)
{
    $query = new Query($neo4j, 'MATCH (n:Country {name: "' . $country . '"})-[r]->(i:Institution)<-[e]-(m:Country) RETURN i, m');
    $result = $query->getResultSet();
    /** @var Row $row */
    foreach ($result as $row) {
        /** @var Node $institution */
        $institution = $row[0];
        $institution = $institution->getProperty('name');
        /** @var Node $targetCountry */
        $targetCountry = $row[1];
        $targetCountry = $targetCountry->getProperty('name');
        if (!isset($relations[$targetCountry])) {
            $relations[$targetCountry] = array('total' => 0, 'reasons' => array());
        }
        $score = $scores['MEMBER_OF'][$institution];
        $relations[$targetCountry]['total'] += $score;
        $relations[$targetCountry]['reasons'][] = 'MEMBER_OF ' . $institution . ' ' . $score;
    }
    return $relations;
}
コード例 #12
0
 public function loginDonatur(Request $request)
 {
     $client = new Client(HelperController::getHost(), HelperController::getPort());
     $client->getTransport()->setAuth(HelperController::getUserNeo4j(), HelperController::getPassNeo4j());
     $username = $request->input('username');
     $password = sha1($request->input('password'));
     $gcmId = $request->input('gcmId');
     $cypher = 'MATCH (n:' . HelperController::getLabelDonatur() . ') where n.username="******" and n.password = "******" RETURN n';
     $query = new Query($client, $cypher);
     $nodes = $query->getResultSet();
     $status = 'failed, check your internet connection';
     $properties = array();
     $isLogin = 0;
     if (count($gcmId) > 0) {
         if (count($nodes) > 0) {
             foreach ($nodes as $node) {
                 $properties['id'] = $node['n']->getId();
                 $properties['username'] = $node['n']->getProperty('username');
                 $properties['password'] = $node['n']->getProperty('password');
                 $isLogin = $node['n']->getProperty('isLogin');
             }
             if ($isLogin == 0) {
                 $status = 'success';
                 $node = $client->getNode($properties['id']);
                 $node->setProperty('gcmId', $gcmId)->setProperty('isLogin', 0)->save();
             } else {
                 $status = 'failed, user already login in other device';
                 $properties = array();
             }
         } else {
             $status = 'failed, check your username and password';
         }
     } else {
         $status = 'failed, check your gcm id';
     }
     return response()->json(array('status' => $status, 'data' => $properties));
 }
コード例 #13
0
 public function updateDonatur(Request $request, $id)
 {
     $client = new Client(HelperController::getHost(), HelperController::getPort());
     $client->getTransport()->setAuth(HelperController::getUserNeo4j(), HelperController::getPassNeo4j());
     $username = $request->input('username');
     $email = $request->input('email');
     $nama = $request->input('nama');
     $notelp = $request->input('notelp');
     $imagePath = $request->input('imagePath');
     $gcmId = $request->input('gcmId');
     $status = 'failed';
     if (count($username) > 0 && count($id) > 0) {
         $cypherCek = 'MATCH (n:' . HelperController::getLabelDonatur() . ') where n.username="******" RETURN n';
         $queryCek = new Query($client, $cypherCek);
         $resultCek = $queryCek->getResultSet();
         if (count($resultCek) > 0) {
             $status = 'failed, data already exist';
         } else {
             $node = $client->getNode($id);
             $node->setProperty('username', $username)->setProperty('email', $email)->setProperty('nama', $nama)->setProperty('notelp', $notelp)->setProperty('imagePath', $imagePath)->setProperty('gcmId', $gcmId)->save();
             $status = 'success';
         }
     } else {
         $status = 'failed, username or id is empty please check your parameter';
     }
     return response()->json(array('status' => $status));
 }
コード例 #14
0
            }
        }
        $movie['cast'][] = $castMember;
    }
    return json_encode($movie);
});
$app->get('/person/{name}', function ($name) use($neo4j) {
    $queryTemplate = <<<QUERY
MATCH (person:Person {name:{name}})
 OPTIONAL MATCH (person)-[r]->(movie:Movie)
 RETURN person.name as name, person.born as born,
       collect({title:movie.title,
                job:head(split(lower(type(r)),'_')),
                role:r.roles}) as movies LIMIT 1
QUERY;
    $cypher = new Query($neo4j, $queryTemplate, array('name' => $name));
    $results = $cypher->getResultSet();
    $result = $results[0];
    $person = array('name' => $result['name'], 'born' => $result['born'], 'movies' => array());
    foreach ($result['movies'] as $member) {
        $movieMember = array('job' => $member['job'], 'title' => $member['title'], 'role' => array());
        if ($member['role']) {
            foreach ($member['role'] as $name) {
                $movieMember['role'][] = $name;
            }
        }
        $person['movies'][] = $movieMember;
    }
    return json_encode($person);
});
$app->run();
コード例 #15
0
 public function execute_query($query_str, $parameters = array())
 {
     try {
         $query = new Query($this->client, $query_str, $parameters);
         //print_r($query);
         return $query->getResultSet();
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
コード例 #16
0
ファイル: Friendship.php プロジェクト: AlexKR/friendly
 /**
  * @param $queryString
  * @param $vars
  * @return array
  * @throws FriendshipException
  */
 public function getQueryResult($queryString, $vars)
 {
     $client = $this->getClient();
     $query = new Cypher\Query($client, $queryString, $vars);
     try {
         $rows = $query->getResultSet();
     } catch (Neo4jException $e) {
         throw new FriendshipException('Cannot execute Neo4j query: ' . $e->getMessage());
     }
     $result = [];
     foreach ($rows as $row) {
         $result[] = $row[0];
     }
     return $result;
 }
コード例 #17
0
ファイル: FindRepository.php プロジェクト: weopendata/medea
 /**
  * Get the count of a query by replacing the RETURN statement
  * This function assumes that find is declared in the query
  *
  * @param  string $query     A cypher query string
  * @param  array  $variables The variables and their variables for the query
  *
  * @return integer
  */
 private function getCount($query, $variables)
 {
     $chunks = explode('RETURN', $query);
     $statement = $chunks[0];
     $countQuery = $statement . ' RETURN count(distinct find) as findCount';
     $countQuery = new Query($this->getClient(), $countQuery, $variables);
     $results = $countQuery->getResultSet();
     $countResult = $results->current();
     return $countResult['findCount'];
 }
コード例 #18
0
 /**
  * @Route("/posts/save/{id}", name="admin_posts_save")
  */
 public function savePostAction(Request $request, $id = null)
 {
     /*
     $em = $this->container->get('neo4j.manager');
     $postRepo = $em->getRepository('AppBundle\\Entity\\Post');
     $authorRepo = $em->getRepository('AppBundle\\Entity\\Author');
     
     $form = $request->request->all();
     
     if($id)
         $post = $postRepo->find($id);
     else
         $post = new Post();
     
     
     $author = $authorRepo->find($form['author']);
     
     $post->setTitle($form['title']);
     $post->setContent($form['content']);
     $post->setAuthor( $author );
     
     $em->persist($post);
     $em->flush();
     */
     $client = new Client();
     $client->getTransport()->setAuth('neo4j', 'password');
     $form = $request->request->all();
     if ($id) {
         $query = new Query($client, "MATCH (n:Post) WHERE n.id = {id} RETURN n", ["id" => $id]);
         $post = $query->getResultSet()->current()['n'];
     }
     if (!$id || !$post) {
         $post = (object) ['id' => null, 'title' => null, 'content' => null, 'author' => null];
     }
     if (!$post->id) {
         // Create new post
         $query = new Query($client, "CREATE n =(post {title:{title}, content:{content}})" . "RETURN n", ["title" => $form['title'], "content" => $form['content']]);
         $post = $query->getResultSet()->current()['n'];
         $query = new Query($client, "MATCH (a:Author),(p:Post)" . "WHERE a.name = {authorName} AND id(p) = {postId}" . "CREATE (a)-[r:AUTHOR {authored_on: {timestamp}}]->(p)" . "RETURN r", ["authorId" => $form['author'], "postId" => $post->getProperty('id'), "timestamp" => strtotime('now')]);
         $relation = $query->getResultSet()->current()['r'];
     } else {
         // Update post
         $query = new Query($client, "MATCH (n {id: {id}})" . "SET n.title = {title}" . "SET n.content = {content}" . "RETURN n");
         $post = $query->getResultSet()->current()['n'];
     }
     return $this->redirectToRoute('admin_posts');
 }
コード例 #19
0
 public function getAllDonasi()
 {
     $client = new Client(HelperController::getHost(), HelperController::getPort());
     $client->getTransport()->setAuth(HelperController::getUserNeo4j(), HelperController::getPassNeo4j());
     $status = 'failed';
     $properties = array();
     $result = array();
     $cypher = 'MATCH (DONATUR)-[r:DONASI]->(MUSTAHIQ) RETURN r LIMIT 100';
     $query = new Query($client, $cypher);
     $nodes = $query->getResultSet();
     if (count($nodes) > 0) {
         $status = 'success';
         foreach ($nodes as $node) {
             $properties['id'] = $node['r']->getId();
             $properties['properties'] = $node['r']->getProperties();
             array_push($result, $properties);
         }
     }
     return response()->json(array('status' => $status, 'data' => $result));
 }
コード例 #20
0
ファイル: cypher.php プロジェクト: MobilityMaster/neo4jphp
    $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') {
        if (!empty($argv[2])) {
            $movie = implode(" ", array_slice($argv, 2));
        } else {
            $movie = "The Matrix";
        }
        $queryTemplate = "START actor=node:actors('name:*') " . "MATCH (actor) -[:IN]- (movie)" . "WHERE movie.title = {title}" . "RETURN actor";
        $query = new Cypher\Query($client, $queryTemplate, array('title' => $movie));
        $result = $query->getResultSet();
        echo "Found " . count($result) . " actors:\n";
        foreach ($result as $row) {
            echo "  " . $row['actor']->getProperty('name') . "\n";
        }
    }
}
コード例 #21
0
ファイル: Neo4j.php プロジェクト: amangion/social_api
 /**
  * @param string $queryTemplate
  * @return \Everyman\Neo4j\Query\ResultSet
  */
 public function query($queryTemplate)
 {
     $query = new Query($this->_client, $queryTemplate);
     return $query->getResultSet();
 }
コード例 #22
0
 private function queryResult($queryStr, $params = [])
 {
     $neo4jCLient = $this->getConnection();
     $query = new Query($neo4jCLient, $queryStr, $params);
     try {
         $res = $query->getResultSet();
     } catch (\Exception $e) {
         throw new RepositoryException('Trapped error while executing query:' . $e->getMessage());
     }
     $result = [];
     foreach ($res as $row) {
         $result[] = $row;
     }
     return $result;
 }
コード例 #23
0
ファイル: ArachnidTest.php プロジェクト: lrezek/arachnid
 function testRelationRemoval()
 {
     $usr1 = new Entity\User();
     $usr2 = new Entity\User();
     $rel = new Entity\FriendsWith();
     $usr1->setFirstName('Arnold');
     $usr1->setLastName('Schwarzenegger');
     $usr1->setTestId($this->id);
     $usr2->setFirstName('Sean');
     $usr2->setLastName('Connery');
     $usr2->setTestId($this->id);
     $rel->setTo($usr2);
     $rel->setFrom($usr1);
     $rel->setSince("1989");
     ArachnidTest::$arachnid->persist($rel);
     ArachnidTest::$arachnid->flush();
     //Get the relation with everyman
     $id = $this->id;
     $queryString = "MATCH (n {firstName:'Arnold', testId:'{$id}'})-[r {since:'1989'}]->(m {firstName:'Sean'}) RETURN r;";
     $query = new EM_QUERY(ArachnidTest::$arachnid->getClient(), $queryString);
     $d = $query->getResultSet();
     //Check the property
     $i = 0;
     foreach ($d as $row) {
         //Check the since property
         $this->assertEquals($row['x']->getProperty("since"), "1989");
         $i++;
     }
     $this->assertEquals(1, $i);
     //Get relation
     $rel = ArachnidTest::$arachnid->reload($rel);
     //Remove it
     $t = microtime(true);
     ArachnidTest::$arachnid->remove($rel);
     ArachnidTest::$arachnid->flush();
     $this->printTime(__FUNCTION__, microtime(true) - $t);
     //Query for it again
     $id = $this->id;
     $queryString = "MATCH (n {firstName:'Arnold', testId:'{$id}'})-[r {since:'1989'}]->(m {firstName:'Sean'}) RETURN r;";
     $query = new EM_QUERY(ArachnidTest::$arachnid->getClient(), $queryString);
     $d = $query->getResultSet();
     //Check the property
     foreach ($d as $row) {
         $this->fail();
     }
 }
コード例 #24
0
 function cypherQuery($string, $parameters)
 {
     try {
         $query = new InternalCypherQuery($this->client, $string, $parameters);
         $rs = $query->getResultSet();
         return $rs;
     } catch (\Everyman\Neo4j\Exception $e) {
         $message = $e->getMessage();
         preg_match('/\\[message\\] => (.*)/', $message, $parts);
         throw new Exception('Query execution failed: ' . $parts[1], 0, $e);
     }
 }
コード例 #25
0
ファイル: Arachnid.php プロジェクト: lrezek/arachnid
 /**
  * Raw cypher query execution.
  *
  * @param string $string The query string.
  * @param array $parameters The arguments to bind with the query.
  * @throws Exception If the query fails.
  * @return \Everyman\Neo4j\Query\ResultSet The everyman result set.
  */
 public function cypherQuery($string, $parameters)
 {
     try {
         $start = microtime(true);
         $query = new InternalCypherQuery($this->client, $string, $parameters);
         $rs = $query->getResultSet();
         $time = microtime(true) - $start;
         $this->triggerEvent(self::QUERY_RUN, $query, $parameters, $time);
         return $rs;
     } catch (EverymanException $e) {
         $message = $e->getMessage();
         preg_match('/\\[message\\] => (.*)/', $message, $parts);
         throw new Exception('Query execution failed: ' . $parts[1], 0, $e, $query);
     }
 }
コード例 #26
0
 public function deleteAllMustahiq()
 {
     $client = new Client(HelperController::getHost(), HelperController::getPort());
     $client->getTransport()->setAuth(HelperController::getUserNeo4j(), HelperController::getPassNeo4j());
     $cypher = 'MATCH (n:Mustahiq) OPTIONAL MATCH (n)-[r]-() DELETE n,r';
     $query = new Query($client, $cypher);
     $query->getResultSet();
     $status = 'success';
     return response()->json(array('status' => $status));
 }
コード例 #27
0
ファイル: EntityManager.php プロジェクト: esynaps/neo4j-ogm
 /**
  * Raw cypher query execution.
  *
  * @param string $string The query string.
  * @param array $parameters The arguments to bind with the query.
  * @throws Exception
  * @return \Everyman\Neo4j\Query\ResultSet
  */
 function cypherQuery($string, array $parameters = array())
 {
     try {
         $start = microtime(true);
         $query = new InternalCypherQuery($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));
         return $rs;
     } catch (\Everyman\Neo4j\Exception $e) {
         $message = $e->getMessage();
         preg_match('/\\[message\\] => (.*)/', $message, $parts);
         throw new Exception('Query execution failed: ' . $parts[1], 0, $e, $query);
     }
 }
コード例 #28
0
ファイル: Importer.php プロジェクト: kylephp/wordchains
    /**
     * Get all words
     *
     * @return array
     */
    public function getWords()
    {
        $q = new Query($this->db, <<<EOHD
START n=node(*)
WHERE has(n.word)
RETURN n.word as word;
EOHD
);
        $words = array();
        $resultSet = $q->getResultSet();
        foreach ($resultSet as $word) {
            $words[] = $word['n'];
        }
        return $words;
    }
コード例 #29
0
 /**
  * Format the given query into a transactional statement
  *
  * @param Query $statement
  * @return array
  */
 protected function formatStatement(Query $statement)
 {
     return array('statement' => $statement->getQuery(), 'parameters' => (object) $statement->getParameters(), 'resultDataContents' => array('rest'));
 }
コード例 #30
0
ファイル: ObjectCollection.php プロジェクト: karwana/penelope
 protected function query($aggregate = null)
 {
     $query_params = array();
     $query_string = $this->getQueryString($aggregate, $query_params);
     // Aggregate results would be unexpected when using limit.
     // Return all objects if page and page size are not set.
     if (!$aggregate and $this->page_size and $this->page) {
         $limit = $this->page_size;
         $query_string .= ' SKIP ' . ($this->page * $limit - $limit) . ' LIMIT ' . $limit;
     }
     // The standard REST API methods for getting nodes by a label don't support paging.
     // Neither do they support querying by multiple properties (only by a single property).
     // This is why we use Cypher instead.
     $query = new Neo4j\Cypher\Query($this->object_schema->getClient(), $query_string, $query_params);
     return $query->getResultSet();
 }