1
0
Fork 0

The new CPP neighbors now take all three directions

This commit is contained in:
Michael Hackstein 2015-05-07 16:33:05 -07:00
parent b70cce0353
commit 323d34f629
4 changed files with 61 additions and 11 deletions

View File

@ -447,7 +447,8 @@ vector<VertexId> TRI_RunNeighborsSearch (
std::string const& edgeCollectionName, std::string const& edgeCollectionName,
std::string const& startVertex, std::string const& startVertex,
CollectionNameResolver const* resolver, CollectionNameResolver const* resolver,
TRI_document_collection_t* ecol TRI_document_collection_t* ecol,
NeighborsOptions& opts
) { ) {
// Transform string ids to VertexIds // Transform string ids to VertexIds
// Needs refactoring! // Needs refactoring!
@ -466,12 +467,31 @@ vector<VertexId> TRI_RunNeighborsSearch (
// collection not found // collection not found
throw TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND; throw TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
} }
if (opts.direction == "any") {
auto edges = TRI_LookupEdgesDocumentCollection(ecol, auto edges = TRI_LookupEdgesDocumentCollection(ecol,
TRI_EDGE_OUT, coli->_cid, const_cast<char*>(str + split + 1)); TRI_EDGE_IN, coli->_cid, const_cast<char*>(str + split + 1));
for (size_t j = 0; j < edges.size(); ++j) {
for (size_t j = 0; j < edges.size(); ++j) { result.push_back(extractFromId(edges[j]));
result.push_back(extractToId(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; return result;
}; };

View File

@ -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& edgeCollectionName,
std::string const& startVertex, std::string const& startVertex,
triagens::arango::CollectionNameResolver const* resolver, triagens::arango::CollectionNameResolver const* resolver,
TRI_document_collection_t* ecol TRI_document_collection_t* ecol,
triagens::basics::traverser::NeighborsOptions& opts
); );
#endif #endif

View File

@ -1857,6 +1857,25 @@ static void JS_QueryNeighbors (const v8::FunctionCallbackInfo<v8::Value>& args)
// TODO Option parsing // 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> readCollections;
vector<string> writeCollections; vector<string> writeCollections;
@ -1900,7 +1919,8 @@ static void JS_QueryNeighbors (const v8::FunctionCallbackInfo<v8::Value>& args)
edgeCollectionName, edgeCollectionName,
startVertex, startVertex,
resolver, resolver,
barriers.find(edgeCid)->second.col->_collection->_collection barriers.find(edgeCid)->second.col->_collection->_collection,
opts
); );
} catch (int e) { } catch (int e) {
trx->finish(e); trx->finish(e);

View File

@ -6468,8 +6468,8 @@ function AQL_NEIGHBORS (vertexCollection,
'use strict'; 'use strict';
vertex = TO_ID(vertex, vertexCollection); vertex = TO_ID(vertex, vertexCollection);
if (examples === undefined && direction === "outbound") { if (examples === undefined) {
return CPP_NEIGHBORS(vertexCollection, edgeCollection, vertex); return CPP_NEIGHBORS(vertexCollection, edgeCollection, vertex, {direction: direction});
} }
var edges = AQL_EDGES(edgeCollection, vertex, direction); var edges = AQL_EDGES(edgeCollection, vertex, direction);