Skip to content

Commit 204ab38

Browse files
committed
API v2: legacy indexing! Simple usage, uniqueness, auto-indexes. [skip ci]
1 parent 01be8a3 commit 204ab38

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

API_v2.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Sections:
2020
- [Transactions](#transactions)
2121
- [Errors](#errors)
2222
- [Schema](#schema)
23+
- [Legacy Indexing](#legacy-indexing)
2324

2425

2526
## General
@@ -385,3 +386,109 @@ Should multiple properties be supported?
385386
db.getPropertyKeys _
386387
db.getRelationshipTypes _
387388
```
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

Comments
 (0)