mirror of https://gitee.com/bigwinds/arangodb
The new CPP neighbors now take all three directions
This commit is contained in:
parent
b70cce0353
commit
323d34f629
|
@ -447,7 +447,8 @@ vector<VertexId> 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<VertexId> TRI_RunNeighborsSearch (
|
|||
// collection not found
|
||||
throw TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
|
||||
}
|
||||
|
||||
auto edges = TRI_LookupEdgesDocumentCollection(ecol,
|
||||
TRI_EDGE_OUT, coli->_cid, const_cast<char*>(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<char*>(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<char*>(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<char*>(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<char*>(str + split + 1));
|
||||
for (size_t j = 0; j < edges.size(); ++j) {
|
||||
result.push_back(extractToId(edges[j]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
};
|
||||
|
|
|
@ -54,6 +54,15 @@ namespace triagens {
|
|||
}
|
||||
|
||||
};
|
||||
struct NeighborsOptions {
|
||||
std::string direction;
|
||||
|
||||
NeighborsOptions() :
|
||||
direction("outbound") {
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +125,8 @@ std::vector<VertexId> 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
|
||||
|
|
|
@ -1857,6 +1857,25 @@ static void JS_QueryNeighbors (const v8::FunctionCallbackInfo<v8::Value>& args)
|
|||
|
||||
|
||||
// TODO Option parsing
|
||||
traverser::NeighborsOptions opts;
|
||||
|
||||
if (args.Length() == 4) {
|
||||
if (! args[3]->IsObject()) {
|
||||
TRI_V8_THROW_TYPE_ERROR("expecting json for <options>");
|
||||
}
|
||||
v8::Handle<v8::Object> options = args[3]->ToObject();
|
||||
v8::Local<v8::String> 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<string> readCollections;
|
||||
vector<string> writeCollections;
|
||||
|
@ -1900,7 +1919,8 @@ static void JS_QueryNeighbors (const v8::FunctionCallbackInfo<v8::Value>& 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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue