mirror of https://gitee.com/bigwinds/arangodb
added new graph function _connectingEdges
This commit is contained in:
parent
be42c1559d
commit
a5bc4aaa4a
|
@ -1032,9 +1032,12 @@ AQLGenerator.prototype._getLastRestrictableStatementInfo = function() {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
AQLGenerator.prototype.restrict = function(restrictions) {
|
AQLGenerator.prototype.restrict = function(restrictions) {
|
||||||
|
var rest = stringToArray(restrictions);
|
||||||
|
if (rest.length == 0) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
this._addToPrint("restrict", restrictions);
|
this._addToPrint("restrict", restrictions);
|
||||||
this._clearCursor();
|
this._clearCursor();
|
||||||
var rest = stringToArray(restrictions);
|
|
||||||
var lastQueryInfo = this._getLastRestrictableStatementInfo();
|
var lastQueryInfo = this._getLastRestrictableStatementInfo();
|
||||||
var lastQuery = lastQueryInfo.statement;
|
var lastQuery = lastQueryInfo.statement;
|
||||||
var opts = lastQueryInfo.options;
|
var opts = lastQueryInfo.options;
|
||||||
|
@ -1185,6 +1188,7 @@ AQLGenerator.prototype.execute = function() {
|
||||||
|
|
||||||
AQLGenerator.prototype.toArray = function() {
|
AQLGenerator.prototype.toArray = function() {
|
||||||
this._createCursor();
|
this._createCursor();
|
||||||
|
|
||||||
return this.cursor.toArray();
|
return this.cursor.toArray();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4486,6 +4490,83 @@ Graph.prototype._removeVertexCollection = function(vertexCollectionName, dropCol
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @startDocuBlock JSF_general_graph_connectingEdges
|
||||||
|
/// @brief Get all connecting edges between 2 groups of vertices defined by the examples
|
||||||
|
///
|
||||||
|
/// `graph._connectingEdges(vertexExample, vertexExample2, options)`
|
||||||
|
///
|
||||||
|
/// The function accepts an id, an example, a list of examples or even an empty
|
||||||
|
/// example as parameter for vertexExample.
|
||||||
|
///
|
||||||
|
/// @PARAMS
|
||||||
|
///
|
||||||
|
/// @PARAM{vertexExample1, object, optional}
|
||||||
|
/// See [Definition of examples](#definition_of_examples)
|
||||||
|
/// @PARAM{vertexExample2, object, optional}
|
||||||
|
/// See [Definition of examples](#definition_of_examples)
|
||||||
|
/// @PARAM{options, object, optional}
|
||||||
|
/// An object defining further options. Can have the following values:
|
||||||
|
/// * *edgeExamples*: Filter the edges, see [Definition of examples](#definition_of_examples)
|
||||||
|
/// * *edgeCollectionRestriction* : One or a list of edge-collection names that should be
|
||||||
|
/// considered to be on the path.
|
||||||
|
/// * *vertex1CollectionRestriction* : One or a list of vertex-collection names that should be
|
||||||
|
/// considered on the intermediate vertex steps.
|
||||||
|
/// * *vertex2CollectionRestriction* : One or a list of vertex-collection names that should be
|
||||||
|
/// considered on the intermediate vertex steps.
|
||||||
|
///
|
||||||
|
/// @EXAMPLES
|
||||||
|
///
|
||||||
|
/// A route planner example, all neighbors of capitals.
|
||||||
|
///
|
||||||
|
/// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphModuleNeighbors1}
|
||||||
|
/// var examples = require("org/arangodb/graph-examples/example-graph.js");
|
||||||
|
/// var graph = examples.loadGraph("routeplanner");
|
||||||
|
/// graph._neighbors({isCapital : true});
|
||||||
|
/// @END_EXAMPLE_ARANGOSH_OUTPUT
|
||||||
|
///
|
||||||
|
/// A route planner example, all outbound neighbors of Hamburg.
|
||||||
|
///
|
||||||
|
/// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphModuleNeighbors2}
|
||||||
|
/// var examples = require("org/arangodb/graph-examples/example-graph.js");
|
||||||
|
/// var graph = examples.loadGraph("routeplanner");
|
||||||
|
/// graph._neighbors('germanCity/Hamburg', {direction : 'outbound', maxDepth : 2});
|
||||||
|
/// @END_EXAMPLE_ARANGOSH_OUTPUT
|
||||||
|
///
|
||||||
|
/// @endDocuBlock
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Graph.prototype._getConnectingEdges = function(vertexExample1, vertexExample2, options) {
|
||||||
|
var AQLStmt = new AQLGenerator(this);
|
||||||
|
if (!options) {
|
||||||
|
options = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
var opts = {
|
||||||
|
};
|
||||||
|
|
||||||
|
options.vertex1CollectionRestriction ? opts.startVertexCollectionRestriction = options.vertex1CollectionRestriction : null ;
|
||||||
|
options.vertex2CollectionRestriction ? opts.endVertexCollectionRestriction = options.vertex2CollectionRestriction : null ;
|
||||||
|
options.edgeCollectionRestriction ? opts.edgeCollectionRestriction = options.edgeCollectionRestriction : null ;
|
||||||
|
options.edgeExamples ? opts.edgeExamples = options.edgeExamples : null ;
|
||||||
|
vertexExample2 ? opts.neighborExamples = vertexExample2 : null ;
|
||||||
|
var query = "RETURN"
|
||||||
|
+ " GRAPH_EDGES(@graphName"
|
||||||
|
+ ',@vertexExample'
|
||||||
|
+ ',@options'
|
||||||
|
+ ')';
|
||||||
|
options = options || {};
|
||||||
|
var bindVars = {
|
||||||
|
"graphName": this.__name,
|
||||||
|
"vertexExample": vertexExample1,
|
||||||
|
"options": opts
|
||||||
|
};
|
||||||
|
var result = db._query(query, bindVars).toArray();
|
||||||
|
return result[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1894,6 +1894,41 @@ function EdgesAndVerticesSuite() {
|
||||||
graph._drop(unitTestGraphName, true);
|
graph._drop(unitTestGraphName, true);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
test_connectingEdges : function () {
|
||||||
|
fillCollections();
|
||||||
|
var res = g._getConnectingEdges({first_name: "Tam"}, {first_name: "Tem"}, {});
|
||||||
|
assertTrue(res.length == 3);
|
||||||
|
},
|
||||||
|
|
||||||
|
test_connectingEdgesWithEdgeCollectionRestriction : function () {
|
||||||
|
fillCollections();
|
||||||
|
var res = g._getConnectingEdges({first_name: "Tam"}, null, {});
|
||||||
|
assertTrue(res.length == 13);
|
||||||
|
var res = g._getConnectingEdges({first_name: "Tam"}, null, {edgeCollectionRestriction : "unitTestEdgeCollection2"});
|
||||||
|
assertTrue(res.length == 5);
|
||||||
|
},
|
||||||
|
|
||||||
|
test_connectingEdgesWithVertexCollectionRestriction : function () {
|
||||||
|
fillCollections();
|
||||||
|
var res = g._getConnectingEdges(null, null, {});
|
||||||
|
assertTrue(res.length == 13);
|
||||||
|
var res = g._getConnectingEdges(null, null, {vertex1CollectionRestriction : "unitTestVertexCollection1"});
|
||||||
|
assertTrue(res.length == 13);
|
||||||
|
var res = g._getConnectingEdges(null, null, {
|
||||||
|
vertex1CollectionRestriction : "unitTestVertexCollection1",
|
||||||
|
vertex2CollectionRestriction : "unitTestVertexCollection3"
|
||||||
|
});
|
||||||
|
assertTrue(res.length == 5);
|
||||||
|
},
|
||||||
|
|
||||||
|
test_connectingEdgesWithIds : function () {
|
||||||
|
var ids = fillCollections();
|
||||||
|
var res = g._getConnectingEdges(ids.vId11, ids.vId13, {});
|
||||||
|
assertTrue(res.length == 2);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
test_dropGraph1 : function () {
|
test_dropGraph1 : function () {
|
||||||
var myGraphName = unitTestGraphName + "2";
|
var myGraphName = unitTestGraphName + "2";
|
||||||
var myEdgeColName = "unitTestEdgeCollection4711";
|
var myEdgeColName = "unitTestEdgeCollection4711";
|
||||||
|
|
|
@ -5891,6 +5891,9 @@ function AQL_GRAPH_NEIGHBORS (graphName,
|
||||||
if (options.vertexCollectionRestriction) {
|
if (options.vertexCollectionRestriction) {
|
||||||
params.filterVertexCollections = options.vertexCollectionRestriction;
|
params.filterVertexCollections = options.vertexCollectionRestriction;
|
||||||
}
|
}
|
||||||
|
if (options.endVertexCollectionRestriction) {
|
||||||
|
params.filterVertexCollections = options.endVertexCollectionRestriction;
|
||||||
|
}
|
||||||
fromVertices.forEach(function (v) {
|
fromVertices.forEach(function (v) {
|
||||||
var e = TRAVERSAL_FUNC("GRAPH_NEIGHBORS",
|
var e = TRAVERSAL_FUNC("GRAPH_NEIGHBORS",
|
||||||
factory,
|
factory,
|
||||||
|
|
Loading…
Reference in New Issue