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