aboutsummaryrefslogtreecommitdiffstats
path: root/searchsummary
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-06-23 05:41:38 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-06-23 05:44:57 +0000
commitb0ba562566027d6de287c53b20f5cda85eb54440 (patch)
tree6a34e33527ec486b704122e39c09fbe96467c6f6 /searchsummary
parent1242ec5b569d86c90045151fc2def817fce6e530 (diff)
rank and summary features are never moved as json anymore.
Diffstat (limited to 'searchsummary')
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp28
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/docsumstate.cpp16
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/docsumstate.h8
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/rankfeaturesdfw.cpp35
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/rankfeaturesdfw.h12
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.cpp49
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.h18
7 files changed, 31 insertions, 135 deletions
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp
index f55a13a9604..9e05acb5935 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp
+++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp
@@ -48,18 +48,13 @@ DynamicDocsumConfig::createFieldWriter(const string & fieldName, const string &
throw IllegalArgumentException("Missing argument");
}
} else if (overrideName == "summaryfeatures") {
- SummaryFeaturesDFW *fw = new SummaryFeaturesDFW();
- fieldWriter.reset(fw);
- fw->init(getEnvironment());
+ fieldWriter = std::make_unique<SummaryFeaturesDFW>(getEnvironment());
rc = true;
} else if (overrideName == "rankfeatures") {
- RankFeaturesDFW * fw = new RankFeaturesDFW();
- fw->init(getEnvironment());
- fieldWriter.reset(fw);
+ fieldWriter = std::make_unique<RankFeaturesDFW>(getEnvironment());
rc = true;
} else if (overrideName == "empty") {
- EmptyDFW *fw = new EmptyDFW();
- fieldWriter.reset(fw);
+ fieldWriter = std::make_unique<EmptyDFW>();
rc = true;
} else if (overrideName == "copy") {
if ( ! argument.empty() ) {
@@ -71,21 +66,18 @@ DynamicDocsumConfig::createFieldWriter(const string & fieldName, const string &
}
} else if (overrideName == "absdist") {
if (getEnvironment()) {
- IAttributeManager *am = getEnvironment()->getAttributeManager();
- fieldWriter = AbsDistanceDFW::create(argument.c_str(), am);
- rc = fieldWriter.get();
+ fieldWriter = AbsDistanceDFW::create(argument.c_str(), getEnvironment()->getAttributeManager());
+ rc = static_cast<bool>(fieldWriter);
}
} else if (overrideName == "positions") {
if (getEnvironment()) {
- IAttributeManager *am = getEnvironment()->getAttributeManager();
- fieldWriter = PositionsDFW::create(argument.c_str(), am, resultConfig.useV8geoPositions());
- rc = fieldWriter.get();
+ fieldWriter = PositionsDFW::create(argument.c_str(), getEnvironment()->getAttributeManager(), resultConfig.useV8geoPositions());
+ rc = static_cast<bool>(fieldWriter);
}
} else if (overrideName == "geopos") {
if (getEnvironment()) {
- IAttributeManager *am = getEnvironment()->getAttributeManager();
- fieldWriter = GeoPositionDFW::create(argument.c_str(), am, resultConfig.useV8geoPositions());
- rc = fieldWriter.get();
+ fieldWriter = GeoPositionDFW::create(argument.c_str(), getEnvironment()->getAttributeManager(), resultConfig.useV8geoPositions());
+ rc = static_cast<bool>(fieldWriter);
}
} else if (overrideName == "attribute") {
if (getEnvironment() && getEnvironment()->getAttributeManager()) {
@@ -135,7 +127,7 @@ DynamicDocsumConfig::configure(const vespa::config::search::SummarymapConfig &cf
const vespa::config::search::SummarymapConfig::Override & o = cfg.override[i];
bool rc(false);
IDocsumFieldWriter::UP fieldWriter = createFieldWriter(o.field, o.command, o.arguments, rc, matching_elems_fields);
- if (rc && fieldWriter.get() != NULL) {
+ if (rc && fieldWriter) {
rc = _writer->Override(o.field.c_str(), fieldWriter.release()); // OBJECT HAND-OVER
}
if (!rc) {
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.cpp
index 80e57666ad3..16575a2e9dc 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.cpp
+++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.cpp
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "docsumstate.h"
+#include "docsum_field_writer_state.h"
#include <vespa/juniper/rpinterface.h>
#include <vespa/document/datatype/positiondatatype.h>
#include <vespa/searchcommon/attribute/iattributecontext.h>
@@ -11,10 +12,6 @@
#include <vespa/searchlib/parsequery/parse.h>
#include <vespa/searchlib/parsequery/stackdumpiterator.h>
#include <vespa/vespalib/util/issue.h>
-#include "docsum_field_writer_state.h"
-
-#include <vespa/log/log.h>
-LOG_SETUP(".searchsummary.docsummary.docsumstate");
using search::common::GeoLocationParser;
using search::common::GeoLocationSpec;
@@ -37,8 +34,7 @@ GetDocsumsState::GetDocsumsState(GetDocsumsStateCallback &callback)
_summaryFeaturesCached(false),
_omit_summary_features(false),
_rankFeatures(nullptr),
- _matching_elements(),
- _jsonStringer()
+ _matching_elements()
{
_dynteaser._docid = static_cast<uint32_t>(-1);
_dynteaser._input = static_cast<uint32_t>(-1);
@@ -68,14 +64,6 @@ GetDocsumsState::get_matching_elements(const MatchingElementsFields &matching_el
return *_matching_elements;
}
-vespalib::JSONStringer &
-GetDocsumsState::jsonStringer() {
- if (!_jsonStringer) {
- _jsonStringer = std::make_unique<vespalib::JSONStringer>();
- }
- return *_jsonStringer;
-}
-
void
GetDocsumsState::parse_locations()
{
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.h b/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.h
index cb8a6851c33..438a8a6d847 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.h
+++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.h
@@ -2,11 +2,9 @@
#pragma once
-#include <vespa/searchlib/util/rawbuf.h>
-#include <vespa/searchsummary/docsummary/getdocsumargs.h>
+#include "getdocsumargs.h"
#include <vespa/searchlib/common/featureset.h>
#include <vespa/searchlib/common/geo_location_spec.h>
-#include <vespa/vespalib/util/jsonwriter.h>
#include <vespa/vespalib/util/stash.h>
namespace juniper {
@@ -97,11 +95,7 @@ public:
~GetDocsumsState();
const MatchingElements &get_matching_elements(const MatchingElementsFields &matching_elems_fields);
- vespalib::JSONStringer & jsonStringer();
vespalib::Stash& get_stash() noexcept { return _stash; }
-private:
- // Only used by rank/summary features, so make it lazy
- std::unique_ptr<vespalib::JSONStringer> _jsonStringer;
};
}
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/rankfeaturesdfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/rankfeaturesdfw.cpp
index e7379296f78..8b75f9de8e1 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/rankfeaturesdfw.cpp
+++ b/searchsummary/src/vespa/searchsummary/docsummary/rankfeaturesdfw.cpp
@@ -2,28 +2,21 @@
#include "rankfeaturesdfw.h"
#include "docsumstate.h"
-#include <vespa/searchlib/common/packets.h>
#include <vespa/vespalib/data/slime/cursor.h>
namespace search::docsummary {
-RankFeaturesDFW::RankFeaturesDFW() :
- _env(nullptr)
+RankFeaturesDFW::RankFeaturesDFW(IDocsumEnvironment * env) :
+ _env(env)
{ }
RankFeaturesDFW::~RankFeaturesDFW() = default;
void
-RankFeaturesDFW::init(IDocsumEnvironment * env)
-{
- _env = env;
-}
-
-void
RankFeaturesDFW::insertField(uint32_t docid, GetDocsumsState *state,
ResType type, vespalib::slime::Inserter &target)
{
- if (state->_rankFeatures.get() == nullptr) {
+ if ( !state->_rankFeatures ) {
state->_callback.FillRankFeatures(state, _env);
if (state->_rankFeatures.get() == nullptr) { // still no rank features to write
return;
@@ -31,7 +24,8 @@ RankFeaturesDFW::insertField(uint32_t docid, GetDocsumsState *state,
}
const FeatureSet::StringVector & names = state->_rankFeatures->getNames();
const FeatureSet::Value * values = state->_rankFeatures->getFeaturesByDocId(docid);
- if (type == RES_FEATUREDATA && values != nullptr) {
+ assert(type == RES_FEATUREDATA);
+ if (values != nullptr) {
vespalib::slime::Cursor& obj = target.insertObject();
for (uint32_t i = 0; i < names.size(); ++i) {
vespalib::Memory name(names[i].c_str(), names[i].size());
@@ -41,25 +35,6 @@ RankFeaturesDFW::insertField(uint32_t docid, GetDocsumsState *state,
obj.setDouble(name, values[i].as_double());
}
}
- return;
- }
- vespalib::JSONStringer & json(state->jsonStringer());
- if (values != nullptr) {
- json.clear();
- json.beginObject();
- for (uint32_t i = 0; i < names.size(); ++i) {
- featureDump(json, names[i], values[i].as_double());
- }
- json.endObject();
- vespalib::Memory value(json.toString().data(),
- json.toString().size());
- if (type == RES_STRING || type == RES_LONG_STRING) {
- target.insertString(value);
- }
- if (type == RES_DATA || type == RES_LONG_DATA) {
- target.insertData(value);
- }
- json.clear();
}
}
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/rankfeaturesdfw.h b/searchsummary/src/vespa/searchsummary/docsummary/rankfeaturesdfw.h
index 92d458c7cbb..eab9fab60b2 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/rankfeaturesdfw.h
+++ b/searchsummary/src/vespa/searchsummary/docsummary/rankfeaturesdfw.h
@@ -6,18 +6,16 @@
namespace search::docsummary {
-class RankFeaturesDFW : public FeaturesDFW
+class RankFeaturesDFW : public ISimpleDFW
{
private:
- RankFeaturesDFW(const RankFeaturesDFW &);
- RankFeaturesDFW & operator=(const RankFeaturesDFW &);
-
IDocsumEnvironment * _env;
public:
- RankFeaturesDFW();
- ~RankFeaturesDFW();
- void init(IDocsumEnvironment * env);
+ RankFeaturesDFW(IDocsumEnvironment * env);
+ RankFeaturesDFW(const RankFeaturesDFW &) = delete;
+ RankFeaturesDFW & operator=(const RankFeaturesDFW &) = delete;
+ ~RankFeaturesDFW() override;
bool IsGenerated() const override { return true; }
void insertField(uint32_t docid, GetDocsumsState *state, ResType type, vespalib::slime::Inserter &target) override;
};
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.cpp
index 37ecbb6737a..960cdd19877 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.cpp
+++ b/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.cpp
@@ -2,7 +2,6 @@
#include "summaryfeaturesdfw.h"
#include "docsumstate.h"
-#include <vespa/searchlib/common/packets.h>
#include <vespa/vespalib/data/slime/cursor.h>
#include <vespa/log/log.h>
@@ -11,20 +10,13 @@ LOG_SETUP(".searchlib.docsummary.summaryfeaturesdfw");
namespace search::docsummary {
-SummaryFeaturesDFW::SummaryFeaturesDFW() :
- _env(nullptr)
+SummaryFeaturesDFW::SummaryFeaturesDFW(IDocsumEnvironment * env) :
+ _env(env)
{
}
SummaryFeaturesDFW::~SummaryFeaturesDFW() = default;
-void
-SummaryFeaturesDFW::init(IDocsumEnvironment * env)
-{
- _env = env;
-}
-
-static vespalib::string _G_cached("vespa.summaryFeatures.cached");
static vespalib::Memory _M_cached("vespa.summaryFeatures.cached");
void
@@ -41,7 +33,8 @@ SummaryFeaturesDFW::insertField(uint32_t docid, GetDocsumsState *state, ResType
}
const FeatureSet::StringVector &names = state->_summaryFeatures->getNames();
const FeatureSet::Value *values = state->_summaryFeatures->getFeaturesByDocId(docid);
- if (type == RES_FEATUREDATA && values != nullptr) {
+ assert(type == RES_FEATUREDATA);
+ if (values != nullptr) {
vespalib::slime::Cursor& obj = target.insertObject();
for (uint32_t i = 0; i < names.size(); ++i) {
vespalib::Memory name(names[i].c_str(), names[i].size());
@@ -56,40 +49,6 @@ SummaryFeaturesDFW::insertField(uint32_t docid, GetDocsumsState *state, ResType
} else {
obj.setDouble(_M_cached, 0.0);
}
- return;
- }
- vespalib::JSONStringer & json(state->jsonStringer());
- if (values != nullptr) {
- json.clear();
- json.beginObject();
- for (uint32_t i = 0; i < names.size(); ++i) {
- featureDump(json, names[i], values[i].as_double());
- }
- json.appendKey(_G_cached);
- if (state->_summaryFeaturesCached) {
- json.appendDouble(1.0);
- } else {
- json.appendDouble(0.0);
- }
- json.endObject();
- vespalib::Memory value(json.toString().data(), json.toString().size());
- if (type == RES_STRING || type == RES_LONG_STRING) {
- target.insertString(value);
- }
- if (type == RES_DATA || type == RES_LONG_DATA) {
- target.insertData(value);
- }
- json.clear();
- }
-}
-
-void FeaturesDFW::featureDump(vespalib::JSONStringer & json, vespalib::stringref name, double feature)
-{
- json.appendKey(name);
- if (std::isnan(feature) || std::isinf(feature)) {
- json.appendNull();
- } else {
- json.appendDouble(feature);
}
}
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.h b/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.h
index 1885ef57399..6c4084b0221 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.h
+++ b/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.h
@@ -4,30 +4,20 @@
#include "docsumfieldwriter.h"
-namespace vespalib { class JSONStringer; }
-
namespace search::docsummary {
class IDocsumEnvironment;
-class FeaturesDFW : public ISimpleDFW
-{
-protected:
- void featureDump(vespalib::JSONStringer & json, vespalib::stringref name, double feature);
-};
-
-class SummaryFeaturesDFW : public FeaturesDFW
+class SummaryFeaturesDFW : public ISimpleDFW
{
private:
- SummaryFeaturesDFW(const SummaryFeaturesDFW &);
- SummaryFeaturesDFW & operator=(const SummaryFeaturesDFW &);
-
IDocsumEnvironment * _env;
public:
- SummaryFeaturesDFW();
+ SummaryFeaturesDFW(IDocsumEnvironment * env);
+ SummaryFeaturesDFW(const SummaryFeaturesDFW &) = delete;
+ SummaryFeaturesDFW & operator=(const SummaryFeaturesDFW &) = delete;
~SummaryFeaturesDFW() override;
- void init(IDocsumEnvironment * env);
bool IsGenerated() const override { return true; }
void insertField(uint32_t docid, GetDocsumsState *state,
ResType type, vespalib::slime::Inserter &target) override;