mirror of https://gitee.com/bigwinds/arangodb
changed documentation for index creation methods
This commit is contained in:
parent
7c3de62b08
commit
0d2197e77f
|
@ -25,7 +25,7 @@ method of `ArangoStatement`:
|
|||
~addIgnoreCollection("test")
|
||||
db._create("test");
|
||||
for (i = 0; i < 100; ++i) { db.test.save({ value: i }); }
|
||||
db.test.ensureSkiplist("value");
|
||||
db.test.ensureIndex({ type: "skiplist", fields: [ "value" ] });
|
||||
stmt = db._createStatement("FOR i IN test FILTER i.value > 97 SORT i.value RETURN i.value");
|
||||
stmt.explain();
|
||||
@END_EXAMPLE_ARANGOSH_OUTPUT
|
||||
|
|
|
@ -85,15 +85,15 @@ In order to create a sparse index, an object with the attribute `sparse` can be
|
|||
the index creation commands:
|
||||
|
||||
```js
|
||||
db.collection.ensureHashIndex(attributeName, { sparse: true });
|
||||
db.collection.ensureHashIndex(attributeName1, attributeName2, { sparse: true });
|
||||
db.collection.ensureUniqueConstraint(attributeName, { sparse: true });
|
||||
db.collection.ensureUniqueConstraint(attributeName1, attributeName2, { sparse: true });
|
||||
db.collection.ensureIndex({ type: "hash", fields: [ "attributeName" ], sparse: true });
|
||||
db.collection.ensureIndex({ type: "hash", fields: [ "attributeName1", "attributeName2" ], sparse: true });
|
||||
db.collection.ensureIndex({ type: "hash", fields: [ "attributeName" ], unique: true, sparse: true });
|
||||
db.collection.ensureIndex({ type: "hash", fields: [ "attributeName1", "attributeName2" ], unique: true, sparse: true });
|
||||
|
||||
db.collection.ensureSkiplist(attributeName, { sparse: true });
|
||||
db.collection.ensureSkiplist(attributeName1, attributeName2, { sparse: true });
|
||||
db.collection.ensureUniqueSkiplist(attributeName, { sparse: true });
|
||||
db.collection.ensureUniqueSkiplist(attributeName1, attributeName2, { sparse: true });
|
||||
db.collection.ensureIndex({ type: "skiplist", fields: [ "attributeName" ], sparse: true });
|
||||
db.collection.ensureIndex({ type: "skiplist", fields: [ "attributeName1", "attributeName2" ], sparse: true });
|
||||
db.collection.ensureIndex({ type: "skiplist", fields: [ "attributeName" ], unique: true, sparse: true });
|
||||
db.collection.ensureIndex({ type: "skiplist", fields: [ "attributeName1", "attributeName2" ], unique: true, sparse: true });
|
||||
```
|
||||
|
||||
When not explicitly set, the `sparse` attribute defaults to `false` for new indexes.
|
||||
|
@ -130,6 +130,5 @@ index range does not include `null` for any of the index attributes.
|
|||
|
||||
Note that if you intend to use [joins](../AqlExamples/Join.html) it may be clever
|
||||
to use non-sparsity and maybe even uniqueness for that attribute, else all items containing
|
||||
the NULL-value will match against each other and thus produce large results.
|
||||
|
||||
the `null` value will match against each other and thus produce large results.
|
||||
|
||||
|
|
|
@ -37,7 +37,10 @@ db._index("demo/362549736");
|
|||
@startDocuBlock collectionGetIndexes
|
||||
|
||||
!SUBSECTION Creating an index
|
||||
Indexes can be created using the general method *ensureIndex*, or *ensure<type>Index* (see the respective subchapters that also describe the behavior of this index in more detail.
|
||||
Indexes should be created using the general method *ensureIndex*. This
|
||||
method obsoletes the specialized index-specific methods *ensureHashIndex*,
|
||||
*ensureSkiplist*, *ensureUniqueConstraint* etc.
|
||||
|
||||
<!-- arangod/V8Server/v8-vocindex.cpp -->
|
||||
@startDocuBlock collectionEnsureIndex
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ For example, to index the following documents, an index can be created on the
|
|||
db.test.save({ position: [ -10, 30 ] });
|
||||
db.test.save({ position: [ 10, 45.5 ] });
|
||||
|
||||
db.test.ensureGeoIndex("position");
|
||||
db.test.ensureIndex({ type: "geo", fields: [ "position" ] });
|
||||
|
||||
If coordinates are stored in two distinct attributes, the index must be created
|
||||
on the two attributes:
|
||||
|
@ -25,7 +25,7 @@ on the two attributes:
|
|||
db.test.save({ latitude: -10, longitude: 30 });
|
||||
db.test.save({ latitude: 10, longitude: 45.5 });
|
||||
|
||||
db.test.ensureGeoIndex("latitude", "longitude");
|
||||
db.test.ensureIndex({ type: "geo", fields: [ "latitude", "longitude" ] });
|
||||
|
||||
In order to find all documents within a given radius around a coordinate use
|
||||
the *within* operator. In order to find all documents near a given document
|
||||
|
|
|
@ -279,7 +279,7 @@ start. The following example using a cap constraint should illustrate that:
|
|||
db._create("c1");
|
||||
|
||||
// limit the number of documents to 3
|
||||
db.c1.ensureCapConstraint(3);
|
||||
db.c1.ensureIndex({ type: "cap", size: 3 });
|
||||
|
||||
// insert 3 documents
|
||||
db.c1.save({ _key: "key1" });
|
||||
|
|
|
@ -366,8 +366,10 @@ triagens::aql::AstNode* SimpleAttributeEqualityMatcher::specializeAll (triagens:
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief determine the costs of using this index
|
||||
/// costs returned are scaled from 0.0 to 1.0, with 0.0 being the lowest cost
|
||||
/// @brief determine the costs of using this index and the number of items
|
||||
/// that will return in average
|
||||
/// cost values have no special meaning, except that multiple cost values are
|
||||
/// comparable, and lower values mean lower costs
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SimpleAttributeEqualityMatcher::calculateIndexCosts (triagens::arango::Index const* index,
|
||||
|
|
|
@ -138,8 +138,10 @@ namespace triagens {
|
|||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief determine the costs of using this index
|
||||
/// costs returned are scaled from 0.0 to 1.0, with 0.0 being the lowest cost
|
||||
/// @brief determine the costs of using this index and the number of items
|
||||
/// that will return in average
|
||||
/// cost values have no special meaning, except that multiple cost values are
|
||||
/// comparable, and lower values mean lower costs
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void calculateIndexCosts (triagens::arango::Index const*,
|
||||
|
|
|
@ -459,7 +459,7 @@ ArangoCollection.prototype.byConditionSkiplist = function (index, condition) {
|
|||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{005_collectionRange}
|
||||
/// ~ db._create("old");
|
||||
/// db.old.ensureSkiplist("age");
|
||||
/// db.old.ensureIndex({ type: "skiplist", fields: [ "age" ] });
|
||||
/// db.old.save({ age: 15 });
|
||||
/// db.old.save({ age: 25 });
|
||||
/// db.old.save({ age: 30 });
|
||||
|
@ -505,7 +505,7 @@ ArangoCollection.prototype.range = function (name, left, right) {
|
|||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{006_collectionClosedRange}
|
||||
/// ~ db._create("old");
|
||||
/// db.old.ensureSkiplist("age");
|
||||
/// db.old.ensureIndex({ type: "skiplist", fields: [ "age" ] });
|
||||
/// db.old.save({ age: 15 });
|
||||
/// db.old.save({ age: 25 });
|
||||
/// db.old.save({ age: 30 });
|
||||
|
@ -571,10 +571,10 @@ ArangoCollection.prototype.closedRange = function (name, left, right) {
|
|||
/// |}
|
||||
///
|
||||
/// db.complex.near(0, 170).limit(5); // xpError(ERROR_QUERY_GEO_INDEX_MISSING)
|
||||
/// db.complex.ensureGeoIndex("home");
|
||||
/// db.complex.ensureIndex({ type: "geo", fields: [ "home" ] });
|
||||
/// db.complex.near(0, 170).limit(5).toArray();
|
||||
/// db.complex.geo("work").near(0, 170).limit(5); // xpError(ERROR_QUERY_GEO_INDEX_MISSING)
|
||||
/// db.complex.ensureGeoIndex("work");
|
||||
/// db.complex.ensureIndex({ type: "geo", fields: [ "work" ] });
|
||||
/// db.complex.geo("work").near(0, 170).limit(5).toArray();
|
||||
/// ~ db._drop("complex");
|
||||
/// @END_EXAMPLE_ARANGOSH_OUTPUT
|
||||
|
@ -695,7 +695,7 @@ ArangoCollection.prototype.geo = function(loc, order) {
|
|||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{007_collectionNear}
|
||||
/// ~ db._create("geo");
|
||||
/// db.geo.ensureGeoIndex("loc");
|
||||
/// db.geo.ensureIndex({ type: "geo", fields: [ "loc" ] });
|
||||
/// |for (var i = -90; i <= 90; i += 10) {
|
||||
/// | for (var j = -180; j <= 180; j += 10) {
|
||||
/// | db.geo.save({
|
||||
|
@ -711,7 +711,7 @@ ArangoCollection.prototype.geo = function(loc, order) {
|
|||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{008_collectionNearDistance}
|
||||
/// ~ db._create("geo");
|
||||
/// db.geo.ensureGeoIndex("loc");
|
||||
/// db.geo.ensureIndex({ type: "geo", fields: [ "loc" ] });
|
||||
/// |for (var i = -90; i <= 90; i += 10) {
|
||||
/// | for (var j = -180; j <= 180; j += 10) {
|
||||
/// | db.geo.save({
|
||||
|
@ -768,7 +768,7 @@ ArangoCollection.prototype.near = function (lat, lon) {
|
|||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{009_collectionWithin}
|
||||
/// ~ db._create("geo");
|
||||
/// ~ db.geo.ensureGeoIndex("loc");
|
||||
/// ~ db.geo.ensureIndex({ type: "geo", fields: [ "loc" ] });
|
||||
/// |~ for (var i = -90; i <= 90; i += 10) {
|
||||
/// | for (var j = -180; j <= 180; j += 10) {
|
||||
/// db.geo.save({ name : "Name/" + i + "/" + j, loc: [ i, j ] }); } }
|
||||
|
@ -820,7 +820,7 @@ ArangoCollection.prototype.fulltext = function (attribute, query, iid) {
|
|||
/// | }
|
||||
/// |}
|
||||
///
|
||||
/// db.example.ensureGeoIndex("home");
|
||||
/// db.example.ensureIndex({ type: "geo", fields: [ "home" ] });
|
||||
/// |items = db.example.getIndexes().map(function(x) { return x.id; });
|
||||
/// db.example.index(items[1]);
|
||||
/// ~ db._drop("example");
|
||||
|
|
|
@ -458,7 +458,7 @@ ArangoCollection.prototype.byConditionSkiplist = function (index, condition) {
|
|||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{005_collectionRange}
|
||||
/// ~ db._create("old");
|
||||
/// db.old.ensureSkiplist("age");
|
||||
/// db.old.ensureIndex({ type: "skiplist", fields: [ "age" ] });
|
||||
/// db.old.save({ age: 15 });
|
||||
/// db.old.save({ age: 25 });
|
||||
/// db.old.save({ age: 30 });
|
||||
|
@ -504,7 +504,7 @@ ArangoCollection.prototype.range = function (name, left, right) {
|
|||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{006_collectionClosedRange}
|
||||
/// ~ db._create("old");
|
||||
/// db.old.ensureSkiplist("age");
|
||||
/// db.old.ensureIndex({ type: "skiplist", fields: [ "age" ] });
|
||||
/// db.old.save({ age: 15 });
|
||||
/// db.old.save({ age: 25 });
|
||||
/// db.old.save({ age: 30 });
|
||||
|
@ -570,10 +570,10 @@ ArangoCollection.prototype.closedRange = function (name, left, right) {
|
|||
/// |}
|
||||
///
|
||||
/// db.complex.near(0, 170).limit(5); // xpError(ERROR_QUERY_GEO_INDEX_MISSING)
|
||||
/// db.complex.ensureGeoIndex("home");
|
||||
/// db.complex.ensureIndex({ type: "geo", fields: [ "home" ] });
|
||||
/// db.complex.near(0, 170).limit(5).toArray();
|
||||
/// db.complex.geo("work").near(0, 170).limit(5); // xpError(ERROR_QUERY_GEO_INDEX_MISSING)
|
||||
/// db.complex.ensureGeoIndex("work");
|
||||
/// db.complex.ensureIndex({ type: "geo", fields: [ "work" ] });
|
||||
/// db.complex.geo("work").near(0, 170).limit(5).toArray();
|
||||
/// ~ db._drop("complex");
|
||||
/// @END_EXAMPLE_ARANGOSH_OUTPUT
|
||||
|
@ -694,7 +694,7 @@ ArangoCollection.prototype.geo = function(loc, order) {
|
|||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{007_collectionNear}
|
||||
/// ~ db._create("geo");
|
||||
/// db.geo.ensureGeoIndex("loc");
|
||||
/// db.geo.ensureIndex({ type: "geo", fields: [ "loc" ] });
|
||||
/// |for (var i = -90; i <= 90; i += 10) {
|
||||
/// | for (var j = -180; j <= 180; j += 10) {
|
||||
/// | db.geo.save({
|
||||
|
@ -710,7 +710,7 @@ ArangoCollection.prototype.geo = function(loc, order) {
|
|||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{008_collectionNearDistance}
|
||||
/// ~ db._create("geo");
|
||||
/// db.geo.ensureGeoIndex("loc");
|
||||
/// db.geo.ensureIndex({ type: "geo", fields: [ "loc" ] });
|
||||
/// |for (var i = -90; i <= 90; i += 10) {
|
||||
/// | for (var j = -180; j <= 180; j += 10) {
|
||||
/// | db.geo.save({
|
||||
|
@ -767,7 +767,7 @@ ArangoCollection.prototype.near = function (lat, lon) {
|
|||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{009_collectionWithin}
|
||||
/// ~ db._create("geo");
|
||||
/// ~ db.geo.ensureGeoIndex("loc");
|
||||
/// ~ db.geo.ensureIndex({ type: "geo", fields: [ "loc" ] });
|
||||
/// |~ for (var i = -90; i <= 90; i += 10) {
|
||||
/// | for (var j = -180; j <= 180; j += 10) {
|
||||
/// db.geo.save({ name : "Name/" + i + "/" + j, loc: [ i, j ] }); } }
|
||||
|
@ -819,7 +819,7 @@ ArangoCollection.prototype.fulltext = function (attribute, query, iid) {
|
|||
/// | }
|
||||
/// |}
|
||||
///
|
||||
/// db.example.ensureGeoIndex("home");
|
||||
/// db.example.ensureIndex({ type: "geo", fields: [ "home" ] });
|
||||
/// |items = db.example.getIndexes().map(function(x) { return x.id; });
|
||||
/// db.example.index(items[1]);
|
||||
/// ~ db._drop("example");
|
||||
|
|
|
@ -1093,7 +1093,7 @@ exports.createLocations = function (name, usersCollection, limit) {
|
|||
collection.truncate();
|
||||
}
|
||||
|
||||
collection.ensureGeoIndex("location");
|
||||
collection.ensureIndex({ type: "geo", fields: [ "location" ] });
|
||||
|
||||
var cursor = usersCollection.all();
|
||||
var lat = 59;
|
||||
|
|
|
@ -56,7 +56,7 @@ var getStorage = function() {
|
|||
var c = db._collection("_apps");
|
||||
if (c === null) {
|
||||
c = db._create("_apps", {isSystem: true});
|
||||
c.ensureUniqueConstraint("mount");
|
||||
c.ensureIndex({ type: "hash", fields: [ "mount" ], unique: true });
|
||||
}
|
||||
return c;
|
||||
};
|
||||
|
|
|
@ -891,7 +891,7 @@ ArangoCollection.prototype.updateByExample = function (example,
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief ensures that a cap constraint exists
|
||||
/// @startDocuBlock collectionEnsureCapConstraint
|
||||
/// `collection.ensureCapConstraint(size, byteSize)`
|
||||
/// `collection.ensureIndex({ type: "cap", size: size, byteSize: byteSize })`
|
||||
///
|
||||
/// Creates a size restriction aka cap for the collection of `size`
|
||||
/// documents and/or `byteSize` data size. If the restriction is in place
|
||||
|
@ -918,7 +918,7 @@ ArangoCollection.prototype.updateByExample = function (example,
|
|||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{collectionEnsureCapConstraint}
|
||||
/// ~db._create('examples');
|
||||
/// db.examples.ensureCapConstraint(10);
|
||||
/// db.examples.ensureIndex({ type: "cap", size: 10 });
|
||||
/// for (var i = 0; i < 20; ++i) { var d = db.examples.save( { n : i } ); }
|
||||
/// db.examples.count();
|
||||
/// ~db._drop('examples');
|
||||
|
@ -940,19 +940,19 @@ ArangoCollection.prototype.ensureCapConstraint = function (size, byteSize) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief ensures that a unique skiplist index exists
|
||||
/// @startDocuBlock ensureUniqueSkiplist
|
||||
/// `collection.ensureUniqueSkiplist(field1, field2, ..., fieldn)`
|
||||
/// `collection.ensureIndex({ type: "skiplist", fields: [ "field1", ..., "fieldn" ], unique: true })`
|
||||
///
|
||||
/// Creates a unique skiplist index on all documents using *field1*, *field2*, ...
|
||||
/// Creates a unique skiplist index on all documents using *field1*, ... *fieldn*
|
||||
/// as attribute paths. At least one attribute path has to be given. The index will
|
||||
/// be non-sparse by default.
|
||||
/// be non-sparse by default.
|
||||
///
|
||||
/// All documents in the collection must differ in terms of the indexed
|
||||
/// attributes. Creating a new document or updating an existing document will
|
||||
/// will fail if the attribute uniqueness is violated.
|
||||
///
|
||||
/// To create a sparse index, use the following command:
|
||||
/// To create a sparse unique index, set the *sparse* attribute to `true`:
|
||||
///
|
||||
/// `collection.ensureUniqueSkiplist(field1, field2, ..., fieldn, { sparse: true })`
|
||||
/// `collection.ensureIndex({ type: "skiplist", fields: [ "field1", ..., "fieldn" ], unique: true, sparse: true })`
|
||||
///
|
||||
/// In a sparse index all documents will be excluded from the index that do not
|
||||
/// contain at least one of the specified index attributes or that have a value
|
||||
|
@ -968,7 +968,7 @@ ArangoCollection.prototype.ensureCapConstraint = function (size, byteSize) {
|
|||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{ensureUniqueSkiplist}
|
||||
/// ~db._create("ids");
|
||||
/// db.ids.ensureUniqueSkiplist("myId");
|
||||
/// db.ids.ensureIndex({ type: "skiplist", fields: [ "myId" ], unique: true });
|
||||
/// db.ids.save({ "myId": 123 });
|
||||
/// db.ids.save({ "myId": 456 });
|
||||
/// db.ids.save({ "myId": 789 });
|
||||
|
@ -977,7 +977,7 @@ ArangoCollection.prototype.ensureCapConstraint = function (size, byteSize) {
|
|||
/// @END_EXAMPLE_ARANGOSH_OUTPUT
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{ensureUniqueSkiplistMultiColmun}
|
||||
/// ~db._create("ids");
|
||||
/// db.ids.ensureUniqueSkiplist("name.first", "name.last");
|
||||
/// db.ids.ensureIndex({ type: "skiplist", fields: [ "name.first", "name.last" ], unique: true });
|
||||
/// db.ids.save({ "name" : { "first" : "hans", "last": "hansen" }});
|
||||
/// db.ids.save({ "name" : { "first" : "jens", "last": "jensen" }});
|
||||
/// db.ids.save({ "name" : { "first" : "hans", "last": "jensen" }});
|
||||
|
@ -1001,24 +1001,20 @@ ArangoCollection.prototype.ensureUniqueSkiplist = function () {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief ensures that a non-unique skiplist index exists
|
||||
/// @startDocuBlock ensureSkiplist
|
||||
/// `collection.ensureSkiplist(field1, field2, ..., fieldn)`
|
||||
/// `collection.ensureIndex({ type: "skiplist", fields: [ "field1", ..., "fieldn" ] })`
|
||||
///
|
||||
/// Creates a non-unique skiplist index on all documents using *field1*,
|
||||
/// *field2*, ... as attribute paths. At least one attribute path has to be given.
|
||||
/// Creates a non-unique skiplist index on all documents using *field1*, ...
|
||||
/// *fieldn* as attribute paths. At least one attribute path has to be given.
|
||||
/// The index will be non-sparse by default.
|
||||
///
|
||||
/// Additional index options can be specified in the *options* argument. If
|
||||
/// set, it has to be an object. Currently the following index options are
|
||||
/// supported:
|
||||
///
|
||||
/// - *sparse*: controls if the index is sparse. The default is *false*.
|
||||
/// To create a sparse unique index, set the *sparse* attribute to `true`.
|
||||
///
|
||||
/// In case that the index was successfully created, an object with the index
|
||||
/// details, including the index-identifier, is returned.
|
||||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{ensureSkiplist}
|
||||
/// ~db._create("names");
|
||||
/// db.names.ensureSkiplist("first");
|
||||
/// db.names.ensureIndex({ type: "skiplist", fields: [ "first" ] });
|
||||
/// db.names.save({ "first" : "Tim" });
|
||||
/// db.names.save({ "first" : "Tom" });
|
||||
/// db.names.save({ "first" : "John" });
|
||||
|
@ -1039,8 +1035,8 @@ ArangoCollection.prototype.ensureSkiplist = function () {
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief ensures that a fulltext index exists
|
||||
/// @startDocuBlock ensureFulltextIndex
|
||||
/// `ensureFulltextIndex(field, minWordLength)`
|
||||
/// @startDocuBlock ensureIndex
|
||||
/// `collection.ensureIndex({ type: "fulltext", fields: [ "field" ], minLength: minLength })`
|
||||
///
|
||||
/// Creates a fulltext index on all documents on attribute *field*.
|
||||
///
|
||||
|
@ -1052,8 +1048,8 @@ ArangoCollection.prototype.ensureSkiplist = function () {
|
|||
/// unsupported.
|
||||
///
|
||||
/// The minimum length of words that are indexed can be specified via the
|
||||
/// *minWordLength* parameter. Words shorter than minWordLength characters will
|
||||
/// not be indexed. *minWordLength* has a default value of 2, but this value might
|
||||
/// *minLength* parameter. Words shorter than minLength characters will
|
||||
/// not be indexed. *minLength* has a default value of 2, but this value might
|
||||
/// be changed in future versions of ArangoDB. It is thus recommended to explicitly
|
||||
/// specify this value.
|
||||
///
|
||||
|
@ -1062,7 +1058,7 @@ ArangoCollection.prototype.ensureSkiplist = function () {
|
|||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{ensureFulltextIndex}
|
||||
/// ~db._create("example");
|
||||
/// db.example.ensureFulltextIndex("text");
|
||||
/// db.example.ensureIndex({ type: "fulltext", fields: [ "text" ], minLength: 3 });
|
||||
/// db.example.save({ text : "the quick brown", b : { c : 1 } });
|
||||
/// db.example.save({ text : "quick brown fox", b : { c : 2 } });
|
||||
/// db.example.save({ text : "brown fox jums", b : { c : 3 } });
|
||||
|
@ -1093,19 +1089,19 @@ ArangoCollection.prototype.ensureFulltextIndex = function (field, minLength) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief ensures that a unique constraint exists
|
||||
/// @startDocuBlock ensureUniqueConstraint
|
||||
/// `collection.ensureUniqueConstraint(field1, field2, ..., fieldn)`
|
||||
/// `collection.ensureIndex({ type: "hash", fields: [ "field1", ..., "fieldn" ], unique: true })`
|
||||
///
|
||||
/// Creates a unique hash index on all documents using *field1*, *field2*,
|
||||
/// ... as attribute paths. At least one attribute path has to be given.
|
||||
/// Creates a unique hash index on all documents using *field1*, ... *fieldn*
|
||||
/// as attribute paths. At least one attribute path has to be given.
|
||||
/// The index will be non-sparse by default.
|
||||
///
|
||||
/// All documents in the collection must differ in terms of the indexed
|
||||
/// attributes. Creating a new document or updating an existing document will
|
||||
/// will fail if the attribute uniqueness is violated.
|
||||
///
|
||||
/// To create a sparse index, use the following command:
|
||||
/// To create a sparse unique index, set the *sparse* attribute to `true`:
|
||||
///
|
||||
/// `collection.ensureUniqueConstraint(field1, field2, ..., fieldn, { sparse: true })`
|
||||
/// `collection.ensureIndex({ type: "hash", fields: [ "field1", ..., "fieldn" ], unique: true, sparse: true })`
|
||||
///
|
||||
/// In case that the index was successfully created, the index identifier is returned.
|
||||
///
|
||||
|
@ -1122,7 +1118,7 @@ ArangoCollection.prototype.ensureFulltextIndex = function (field, minLength) {
|
|||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{ensureUniqueConstraint}
|
||||
/// ~db._create("test");
|
||||
/// db.test.ensureUniqueConstraint("a", "b.c");
|
||||
/// db.test.ensureIndex({ type: "hash", fields: [ "a", "b.c" ], unique: true });
|
||||
/// db.test.save({ a : 1, b : { c : 1 } });
|
||||
/// db.test.save({ a : 1, b : { c : 1 } }); // xpError(ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED)
|
||||
/// db.test.save({ a : 1, b : { c : null } });
|
||||
|
@ -1144,22 +1140,22 @@ ArangoCollection.prototype.ensureUniqueConstraint = function () {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief ensures that a non-unique hash index exists
|
||||
/// @startDocuBlock ensureHashIndex
|
||||
/// `collection.ensureHashIndex(field1, field2, ..., fieldn)`
|
||||
/// `collection.ensureIndex({ type: "hash", fields: [ "field1", ..., "fieldn" ] })`
|
||||
///
|
||||
/// Creates a non-unique hash index on all documents using *field1*, *field2*
|
||||
/// ... as attribute paths. At least one attribute path has to be given.
|
||||
/// Creates a non-unique hash index on all documents using *field1*, ... *fieldn*
|
||||
/// as attribute paths. At least one attribute path has to be given.
|
||||
/// The index will be non-sparse by default.
|
||||
///
|
||||
/// To create a sparse index, use the following command:
|
||||
///
|
||||
/// `collection.ensureHashIndex(field1, field2, ..., fieldn, { sparse: true })`
|
||||
/// To create a sparse unique index, set the *sparse* attribute to `true`:
|
||||
///
|
||||
/// `collection.ensureIndex({ type: "hash", fields: [ "field1", ..., "fieldn" ], sparse: true })`
|
||||
///
|
||||
/// In case that the index was successfully created, an object with the index
|
||||
/// details, including the index-identifier, is returned.
|
||||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{ensureHashIndex}
|
||||
/// ~db._create("test");
|
||||
/// db.test.ensureHashIndex("a");
|
||||
/// db.test.ensureIndex({ type: "hash", fields: [ "a" ] });
|
||||
/// db.test.save({ a : 1 });
|
||||
/// db.test.save({ a : 1 });
|
||||
/// db.test.save({ a : null });
|
||||
|
@ -1179,7 +1175,7 @@ ArangoCollection.prototype.ensureHashIndex = function () {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief ensures that a geo index exists
|
||||
/// @startDocuBlock collectionEnsureGeoIndex
|
||||
/// `collection.ensureGeoIndex(location)`
|
||||
/// `collection.ensureIndex({ type: "geo", fields: [ "location" ] })`
|
||||
///
|
||||
/// Creates a geo-spatial index on all documents using *location* as path to
|
||||
/// the coordinates. The value of the attribute has to be an array with at least two
|
||||
|
@ -1194,23 +1190,17 @@ ArangoCollection.prototype.ensureHashIndex = function () {
|
|||
/// In case that the index was successfully created, an object with the index
|
||||
/// details, including the index-identifier, is returned.
|
||||
///
|
||||
/// `collection.ensureGeoIndex(location, true)`
|
||||
///
|
||||
/// As above whith the exception, that the order within the array is longitude
|
||||
/// followed by latitude. This corresponds to the format described in
|
||||
/// To create a geo on an array attribute that contains longitude first, set the
|
||||
/// *geoJson* attribute to `true`. This corresponds to the format described in
|
||||
/// [positions](http://geojson.org/geojson-spec.html)
|
||||
///
|
||||
/// `collection.ensureGeoIndex(latitude, longitude)`
|
||||
/// `collection.ensureIndex({ type: "geo", fields: [ "location" ], geoJson: true })`
|
||||
///
|
||||
/// Creates a geo-spatial index on all documents using *latitude* and
|
||||
/// *longitude* as paths the latitude and the longitude. The values of the
|
||||
/// attributes *latitude* and *longitude* has to be numeric.
|
||||
/// All documents, which do not have the attribute paths or
|
||||
/// have non-conforming values in the index attributes are excluded from the index.
|
||||
/// To create a geo-spatial index on all documents using *latitude* and
|
||||
/// *longitude* as separate attribute paths, two paths need to be specified
|
||||
/// in the *fields* array:
|
||||
///
|
||||
/// Geo indexes are always sparse, meaning that documents which do not contain
|
||||
/// the index attributes or have non-numeric values in the index attributes
|
||||
/// will not be indexed.
|
||||
/// `collection.ensureIndex({ type: "geo", fields: [ "latitude", "longitude" ] })`
|
||||
///
|
||||
/// In case that the index was successfully created, an object with the index
|
||||
/// details, including the index-identifier, is returned.
|
||||
|
@ -1221,7 +1211,7 @@ ArangoCollection.prototype.ensureHashIndex = function () {
|
|||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{geoIndexCreateForArrayAttribute}
|
||||
/// ~db._create("geo")
|
||||
/// db.geo.ensureGeoIndex("loc");
|
||||
/// db.geo.ensureIndex({ type: "geo", fields: [ "loc" ] });
|
||||
/// | for (i = -90; i <= 90; i += 10) {
|
||||
/// | for (j = -180; j <= 180; j += 10) {
|
||||
/// | db.geo.save({ name : "Name/" + i + "/" + j, loc: [ i, j ] });
|
||||
|
@ -1237,7 +1227,7 @@ ArangoCollection.prototype.ensureHashIndex = function () {
|
|||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{geoIndexCreateForArrayAttribute2}
|
||||
/// ~db._create("geo2")
|
||||
/// db.geo2.ensureGeoIndex("location.latitude", "location.longitude");
|
||||
/// db.geo2.ensureIndex({ type: "geo", fields: [ "location.latitude", "location.longitude" ] });
|
||||
/// | for (i = -90; i <= 90; i += 10) {
|
||||
/// | for (j = -180; j <= 180; j += 10) {
|
||||
/// | db.geo2.save({ name : "Name/" + i + "/" + j, location: { latitude : i, longitude : j } });
|
||||
|
@ -1281,11 +1271,7 @@ ArangoCollection.prototype.ensureGeoIndex = function (lat, lon) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief ensures that a geo constraint exists
|
||||
/// @startDocuBlock collectionEnsureGeoConstraint
|
||||
/// `collection.ensureGeoConstraint(location)`
|
||||
///
|
||||
/// `collection.ensureGeoConstraint(location, true)`
|
||||
///
|
||||
/// `collection.ensureGeoConstraint(latitude, longitude)`
|
||||
/// `collection.ensureIndex({ type: "geo", fields: [ "location" ] })`
|
||||
///
|
||||
/// Since ArangoDB 2.5, this method is an alias for *ensureGeoIndex* since
|
||||
/// geo indexes are always sparse, meaning that documents that do not contain
|
||||
|
@ -1357,7 +1343,7 @@ ArangoCollection.prototype.lookupSkiplist = function () {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief looks up a fulltext index
|
||||
/// @startDocuBlock lookUpFulltextIndex
|
||||
/// `lookupFulltextIndex(attribute, minLength)`
|
||||
/// `collection.lookupFulltextIndex(attribute, minLength)`
|
||||
///
|
||||
/// Checks whether a fulltext index on the given attribute *attribute* exists.
|
||||
/// @endDocuBlock
|
||||
|
|
|
@ -296,15 +296,15 @@ ArangoDatabase.prototype._truncate = function(name) {
|
|||
/// @startDocuBlock IndexVerify
|
||||
///
|
||||
/// So you've created an index, and since its maintainance isn't for free,
|
||||
/// you definitely want to know whether your Query can utilize it.
|
||||
/// you definitely want to know whether your query can utilize it.
|
||||
///
|
||||
/// You can use explain to verify whether **skiplist** or **hash indices** are used
|
||||
/// (if you ommit `colors: false` you will get nice colors in ArangoShell):
|
||||
/// You can use explain to verify whether **skiplists** or **hash indexes** are
|
||||
/// used (if you omit `colors: false` you will get nice colors in ArangoShell):
|
||||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{IndexVerify}
|
||||
/// ~db._create("example");
|
||||
/// var explain = require("org/arangodb/aql/explainer").explain;
|
||||
/// db.example.ensureSkiplist("a", "b");
|
||||
/// db.example.ensureIndex({ type: "skiplist", fields: [ "a", "b" ] });
|
||||
/// explain("FOR doc IN example FILTER doc.a < 23 RETURN doc", {colors:false});
|
||||
/// ~db._drop("example");
|
||||
/// @END_EXAMPLE_ARANGOSH_OUTPUT
|
||||
|
@ -322,7 +322,7 @@ ArangoDatabase.indexRegex = /^([a-zA-Z0-9\-_]+)\/([0-9]+)$/;
|
|||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{IndexHandle}
|
||||
/// ~db._create("example");
|
||||
/// db.example.ensureSkiplist("a", "b");
|
||||
/// db.example.ensureIndex({ type: "skiplist", fields: [ "a", "b" ] });
|
||||
/// var indexInfo = db.example.getIndexes().map(function(x) { return x.id; });
|
||||
/// indexInfo;
|
||||
/// db._index(indexInfo[0])
|
||||
|
@ -385,7 +385,7 @@ ArangoDatabase.prototype._index = function(id) {
|
|||
///
|
||||
/// @EXAMPLE_ARANGOSH_OUTPUT{dropIndex}
|
||||
/// ~db._create("example");
|
||||
/// db.example.ensureSkiplist("a", "b");
|
||||
/// db.example.ensureIndex({ type: "skiplist", fields: [ "a", "b" ] });
|
||||
/// var indexInfo = db.example.getIndexes();
|
||||
/// indexInfo;
|
||||
/// db._dropIndex(indexInfo[0])
|
||||
|
|
|
@ -404,7 +404,7 @@ Users.prototype.setup = function (options) {
|
|||
db._create(this._collectionName, createOptions);
|
||||
}
|
||||
|
||||
this.storage().ensureUniqueConstraint("identifier", { sparse: true });
|
||||
this.storage().ensureIndex({ type: "hash", fields: [ "identifier" ], sparse: true });
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -754,7 +754,7 @@ Sessions.prototype.setup = function (options) {
|
|||
db._create(this._collectionName, createOptions);
|
||||
}
|
||||
|
||||
this.storage().ensureHashIndex("identifier");
|
||||
this.storage().ensureIndex({ type: "hash", fields: ["identifier"]});
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -182,9 +182,9 @@ extend(Console.prototype, {
|
|||
|
||||
if (!db._foxxlog) {
|
||||
db._create('_foxxlog', {isSystem: true});
|
||||
db._foxxlog.ensureSkiplist('mount');
|
||||
db._foxxlog.ensureSkiplist('mount', 'created');
|
||||
db._foxxlog.ensureSkiplist('mount', 'created', 'levelNum');
|
||||
db._foxxlog.ensureIndex({type: 'skiplist', fields: ['mount']});
|
||||
db._foxxlog.ensureIndex({type: 'skiplist', fields: ['mount', 'created']});
|
||||
db._foxxlog.ensureIndex({type: 'skiplist', fields: ['mount', 'created', 'levelNum']});
|
||||
}
|
||||
|
||||
db._foxxlog.save(doc);
|
||||
|
@ -275,4 +275,4 @@ module.exports = extend(
|
|||
return new Console(mount, tracing);
|
||||
},
|
||||
{Console: Console}
|
||||
);
|
||||
);
|
||||
|
|
|
@ -76,7 +76,7 @@ function createStatisticsCollection (name) {
|
|||
}
|
||||
|
||||
if (collection !== null) {
|
||||
collection.ensureSkiplist("time");
|
||||
collection.ensureIndex({ type: "skiplist", fields: [ "time" ] });
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -557,7 +557,7 @@
|
|||
return false;
|
||||
}
|
||||
|
||||
users.ensureUniqueConstraint("user", { sparse: true });
|
||||
users.ensureIndex({ type: "hash", fields: ["user"], unique: true, sparse: true });
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -984,7 +984,7 @@
|
|||
return false;
|
||||
}
|
||||
|
||||
aal.ensureUniqueConstraint("name", "version", { sparse: true });
|
||||
aal.ensureIndex({ type: "hash", fields: ["name", "version"], unique: true, sparse: true });
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue