aboutsummaryrefslogtreecommitdiffstats
path: root/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp')
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp85
1 files changed, 71 insertions, 14 deletions
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp
index 9c82c00c3ef..6b003553f49 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp
+++ b/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp
@@ -3,8 +3,11 @@
#include "positionsdfw.h"
#include "docsumstate.h"
#include <vespa/searchlib/attribute/iattributemanager.h>
+#include <vespa/searchcommon/attribute/attributecontent.h>
#include <vespa/searchlib/common/location.h>
#include <vespa/vespalib/stllike/asciistream.h>
+#include <vespa/vespalib/data/slime/cursor.h>
+#include <vespa/vespalib/data/slime/inserter.h>
#include <cmath>
#include <climits>
@@ -16,6 +19,7 @@ namespace search::docsummary {
using search::attribute::IAttributeContext;
using search::attribute::IAttributeVector;
using search::attribute::BasicType;
+using search::attribute::IntegerContent;
using search::common::Location;
AbsDistanceDFW::AbsDistanceDFW(const vespalib::string & attrName) :
@@ -31,13 +35,9 @@ AbsDistanceDFW::findMinDistance(uint32_t docid, GetDocsumsState *state)
uint64_t absdist = std::numeric_limits<int64_t>::max();
int32_t docx = 0;
int32_t docy = 0;
- std::vector<IAttributeVector::largeint_t> pos(16);
- uint32_t numValues = attribute.get(docid, &pos[0], pos.size());
- if (numValues > pos.size()) {
- pos.resize(numValues);
- numValues = attribute.get(docid, &pos[0], pos.size());
- assert(numValues <= pos.size());
- }
+ IntegerContent pos;
+ pos.fill(attribute, docid);
+ uint32_t numValues = pos.size();
for (uint32_t i = 0; i < numValues; i++) {
int64_t docxy(pos[i]);
vespalib::geo::ZCurve::decode(docxy, &docx, &docy);
@@ -112,19 +112,72 @@ PositionsDFW::PositionsDFW(const vespalib::string & attrName) :
}
namespace {
+
+void
+insertPos(int64_t docxy, vespalib::slime::Inserter &target)
+{
+
+ int32_t docx = 0;
+ int32_t docy = 0;
+ vespalib::geo::ZCurve::decode(docxy, &docx, &docy);
+ if (docx == 0 && docy == INT_MIN) {
+ LOG(spam, "skipping empty zcurve value");
+ return;
+ }
+ vespalib::slime::Cursor &obj = target.insertObject();
+ obj.setLong("y", docy);
+ obj.setLong("x", docx);
+
+ double degrees_ns = docy;
+ degrees_ns /= 1000000.0;
+ double degrees_ew = docx;
+ degrees_ew /= 1000000.0;
+
+ vespalib::asciistream latlong;
+ latlong << vespalib::FloatSpec::fixed;
+ if (degrees_ns < 0) {
+ latlong << "S" << (-degrees_ns);
+ } else {
+ latlong << "N" << degrees_ns;
+ }
+ latlong << ";";
+ if (degrees_ew < 0) {
+ latlong << "W" << (-degrees_ew);
+ } else {
+ latlong << "E" << degrees_ew;
+ }
+ obj.setString("latlong", vespalib::Memory(latlong.str()));
+}
+
+void
+insertFromAttr(const attribute::IAttributeVector &attribute, uint32_t docid, vespalib::slime::Inserter &target)
+{
+ IntegerContent pos;
+ pos.fill(attribute, docid);
+ uint32_t numValues = pos.size();
+ LOG(debug, "docid=%d, numValues=%d", docid, numValues);
+ if (numValues > 0) {
+ if (attribute.getCollectionType() == attribute::CollectionType::SINGLE) {
+ insertPos(pos[0], target);
+ } else {
+ vespalib::slime::Cursor &arr = target.insertArray();
+ for (uint32_t i = 0; i < numValues; i++) {
+ vespalib::slime::ArrayInserter ai(arr);
+ insertPos(pos[i], ai);
+ }
+ }
+ }
+}
+
vespalib::asciistream
formatField(const attribute::IAttributeVector &attribute, uint32_t docid, ResType type) {
vespalib::asciistream target;
int32_t docx = 0;
int32_t docy = 0;
- std::vector<IAttributeVector::largeint_t> pos(16);
- uint32_t numValues = attribute.get(docid, &pos[0], pos.size());
- if (numValues > pos.size()) {
- pos.resize(numValues);
- numValues = attribute.get(docid, &pos[0], pos.size());
- assert(numValues <= pos.size());
- }
+ IntegerContent pos;
+ pos.fill(attribute, docid);
+ uint32_t numValues = pos.size();
LOG(debug, "docid=%d, numValues=%d", docid, numValues);
bool isShort = !IDocsumFieldWriter::IsBinaryCompatible(type, RES_LONG_STRING);
@@ -167,6 +220,10 @@ formatField(const attribute::IAttributeVector &attribute, uint32_t docid, ResTyp
void
PositionsDFW::insertField(uint32_t docid, GetDocsumsState * dsState, ResType type, vespalib::slime::Inserter &target)
{
+ if (type == RES_XMLSTRING) {
+ insertFromAttr(vec(*dsState), docid, target);
+ return;
+ }
vespalib::asciistream val(formatField(vec(*dsState), docid, type));
target.insertString(vespalib::Memory(val.c_str(), val.size()));
}