From c57b27a8def89067d3b488c0e3153d67878c483c Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Thu, 13 Dec 2018 12:39:33 +0000 Subject: add code to insert position attributes directly --- .../src/tests/proton/docsummary/docsummary.cpp | 10 ++-- .../searchsummary/docsummary/positionsdfw.cpp | 63 ++++++++++++++++++++++ 2 files changed, 68 insertions(+), 5 deletions(-) diff --git a/searchcore/src/tests/proton/docsummary/docsummary.cpp b/searchcore/src/tests/proton/docsummary/docsummary.cpp index c0c706383f6..4b70b4797af 100644 --- a/searchcore/src/tests/proton/docsummary/docsummary.cpp +++ b/searchcore/src/tests/proton/docsummary/docsummary.cpp @@ -1108,13 +1108,13 @@ Test::requireThatPositionsAreUsed() EXPECT_EQUAL(1u, rep->docsums[0].docid); EXPECT_EQUAL(gid1, rep->docsums[0].gid); EXPECT_TRUE(assertSlime("{sp2:'1047758'" - ",sp2x:''" + ",sp2x:[{x:1002, y:1003, latlong:'N0.001003;E0.001002'}]" ",ap2:[1047806,1048322]" - ",ap2x:'" - "'" + ",ap2x:[{x:1006, y:1007, latlong:'N0.001007;E0.001006'}," + "{x:1008, y:1009, latlong:'N0.001009;E0.001008'}]" ",wp2:[{item:1048370,weight:43},{item:1048382,weight:44}]" - ",wp2x:'" - "'}", + ",wp2x:[{ x:1012, y:1013, latlong:'N0.001013;E0.001012'}," + "{ x:1014, y:1015, latlong:'N0.001015;E0.001014'}]}", *rep, 0, false)); } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp index 9c82c00c3ef..607a4db9d13 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include #include @@ -112,6 +114,63 @@ 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) +{ + std::vector 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()); + } + LOG(debug, "docid=%d, numValues=%d", docid, numValues); + if (numValues > 0) { + 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; @@ -167,6 +226,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())); } -- cgit v1.2.3