@@ -20,6 +20,7 @@ Sections:
20
20
- [ Transactions] ( #transactions )
21
21
- [ Errors] ( #errors )
22
22
- [ Schema] ( #schema )
23
+ - [ Legacy Indexing] ( #legacy-indexing )
23
24
24
25
25
26
## General
@@ -388,3 +389,109 @@ Should multiple properties be supported?
388
389
db .getPropertyKeys _
389
390
db .getRelationshipTypes _
390
391
```
392
+
393
+
394
+ ## Legacy Indexing
395
+
396
+ Neo4j v2's constraint-based indexing has yet to implement much of the
397
+ functionality provided by Neo4j v1's legacy indexing (e.g. relationships,
398
+ support for arrays, fulltext indexing).
399
+ This driver thus provides legacy indexing APIs.
400
+
401
+ ### Management
402
+
403
+ ``` coffee
404
+ db .getLegacyNodeIndexes _
405
+ db .getLegacyNodeIndex {name}, _
406
+ db .createLegacyNodeIndex {name, config}, _
407
+ db .deleteLegacyNodeIndex {name}, _
408
+
409
+ db .getLegacyRelationshipIndexes _
410
+ db .getLegacyRelationshipIndex {name}, _
411
+ db .createLegacyRelationshipIndex {name, config}, _
412
+ db .deleteLegacyRelationshipIndex {name}, _
413
+ ```
414
+
415
+ Both returned legacy node indexes and legacy relationship indexes are
416
+ minimal ` LegacyIndex ` objects:
417
+
418
+ ``` coffee
419
+ class LegacyIndex {name, config}
420
+ ```
421
+
422
+ The ` config ` property is e.g. ` {provider: 'lucene', type: 'fulltext'} ` ;
423
+ [ full documentation here] ( http://neo4j.com/docs/stable/indexing-create-advanced.html ) .
424
+
425
+ ### Simple Usage
426
+
427
+ ``` coffee
428
+ db .addNodeToLegacyIndex {name, key, value, _id}
429
+ db .getNodesFromLegacyIndex {name, key, value} # key-value lookup
430
+ db .getNodesFromLegacyIndex {name, query} # arbitrary Lucene query
431
+ db .removeNodeFromLegacyIndex {name, key, value, _id} # key, value optional
432
+
433
+ db .addRelationshipToLegacyIndex {name, key, value, _id}
434
+ db .getRelationshipsFromLegacyIndex {name, key, value} # key-value lookup
435
+ db .getRelationshipsFromLegacyIndex {name, query} # arbitrary Lucene query
436
+ db .removeRelationshipFromLegacyIndex {name, key, value, _id} # key, value optional
437
+ ```
438
+
439
+ ### Uniqueness
440
+
441
+ Neo4j v1's legacy indexing provides a uniqueness constraint for
442
+ adding (existing) and creating (new) nodes and relationships.
443
+ It has two modes:
444
+
445
+ - "Get or create": if an existing node or relationship is found for the given
446
+ key and value, return it, otherwise add this node or relationship
447
+ (creating it if it's new).
448
+
449
+ - "Create or fail": if an existing node or relationship is found for the given
450
+ key and value, fail, otherwise add this node or relationship
451
+ (creating it if it's new).
452
+
453
+ For adding existing nodes or relationships, simply pass ` unique: true ` to the
454
+ ` add ` method.
455
+
456
+ ``` coffee
457
+ db .addNodeToLegacyIndex {name, key, value, _id, unique : true }
458
+ db .addRelationshipToLegacyIndex {name, key, value, _id, unique : true }
459
+ ```
460
+
461
+ (This defaults to the "create or fail" mode, as it's hard to imagine a
462
+ real-world use case for "get or create" when adding existing nodes.)
463
+
464
+ For creating new nodes or relationships, the ` create ` method below corresponds
465
+ with "create or fail", while ` getOrCreate ` corresponds with "get or create":
466
+
467
+ ``` coffee
468
+ db .createNodeFromLegacyIndex {name, key, value, properties}
469
+ db .getOrCreateNodeFromLegacyIndex {name, key, value, properties}
470
+
471
+ db .createRelationshipFromLegacyIndex {name, key, value, type, properties, _fromId, _toId}
472
+ db .getOrCreateRelationshipFromLegacyIndex {name, key, value, type, properties, _fromId, _toId}
473
+ ```
474
+
475
+ ### Auto-Indexes
476
+
477
+ Neo4j provides two automatic legacy indexes:
478
+ ` node_auto_index ` and ` relationship_auto_index ` .
479
+ Instead of hardcoding those index names in your app,
480
+ Neo4j provides separate legacy auto-indexing APIs,
481
+ which this driver exposes as well.
482
+
483
+ The APIs are effectively the same as the above;
484
+ just replace ` LegacyIndex ` with ` LegacyAutoIndex ` in all method names,
485
+ then omit the ` name ` parameter.
486
+
487
+ ``` coffee
488
+ db .getNodesFromLegacyAutoIndex {key, value} # key-value lookup
489
+ db .getNodesFromLegacyAutoIndex {query} # arbitrary Lucene query
490
+ db .createNodeFromLegacyAutoIndex {key, value, properties}
491
+ db .getOrCreateNodeFromLegacyAutoIndex {key, value, properties}
492
+
493
+ db .getRelationshipsFromLegacyAutoIndex {key, value} # key-value lookup
494
+ db .getRelationshipsFromLegacyAutoIndex {query} # arbitrary Lucene query
495
+ db .createRelationshipFromLegacyAutoIndex {key, value, type, properties, _fromId, _toId}
496
+ db .getOrCreateRelationshipFromLegacyAutoIndex {key, value, type, properties, _fromId, _toId}
497
+ ```
0 commit comments