1
0
Fork 0

make use of geo index cursor api

This commit is contained in:
Jan Christoph Uhde 2016-11-29 14:13:35 +01:00
parent 5b3be69e10
commit 86c21eb733
2 changed files with 53 additions and 22 deletions

View File

@ -26,6 +26,7 @@
#include "Basics/StringRef.h" #include "Basics/StringRef.h"
#include "Basics/VelocyPackHelper.h" #include "Basics/VelocyPackHelper.h"
#include "VocBase/transaction.h" #include "VocBase/transaction.h"
#include "Indexes/GeoIndex.h"
using namespace arangodb; using namespace arangodb;
GeoIndexIterator::GeoIndexIterator(LogicalCollection* collection, GeoIndexIterator::GeoIndexIterator(LogicalCollection* collection,
@ -39,28 +40,54 @@ GeoIndexIterator::GeoIndexIterator(LogicalCollection* collection,
// lookup will hold the inforamtion if this is a cursor for // lookup will hold the inforamtion if this is a cursor for
// near/within and the reference point // near/within and the reference point
//_lookups(trx, node, reference, index->fields()), //_lookups(trx, node, reference, index->fields()),
_lookupResult(nullptr), _cursor(nullptr)
_posInBuffer(0) { {}
//_index->lookup(_trx, _lookups.lookup(), _buffer);
}
IndexLookupResult GeoIndexIterator::next() { IndexLookupResult GeoIndexIterator::next() {
if (!_lookupResult){ if (!_cursor){
_lookupResult = _index->nearQuery(_trx,0,0,10); createCursor(0,0);
} }
//implement
if (_posInBuffer < _lookupResult->length){ auto coords = std::unique_ptr<GeoCoordinates>(::GeoIndex_ReadCursor(_cursor,1));
//is data the revision id? if(coords && coords->length){
return IndexLookupResult(GeoIndex::toRevision(_lookupResult->coordinates[_posInBuffer++].data)); auto revision = ::GeoIndex::toRevision(coords->coordinates[0].data);
return IndexLookupResult{revision};
} }
// if there are no more results we return the default constructed IndexLookupResult // if there are no more results we return the default constructed IndexLookupResult
return IndexLookupResult{}; return IndexLookupResult{};
} }
// optional void GeoIndexIterator::nextBabies(std::vector<IndexLookupResult>& result, size_t batchSize) {
// void GeoIndexIterator::nextBabies(std::vector<IndexLookupResult>& result, size_t atMost) { if (!_cursor){
// //implement provide fast implementation createCursor(0,0);
// } }
result.clear();
if (batchSize > 0) {
auto coords = std::unique_ptr<GeoCoordinates>(::GeoIndex_ReadCursor(_cursor,batchSize));
size_t length = coords ? coords->length : 0;
if (!length){
return;
}
for(std::size_t index = 0; index < length; ++index){
result.emplace_back(IndexLookupResult(::GeoIndex::toRevision(coords->coordinates[index].data)));
}
}
}
::GeoCursor* GeoIndexIterator::replaceCursor(::GeoCursor* c){
if(_cursor){
::GeoIndex_CursorFree(_cursor);
}
_cursor = c;
return _cursor;
}
::GeoCursor* GeoIndexIterator::createCursor(double lat, double lon){
::GeoCoordinate coor{lat, lon, 0};
return replaceCursor(::GeoIndex_NewCursor(_index->_geoIndex, &coor));
}
/// @brief creates an IndexIterator for the given Condition /// @brief creates an IndexIterator for the given Condition
IndexIterator* GeoIndex::iteratorForCondition( IndexIterator* GeoIndex::iteratorForCondition(
@ -76,8 +103,7 @@ IndexIterator* GeoIndex::iteratorForCondition(
void GeoIndexIterator::reset() { void GeoIndexIterator::reset() {
_lookupResult = nullptr; replaceCursor(nullptr);
_posInBuffer = 0;
} }
GeoIndex::GeoIndex(TRI_idx_iid_t iid, arangodb::LogicalCollection* collection, GeoIndex::GeoIndex(TRI_idx_iid_t iid, arangodb::LogicalCollection* collection,

View File

@ -42,7 +42,7 @@ class GeoIndex;
class GeoIndexIterator final : public IndexIterator { class GeoIndexIterator final : public IndexIterator {
public: public:
/// @brief Construct an GeoIndexIterator based on Ast Conditions /// @brief Construct an GeoIndexIterator based on Ast Conditions
GeoIndexIterator(LogicalCollection* collection, arangodb::Transaction* trx, GeoIndexIterator(LogicalCollection* collection, arangodb::Transaction* trx,
ManagedDocumentResult* mmdr, ManagedDocumentResult* mmdr,
@ -50,24 +50,29 @@ class GeoIndexIterator final : public IndexIterator {
arangodb::aql::AstNode const*, arangodb::aql::AstNode const*,
arangodb::aql::Variable const*); arangodb::aql::Variable const*);
~GeoIndexIterator() = default; ~GeoIndexIterator() {
replaceCursor(nullptr);
};
char const* typeName() const override { return "geo-index-iterator"; } char const* typeName() const override { return "geo-index-iterator"; }
IndexLookupResult next() override; IndexLookupResult next() override;
//void nextBabies(std::vector<IndexLookupResult>&, size_t) override; void nextBabies(std::vector<IndexLookupResult>&, size_t) override;
void reset() override; void reset() override;
private: private:
::GeoCursor* replaceCursor(::GeoCursor* c);
::GeoCursor* createCursor(double lat, double lon);
GeoIndex const* _index; GeoIndex const* _index;
::GeoCursor* _cursor;
//LookupBuilder _lookups; //LookupBuilder _lookups;
GeoCoordinates* _lookupResult;
size_t _posInBuffer;
}; };
class GeoIndex final : public Index { class GeoIndex final : public Index {
friend class GeoIndexIterator;
public: public:
GeoIndex() = delete; GeoIndex() = delete;