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