mirror of https://gitee.com/bigwinds/arangodb
small fixes
This commit is contained in:
parent
d582e6e75a
commit
12a297281e
|
@ -21,12 +21,13 @@
|
||||||
/// @author Dr. Frank Celler
|
/// @author Dr. Frank Celler
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "GeoIndex.h"
|
||||||
|
|
||||||
#include "Aql/Ast.h"
|
#include "Aql/Ast.h"
|
||||||
#include "Aql/AstNode.h"
|
#include "Aql/AstNode.h"
|
||||||
#include "Aql/SortCondition.h"
|
#include "Aql/SortCondition.h"
|
||||||
#include "Basics/StringRef.h"
|
#include "Basics/StringRef.h"
|
||||||
#include "Basics/VelocyPackHelper.h"
|
#include "Basics/VelocyPackHelper.h"
|
||||||
#include "GeoIndex.h"
|
|
||||||
#include "Indexes/GeoIndex.h"
|
#include "Indexes/GeoIndex.h"
|
||||||
#include "Logger/Logger.h"
|
#include "Logger/Logger.h"
|
||||||
#include "VocBase/transaction.h"
|
#include "VocBase/transaction.h"
|
||||||
|
@ -44,51 +45,43 @@ GeoIndexIterator::GeoIndexIterator(LogicalCollection* collection,
|
||||||
_coor(),
|
_coor(),
|
||||||
_condition(cond),
|
_condition(cond),
|
||||||
_variable(var),
|
_variable(var),
|
||||||
_lat(0),
|
_lat(0.0),
|
||||||
_lon(0),
|
_lon(0.0),
|
||||||
_near(true),
|
_near(true),
|
||||||
_withinRange(0),
|
_withinRange(0.0),
|
||||||
_withinLessEq(false)
|
_withinLessEq(false) {
|
||||||
// lookup will hold the inforamtion if this is a cursor for
|
|
||||||
// near/within and the reference point
|
|
||||||
//_lookups(trx, node, reference, index->fields()),
|
|
||||||
{
|
|
||||||
evaluateCondition();
|
evaluateCondition();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeoIndexIterator::evaluateCondition() {
|
void GeoIndexIterator::evaluateCondition() {
|
||||||
if (_condition) {
|
if (_condition) {
|
||||||
auto numMembers = _condition->numMembers();
|
auto numMembers = _condition->numMembers();
|
||||||
|
|
||||||
if(numMembers >= 2){
|
if (numMembers >= 2) {
|
||||||
_lat = _condition->getMember(0)->getMember(1)->getDoubleValue();
|
_lat = _condition->getMember(0)->getMember(1)->getDoubleValue();
|
||||||
_lon = _condition->getMember(1)->getMember(1)->getDoubleValue();
|
_lon = _condition->getMember(1)->getMember(1)->getDoubleValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numMembers == 2){ //near
|
if (numMembers == 2) { //near
|
||||||
_near = true;
|
_near = true;
|
||||||
} else { //within
|
} else { //within
|
||||||
_near = false;
|
_near = false;
|
||||||
_withinRange = _condition->getMember(2)->getMember(1)->getDoubleValue();
|
_withinRange = _condition->getMember(2)->getMember(1)->getDoubleValue();
|
||||||
_withinLessEq = _condition->getMember(3)->getMember(1)->getDoubleValue();
|
_withinLessEq = _condition->getMember(3)->getMember(1)->getDoubleValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LOG(ERR) << "No Condition passed to GeoIndexIterator constructor";
|
LOG(ERR) << "No condition passed to GeoIndexIterator constructor";
|
||||||
}
|
}
|
||||||
|
|
||||||
//LOG_TOPIC(DEBUG, Logger::DEVEL) << "EXIT evaluate Condition";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexLookupResult GeoIndexIterator::next() {
|
IndexLookupResult GeoIndexIterator::next() {
|
||||||
//LOG_TOPIC(DEBUG, Logger::DEVEL) << "ENTER next";
|
if (!_cursor) {
|
||||||
if (!_cursor){
|
createCursor(_lat, _lon);
|
||||||
createCursor(_lat,_lon);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto coords = std::unique_ptr<GeoCoordinates>(::GeoIndex_ReadCursor(_cursor,1));
|
auto coords = std::unique_ptr<GeoCoordinates>(::GeoIndex_ReadCursor(_cursor, 1));
|
||||||
if(coords && coords->length){
|
if (coords && coords->length) {
|
||||||
if(_near || GeoIndex_distance(&_coor, &coords->coordinates[0]) <= _withinRange ){
|
if (_near || GeoIndex_distance(&_coor, &coords->coordinates[0]) <= _withinRange) {
|
||||||
auto revision = ::GeoIndex::toRevision(coords->coordinates[0].data);
|
auto revision = ::GeoIndex::toRevision(coords->coordinates[0].data);
|
||||||
return IndexLookupResult{revision};
|
return IndexLookupResult{revision};
|
||||||
}
|
}
|
||||||
|
@ -98,8 +91,7 @@ IndexLookupResult GeoIndexIterator::next() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeoIndexIterator::nextBabies(std::vector<IndexLookupResult>& result, size_t batchSize) {
|
void GeoIndexIterator::nextBabies(std::vector<IndexLookupResult>& result, size_t batchSize) {
|
||||||
//LOG_TOPIC(DEBUG, Logger::DEVEL) << "ENTER nextBabies " << batchSize;
|
if (!_cursor) {
|
||||||
if (!_cursor){
|
|
||||||
createCursor(_lat,_lon);
|
createCursor(_lat,_lon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,36 +100,30 @@ void GeoIndexIterator::nextBabies(std::vector<IndexLookupResult>& result, size_t
|
||||||
auto coords = std::unique_ptr<GeoCoordinates>(::GeoIndex_ReadCursor(_cursor,batchSize));
|
auto coords = std::unique_ptr<GeoCoordinates>(::GeoIndex_ReadCursor(_cursor,batchSize));
|
||||||
|
|
||||||
size_t length = coords ? coords->length : 0;
|
size_t length = coords ? coords->length : 0;
|
||||||
//LOG_TOPIC(DEBUG, Logger::DEVEL) << "length " << length;
|
|
||||||
if (!length) {
|
if (!length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(std::size_t index = 0; index < length; ++index){
|
for (std::size_t index = 0; index < length; ++index) {
|
||||||
//LOG_TOPIC(DEBUG, Logger::DEVEL) << "near " << _near << " max allowed range: " << _withinRange
|
if (_near || GeoIndex_distance(&_coor, &coords->coordinates[index]) <= _withinRange) {
|
||||||
// << " actual range: " << GeoIndex_distance(&_coor, &coords->coordinates[index]) ;
|
|
||||||
if (_near || GeoIndex_distance(&_coor, &coords->coordinates[index]) <= _withinRange ){
|
|
||||||
//LOG_TOPIC(DEBUG, Logger::DEVEL) << "add above to result" ;
|
|
||||||
result.emplace_back(IndexLookupResult(::GeoIndex::toRevision(coords->coordinates[index].data)));
|
result.emplace_back(IndexLookupResult(::GeoIndex::toRevision(coords->coordinates[index].data)));
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//LOG_TOPIC(DEBUG, Logger::DEVEL) << "EXIT nextBabies " << result.size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
::GeoCursor* GeoIndexIterator::replaceCursor(::GeoCursor* c){
|
void GeoIndexIterator::replaceCursor(::GeoCursor* c) {
|
||||||
if(_cursor){
|
if (_cursor) {
|
||||||
::GeoIndex_CursorFree(_cursor);
|
::GeoIndex_CursorFree(_cursor);
|
||||||
}
|
}
|
||||||
_cursor = c;
|
_cursor = c;
|
||||||
return _cursor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
::GeoCursor* GeoIndexIterator::createCursor(double lat, double lon){
|
void GeoIndexIterator::createCursor(double lat, double lon) {
|
||||||
_coor = GeoCoordinate{lat, lon, 0};
|
_coor = GeoCoordinate{lat, lon, 0};
|
||||||
return replaceCursor(::GeoIndex_NewCursor(_index->_geoIndex, &_coor));
|
replaceCursor(::GeoIndex_NewCursor(_index->_geoIndex, &_coor));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief creates an IndexIterator for the given Condition
|
/// @brief creates an IndexIterator for the given Condition
|
||||||
|
@ -152,7 +138,6 @@ IndexIterator* GeoIndex::iteratorForCondition(
|
||||||
return new GeoIndexIterator(_collection, trx, mmdr, this, node, reference);
|
return new GeoIndexIterator(_collection, trx, mmdr, this, node, reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GeoIndexIterator::reset() {
|
void GeoIndexIterator::reset() {
|
||||||
replaceCursor(nullptr);
|
replaceCursor(nullptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ class GeoIndexIterator final : public IndexIterator {
|
||||||
|
|
||||||
~GeoIndexIterator() {
|
~GeoIndexIterator() {
|
||||||
replaceCursor(nullptr);
|
replaceCursor(nullptr);
|
||||||
};
|
}
|
||||||
|
|
||||||
char const* typeName() const override { return "geo-index-iterator"; }
|
char const* typeName() const override { return "geo-index-iterator"; }
|
||||||
|
|
||||||
|
@ -63,8 +63,8 @@ class GeoIndexIterator final : public IndexIterator {
|
||||||
void reset() override;
|
void reset() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
::GeoCursor* replaceCursor(::GeoCursor* c);
|
void replaceCursor(::GeoCursor* c);
|
||||||
::GeoCursor* createCursor(double lat, double lon);
|
void createCursor(double lat, double lon);
|
||||||
void evaluateCondition(); //called in constructor
|
void evaluateCondition(); //called in constructor
|
||||||
|
|
||||||
GeoIndex const* _index;
|
GeoIndex const* _index;
|
||||||
|
@ -76,7 +76,7 @@ class GeoIndexIterator final : public IndexIterator {
|
||||||
double _lon;
|
double _lon;
|
||||||
bool _near;
|
bool _near;
|
||||||
double _withinRange;
|
double _withinRange;
|
||||||
double _withinLessEq;
|
bool _withinLessEq;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GeoIndex final : public Index {
|
class GeoIndex final : public Index {
|
||||||
|
|
Loading…
Reference in New Issue