From 323d34f6292a198640ce5478d09c40c61d7ababd Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Thu, 7 May 2015 16:33:05 -0700 Subject: [PATCH] The new CPP neighbors now take all three directions --- arangod/V8Server/V8Traverser.cpp | 34 +++++++++++++++++++++------ arangod/V8Server/V8Traverser.h | 12 +++++++++- arangod/V8Server/v8-vocbase.cpp | 22 ++++++++++++++++- js/server/modules/org/arangodb/aql.js | 4 ++-- 4 files changed, 61 insertions(+), 11 deletions(-) diff --git a/arangod/V8Server/V8Traverser.cpp b/arangod/V8Server/V8Traverser.cpp index 1b12c0e49f..ada3b93858 100644 --- a/arangod/V8Server/V8Traverser.cpp +++ b/arangod/V8Server/V8Traverser.cpp @@ -447,7 +447,8 @@ vector TRI_RunNeighborsSearch ( std::string const& edgeCollectionName, std::string const& startVertex, CollectionNameResolver const* resolver, - TRI_document_collection_t* ecol + TRI_document_collection_t* ecol, + NeighborsOptions& opts ) { // Transform string ids to VertexIds // Needs refactoring! @@ -466,12 +467,31 @@ vector TRI_RunNeighborsSearch ( // collection not found throw TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND; } - - auto edges = TRI_LookupEdgesDocumentCollection(ecol, - TRI_EDGE_OUT, coli->_cid, const_cast(str + split + 1)); - - for (size_t j = 0; j < edges.size(); ++j) { - result.push_back(extractToId(edges[j])); + if (opts.direction == "any") { + auto edges = TRI_LookupEdgesDocumentCollection(ecol, + TRI_EDGE_IN, coli->_cid, const_cast(str + split + 1)); + for (size_t j = 0; j < edges.size(); ++j) { + result.push_back(extractFromId(edges[j])); + } + edges = TRI_LookupEdgesDocumentCollection(ecol, + TRI_EDGE_OUT, coli->_cid, const_cast(str + split + 1)); + for (size_t j = 0; j < edges.size(); ++j) { + result.push_back(extractToId(edges[j])); + } + } else if (opts.direction == "inbound") { + auto edges = TRI_LookupEdgesDocumentCollection(ecol, + TRI_EDGE_IN, coli->_cid, const_cast(str + split + 1)); + for (size_t j = 0; j < edges.size(); ++j) { + result.push_back(extractFromId(edges[j])); + } + } else { + auto edges = TRI_LookupEdgesDocumentCollection(ecol, + TRI_EDGE_OUT, coli->_cid, const_cast(str + split + 1)); + for (size_t j = 0; j < edges.size(); ++j) { + result.push_back(extractToId(edges[j])); + } } + + return result; }; diff --git a/arangod/V8Server/V8Traverser.h b/arangod/V8Server/V8Traverser.h index 2797c93e6b..0655903266 100644 --- a/arangod/V8Server/V8Traverser.h +++ b/arangod/V8Server/V8Traverser.h @@ -54,6 +54,15 @@ namespace triagens { } }; + struct NeighborsOptions { + std::string direction; + + NeighborsOptions() : + direction("outbound") { + } + + }; + } } } @@ -116,7 +125,8 @@ std::vector TRI_RunNeighborsSearch ( std::string const& edgeCollectionName, std::string const& startVertex, triagens::arango::CollectionNameResolver const* resolver, - TRI_document_collection_t* ecol + TRI_document_collection_t* ecol, + triagens::basics::traverser::NeighborsOptions& opts ); #endif diff --git a/arangod/V8Server/v8-vocbase.cpp b/arangod/V8Server/v8-vocbase.cpp index 959be75a75..d03aaf1921 100644 --- a/arangod/V8Server/v8-vocbase.cpp +++ b/arangod/V8Server/v8-vocbase.cpp @@ -1857,6 +1857,25 @@ static void JS_QueryNeighbors (const v8::FunctionCallbackInfo& args) // TODO Option parsing + traverser::NeighborsOptions opts; + + if (args.Length() == 4) { + if (! args[3]->IsObject()) { + TRI_V8_THROW_TYPE_ERROR("expecting json for "); + } + v8::Handle options = args[3]->ToObject(); + v8::Local keyDirection = TRI_V8_ASCII_STRING("direction"); + + if (options->Has(keyDirection) ) { + opts.direction = TRI_ObjectToString(options->Get(keyDirection)); + if ( opts.direction != "outbound" + && opts.direction != "inbound" + && opts.direction != "any" + ) { + TRI_V8_THROW_TYPE_ERROR("expecting direction to be 'outbound', 'inbound' or 'any'"); + } + } + } vector readCollections; vector writeCollections; @@ -1900,7 +1919,8 @@ static void JS_QueryNeighbors (const v8::FunctionCallbackInfo& args) edgeCollectionName, startVertex, resolver, - barriers.find(edgeCid)->second.col->_collection->_collection + barriers.find(edgeCid)->second.col->_collection->_collection, + opts ); } catch (int e) { trx->finish(e); diff --git a/js/server/modules/org/arangodb/aql.js b/js/server/modules/org/arangodb/aql.js index 43bf4936ea..12861f6461 100644 --- a/js/server/modules/org/arangodb/aql.js +++ b/js/server/modules/org/arangodb/aql.js @@ -6468,8 +6468,8 @@ function AQL_NEIGHBORS (vertexCollection, 'use strict'; vertex = TO_ID(vertex, vertexCollection); - if (examples === undefined && direction === "outbound") { - return CPP_NEIGHBORS(vertexCollection, edgeCollection, vertex); + if (examples === undefined) { + return CPP_NEIGHBORS(vertexCollection, edgeCollection, vertex, {direction: direction}); } var edges = AQL_EDGES(edgeCollection, vertex, direction);