summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArne Juul <arnej@yahoo-inc.com>2018-12-13 12:39:33 +0000
committergjoranv <gv@oath.com>2019-01-21 15:09:29 +0100
commitc57b27a8def89067d3b488c0e3153d67878c483c (patch)
treef6fb4b672a3ae18c2ad1eebfdddf8f45f6a7b2e8
parenta500786ddb647d53cbefc1496ddddb9e34bf4b1b (diff)
add code to insert position attributes directly
-rw-r--r--searchcore/src/tests/proton/docsummary/docsummary.cpp10
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp63
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:'<position x=\"1002\" y=\"1003\" latlong=\"N0.001003;E0.001002\" />'"
+ ",sp2x:[{x:1002, y:1003, latlong:'N0.001003;E0.001002'}]"
",ap2:[1047806,1048322]"
- ",ap2x:'<position x=\"1006\" y=\"1007\" latlong=\"N0.001007;E0.001006\" />"
- "<position x=\"1008\" y=\"1009\" latlong=\"N0.001009;E0.001008\" />'"
+ ",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:'<position x=\"1012\" y=\"1013\" latlong=\"N0.001013;E0.001012\" />"
- "<position x=\"1014\" y=\"1015\" latlong=\"N0.001015;E0.001014\" />'}",
+ ",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 <vespa/searchlib/attribute/iattributemanager.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>
@@ -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<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());
+ }
+ 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()));
}