/** * Initialize the index * * @param Client $client * @param string $name * @param array $config */ public function __construct(Client $client, $name, $config = array()) { if (empty($config['type'])) { $config['type'] = 'fulltext'; } if (empty($config['provider'])) { $config['provider'] = 'lucene'; } parent::__construct($client, $name, $config); }
Usage: {$argv[0]} \tDisplay usage instructions {$argv[0]} init \tInitialize the data. This only needs to be done once. {$argv[0]} actors <movie_name> \tGet a list of all actors in the movie. HELP; exit(0); } $client = new Client(); $actors = new NodeIndex($client, 'actors'); // 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();
#!/usr/bin/env php <?php use Everyman\Neo4j\Client, Everyman\Neo4j\Index\NodeIndex, Everyman\Neo4j\Index\RelationshipIndex, Everyman\Neo4j\Index\NodeFulltextIndex, Everyman\Neo4j\Node, Everyman\Neo4j\Batch; require_once 'example_bootstrap.php'; $client = new Client(); $actorIndex = new NodeIndex($client, 'actors'); $roleIndex = new RelationshipIndex($client, 'roles'); $plotIndex = new NodeFulltextIndex($client, 'plots'); $plotIndex->save(); $leslie = $client->makeNode()->setProperty('name', 'Leslie Nielsen')->save(); $airplane = $client->makeNode()->setProperty('title', 'Airplane')->save(); $rumack = $leslie->relateTo($airplane, 'PLAYED')->setProperty('character', 'Dr. Rumack')->save(); $actorIndex->add($leslie, 'name', $leslie->getProperty('name')); $roleIndex->add($rumack, 'character', $rumack->getProperty('character')); $plotIndex->add($airplane, 'synopsis', 'An airplane crew takes ill. Surely the only person capable of landing the plane is an ex-pilot afraid to fly. But don\'t call him Shirley.'); echo $actorIndex->queryOne('name:Leslie*')->getProperty('name') . "\n"; echo $roleIndex->queryOne('character:*u*')->getProperty('character') . "\n"; echo $plotIndex->queryOne('synopsis:lend~0.2')->getProperty('title') . "\n";
{$argv[0]} map \tDisplay the available points and the connections and distances between them. {$argv[0]} path <start> <end> [<algorithm>] \tFind a path from one node to another. \talgorithm is optional, and can be one of: \t\toptimal: Find the shortest paths by distance. Default. \t\tsimple: Find the shortest paths by number of nodes. \t\tall: Find all paths, regardless of length. HELP; exit(0); } $client = new Client(); $intersections = new NodeIndex($client, 'intersections1'); $inters = array('A' => null, 'B' => null, 'C' => null, 'D' => null, 'E' => null, 'F' => null); $streets = array(array('A', 'B', array('direction' => 'east', 'distance' => 2.1, 'name' => 'AB')), array('A', 'D', array('direction' => 'south', 'distance' => 2.1, 'name' => 'AD')), array('A', 'E', array('direction' => 'south', 'distance' => 3.1, 'name' => 'AE')), array('B', 'A', array('direction' => 'west', 'distance' => 2.1, 'name' => 'AB')), array('B', 'C', array('direction' => 'east', 'distance' => 2.1, 'name' => 'BC')), array('B', 'E', array('direction' => 'south', 'distance' => 2.1, 'name' => 'BE')), array('C', 'B', array('direction' => 'west', 'distance' => 2.1, 'name' => 'BC')), array('C', 'F', array('direction' => 'south', 'distance' => 1.1, 'name' => 'CF')), array('D', 'A', array('direction' => 'north', 'distance' => 2.1, 'name' => 'AD')), array('D', 'E', array('direction' => 'east', 'distance' => 2.1, 'name' => 'DE')), array('E', 'D', array('direction' => 'west', 'distance' => 2.1, 'name' => 'DE')), array('E', 'B', array('direction' => 'north', 'distance' => 2.1, 'name' => 'BE')), array('F', 'C', array('direction' => 'north', 'distance' => 1.1, 'name' => 'CF')), array('F', 'E', array('direction' => 'west', 'distance' => 2.1, 'name' => 'FE'))); $turns = array('east' => array('north' => 'left', 'south' => 'right', 'west' => 'u-turn'), 'west' => array('north' => 'right', 'south' => 'left', 'east' => 'u-turn'), 'north' => array('east' => 'right', 'west' => 'left', 'south' => 'u-turn'), 'south' => array('east' => 'left', 'west' => 'right', 'north' => 'u-turn')); // Initialize the data if ($cmd == 'init') { echo "Initializing data.\n"; foreach ($inters as $inter => $temp) { $node = $client->makeNode()->setProperty('name', $inter)->save(); $intersections->add($node, 'name', $node->getProperty('name')); $inters[$inter] = $node; } foreach ($streets as $info) { $start = $inters[$info[0]]; $end = $inters[$info[1]]; $properties = $info[2];
public function insert_with_index($modelName, $property, $value) { try { /* creating node index */ $nodeIndex = new NodeIndex($this->client, $modelName); /* creating label*/ $label = $this->client->makeLabel($modelName); /* creating node */ $node = $this->client->makeNode()->setProperty($property, $value)->save(); /* labeling node */ $node->addLabels(array($label)); /* adding node to index */ $nodeIndex->add($node, $property, $node->getProperty($property)); return $node->getId(); } catch (Exception $e) { echo $e->getMessage(); } }
Usage: {$argv[0]} \tDisplay usage instructions {$argv[0]} init \tInitialize the data. This only needs to be done once. {$argv[0]} path <from name> <to name> \tFind a path from one actor to another. HELP; exit(0); } $client = new Client(); $actors = new NodeIndex($client, 'actors'); // 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();
{$argv[0]} parts \tDisplay the available parts in the system. {$argv[0]} stores <part> [<language>] \tFind all the stores where the given part was sold. \tLanguage can be one of: \t\ttraverse: use the javascript traversal. Default. \t\tcypher: use a cypher query HELP; exit(0); } $client = new Client(); $partsIndex = new NodeIndex($client, 'parts3'); $parts = array('widget', 'gadget', 'gizmo'); $stores = array("Bob's Old Houseware", "Mainstreet Hardware", "Nutz N' Boltz", "Doodad Emporium"); // Store, part list $orders = array(array(0, array(0, 1)), array(0, array(1)), array(1, array(1, 2)), array(1, array(0, 2)), array(2, array(0, 1, 2)), array(3, array(2)), array(3, array(0))); // Initialize the data if ($cmd == 'init') { echo "Initializing data.\n"; $p = array(); $s = array(); foreach ($parts as $part) { $node = $client->makeNode()->setProperty('name', $part)->save(); $partsIndex->add($node, 'name', $node->getProperty('name')); $p[] = $node; } foreach ($stores as $store) {