mirror of https://gitee.com/bigwinds/arangodb
traversal(_tree) vertex filtering
added params "filterVertices" and "vertexFilterType" to traversal(_tree). "filterVertices" accepts an array of examples similar to "followEdges", while "vertexFilterType" defines how to filter out vertices that do not match the examples. "vertexFilterType" can be set to "prune", "exclude", or (default) ["prune","exclude"].
This commit is contained in:
parent
587c2aef64
commit
27806d90a8
|
@ -3757,6 +3757,38 @@ function TRAVERSAL_FILTER (config, vertex, edge, path) {
|
|||
return MATCHES(edge, config.expandEdgeExamples);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief vertex filter callback function for traversal
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function TRAVERSAL_VERTEX_FILTER (config, vertex, path) {
|
||||
"use strict";
|
||||
|
||||
if (!MATCHES(vertex, config.filterVertexExamples)) {
|
||||
return config.vertexFilterType;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief check typeweights of params.followEdges/params.followVertices
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function TRAVERSAL_CHECK_EXAMPLES_TYPEWEIGHTS (examples) {
|
||||
"use strict";
|
||||
|
||||
if (TYPEWEIGHT(examples) !== TYPEWEIGHT_LIST) {
|
||||
THROW(INTERNAL.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, func);
|
||||
}
|
||||
if (examples.length === 0) {
|
||||
THROW(INTERNAL.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, func);
|
||||
}
|
||||
examples.forEach(function (example) {
|
||||
if (TYPEWEIGHT(example) !== TYPEWEIGHT_DOCUMENT) {
|
||||
THROW(INTERNAL.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, func);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief traverse a graph
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -3770,20 +3802,14 @@ function TRAVERSAL_FUNC (func, vertexCollection, edgeCollection, startVertex, di
|
|||
|
||||
vertexCollection = COLLECTION(vertexCollection);
|
||||
edgeCollection = COLLECTION(edgeCollection);
|
||||
|
||||
|
||||
// check followEdges property
|
||||
if (params.followEdges) {
|
||||
if (TYPEWEIGHT(params.followEdges) !== TYPEWEIGHT_LIST) {
|
||||
THROW(INTERNAL.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, func);
|
||||
}
|
||||
if (params.followEdges.length === 0) {
|
||||
THROW(INTERNAL.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, func);
|
||||
}
|
||||
params.followEdges.forEach(function (example) {
|
||||
if (TYPEWEIGHT(example) !== TYPEWEIGHT_DOCUMENT) {
|
||||
THROW(INTERNAL.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, func);
|
||||
}
|
||||
});
|
||||
TRAVERSAL_CHECK_EXAMPLES_TYPEWEIGHTS(params.followEdges);
|
||||
}
|
||||
// check followVertices property
|
||||
if (params.followVertices) {
|
||||
TRAVERSAL_CHECK_EXAMPLES_TYPEWEIGHTS(params.followVertices);
|
||||
}
|
||||
|
||||
if (typeof params.visitor !== "function") {
|
||||
|
@ -3812,6 +3838,12 @@ function TRAVERSAL_FUNC (func, vertexCollection, edgeCollection, startVertex, di
|
|||
config.expandEdgeExamples = params.followEdges;
|
||||
}
|
||||
|
||||
if (params.filterVertices) {
|
||||
config.filter = TRAVERSAL_VERTEX_FILTER;
|
||||
config.filterVertexExamples = params.filterVertices;
|
||||
config.vertexFilterType = params.vertexFilterType || ["prune","exclude"];
|
||||
}
|
||||
|
||||
if (params._sort) {
|
||||
config.sort = function (l, r) { return l._key < r._key ? -1 : 1; };
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue