aboutsummaryrefslogtreecommitdiffstats
path: root/searchsummary
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2020-07-14 06:42:52 +0000
committerArne Juul <arnej@verizonmedia.com>2020-07-15 15:39:23 +0000
commit9534d9ef4d74017ff4ef0849924f751403979cbb (patch)
tree54bfac4a2cb6d39e64eb8ee920ac12307d6a0100 /searchsummary
parent909c3b8f302cbe615d38139d202e809c9f6079a4 (diff)
finish rewrite to use GeoLocation
Diffstat (limited to 'searchsummary')
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/docsumstate.cpp14
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp26
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.h2
3 files changed, 16 insertions, 26 deletions
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.cpp
index 708198b1c85..c42d4d9924d 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.cpp
+++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.cpp
@@ -3,7 +3,9 @@
#include "docsumstate.h"
#include <vespa/juniper/rpinterface.h>
#include <vespa/searchcommon/attribute/iattributecontext.h>
-#include <vespa/searchlib/common/location.h>
+#include <vespa/searchlib/common/geo_location.h>
+#include <vespa/searchlib/common/geo_location_parser.h>
+#include <vespa/searchlib/common/geo_location_spec.h>
#include <vespa/searchlib/common/matching_elements.h>
#include <vespa/searchlib/parsequery/parse.h>
#include <vespa/searchlib/parsequery/stackdumpiterator.h>
@@ -70,7 +72,10 @@ GetDocsumsState::parse_locations()
if (! _args.getLocation().empty()) {
search::common::GeoLocationParser locationParser;
if (locationParser.parseOldFormatWithField(_args.getLocation())) {
- _parsedLocations.emplace_back(locationParser.spec());
+ // TODO: do we need to add _zcurve prefix?
+ auto attr_name = locationParser.getFieldName();
+ search::common::GeoLocationSpec spec{attr_name, locationParser.getGeoLocation()};
+ _parsedLocations.push_back(spec);
} else {
LOG(warning, "could not parse location string '%s' from request",
_args.getLocation().c_str());
@@ -85,8 +90,9 @@ GetDocsumsState::parse_locations()
vespalib::string term = iterator.getTerm();
search::common::GeoLocationParser locationParser;
if (locationParser.parseOldFormat(term)) {
- locationParser.setFieldName(view);
- _parsedLocations.emplace_back(locationParser.spec());
+ // TODO: do we need to add _zcurve prefix?
+ search::common::GeoLocationSpec spec{view, locationParser.getGeoLocation()};
+ _parsedLocations.push_back(spec);
} else {
LOG(warning, "could not parse location string '%s' from stack dump",
term.c_str());
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp
index e5b5902ec23..50e1015aa37 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp
+++ b/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp
@@ -33,11 +33,11 @@ LocationAttrDFW::getAllLocations(GetDocsumsState *state)
state->parse_locations();
}
for (const auto & loc : state->_parsedLocations) {
- if (loc.isValid()) {
- if (getAttributeName() == loc.getFieldName()) {
- retval.matching.push_back(&loc);
+ if (loc.location.valid()) {
+ if (getAttributeName() == loc.field_name) {
+ retval.matching.push_back(&loc.location);
} else {
- retval.other.push_back(&loc);
+ retval.other.push_back(&loc.location);
}
}
}
@@ -67,23 +67,7 @@ AbsDistanceDFW::findMinDistance(uint32_t docid, GetDocsumsState *state,
for (uint32_t i = 0; i < numValues; i++) {
int64_t docxy(pos[i]);
vespalib::geo::ZCurve::decode(docxy, &docx, &docy);
- uint32_t dx;
- if (location->getX() > docx) {
- dx = location->getX() - docx;
- } else {
- dx = docx - location->getX();
- }
- if (location->getXAspect() != 0) {
- dx = ((uint64_t) dx * location->getXAspect()) >> 32;
- }
- uint32_t dy;
- if (location->getY() > docy) {
- dy = location->getY() - docy;
- } else {
- dy = docy - location->getY();
- }
- uint64_t dist2 = dx * (uint64_t) dx +
- dy * (uint64_t) dy;
+ uint64_t dist2 = location->sq_distance_to(GeoLoc::Point{docx, docy});
if (dist2 < absdist) {
absdist = dist2;
}
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.h b/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.h
index b2c9de81389..c135737e44c 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.h
+++ b/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.h
@@ -10,7 +10,7 @@ namespace search::docsummary {
class LocationAttrDFW : public AttrDFW
{
public:
- using GeoLoc = search::common::GeoLocationSpec;
+ using GeoLoc = search::common::GeoLocation;
LocationAttrDFW(const vespalib::string & attrName)
: AttrDFW(attrName)