diff options
author | Tor Egge <Tor.Egge@online.no> | 2022-08-25 13:15:37 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2022-08-25 13:15:37 +0200 |
commit | 83a0fed65aae5fa177d123ae511f35c534dec119 (patch) | |
tree | ca2857c8e31be4ce276b1e72e2198680267851b0 /streamingvisitors | |
parent | bf81a11f33d4c687e6446b67b1e26a67c1bd59b7 (diff) |
Remove DocsumStoreValue, DocsumBlobEntryFilter, GeneralResult and ResultPacker.
Diffstat (limited to 'streamingvisitors')
-rw-r--r-- | streamingvisitors/src/vespa/vsm/vsm/docsumfilter.cpp | 310 | ||||
-rw-r--r-- | streamingvisitors/src/vespa/vsm/vsm/docsumfilter.h | 10 | ||||
-rw-r--r-- | streamingvisitors/src/vespa/vsm/vsm/vsm-adapter.cpp | 18 |
3 files changed, 5 insertions, 333 deletions
diff --git a/streamingvisitors/src/vespa/vsm/vsm/docsumfilter.cpp b/streamingvisitors/src/vespa/vsm/vsm/docsumfilter.cpp index bc05ec72638..f6090232b02 100644 --- a/streamingvisitors/src/vespa/vsm/vsm/docsumfilter.cpp +++ b/streamingvisitors/src/vespa/vsm/vsm/docsumfilter.cpp @@ -14,110 +14,6 @@ LOG_SETUP(".vsm.docsumfilter"); using namespace search::docsummary; -namespace { - -class Handler : public document::fieldvalue::IteratorHandler { -public: -}; - -struct IntResultHandler : public Handler { - int32_t value; - IntResultHandler() : value(0) {} - void onPrimitive(uint32_t, const Content & c) override { - value = c.getValue().getAsInt(); - } -}; - -struct LongResultHandler : public Handler { - int64_t value; - LongResultHandler() : value(0) {} - void onPrimitive(uint32_t, const Content & c) override { - value = c.getValue().getAsLong(); - } -}; - -struct FloatResultHandler : public Handler { - float value; - FloatResultHandler() : value(0) {} - void onPrimitive(uint32_t, const Content & c) override { - value = c.getValue().getAsFloat(); - } -}; - -struct DoubleResultHandler : public Handler { - double value; - DoubleResultHandler() : value(0) {} - void onPrimitive(uint32_t, const Content & c) override { - value = c.getValue().getAsDouble(); - } -}; - -class StringResultHandler : public Handler { -private: - ResType _type; - ResultPacker & _packer; - void addToPacker(const char * buf, size_t len) { - switch (_type) { - case RES_STRING: - _packer.AddString(buf, len); - break; - case RES_LONG_STRING: - _packer.AddLongString(buf, len); - break; - default: - break; - } - } - -public: - StringResultHandler(ResType t, ResultPacker & p) : _type(t), _packer(p) {} - void onPrimitive(uint32_t, const Content & c) override { - const document::FieldValue & fv = c.getValue(); - if (fv.isLiteral()) { - const document::LiteralFieldValueB & lfv = static_cast<const document::LiteralFieldValueB &>(fv); - vespalib::stringref s = lfv.getValueRef(); - addToPacker(s.data(), s.size()); - } else { - vespalib::string s = fv.toString(); - addToPacker(s.c_str(), s.size()); - } - } -}; - -class RawResultHandler : public Handler { -private: - ResType _type; - ResultPacker & _packer; - -public: - RawResultHandler(ResType t, ResultPacker & p) : _type(t), _packer(p) {} - void onPrimitive(uint32_t, const Content & c) override { - const document::FieldValue & fv = c.getValue(); - try { - std::pair<const char *, size_t> buf = fv.getAsRaw(); - if (buf.first != nullptr) { - switch (_type) { - case RES_DATA: - _packer.AddData(buf.first, buf.second); - break; - case RES_LONG_DATA: - _packer.AddLongData(buf.first, buf.second); - break; - default: - break; - } - } - } catch (document::InvalidDataTypeConversionException & e) { - LOG(warning, "RawResultHandler: Could not get field value '%s' as raw. Skipping writing this field", fv.toString().c_str()); - _packer.AddEmpty(); - } - } -}; - - -} - - namespace vsm { namespace { @@ -306,7 +202,6 @@ DocsumFilter::DocsumFilter(const DocsumToolsPtr &tools, const IDocSumCache & doc _tools(tools), _fields(), _highestFieldNo(0), - _packer(tools ? tools->getResultConfig() : nullptr), _flattenWriter(), _snippetModifiers(nullptr), _cachedValue(), @@ -341,110 +236,6 @@ DocsumFilter::getNumDocs() const return std::numeric_limits<uint32_t>::max(); } -void -DocsumFilter::writeField(const document::FieldValue & fv, const FieldPath & path, ResType type, ResultPacker & packer) -{ - switch (type) { - case RES_INT: { - IntResultHandler rh; - fv.iterateNested(path, rh); - uint32_t val = rh.value; - packer.AddInteger(val); - break; } - case RES_SHORT: { - IntResultHandler rh; - fv.iterateNested(path, rh); - uint16_t val = rh.value; - packer.AddShort(val); - break; } - case RES_BYTE: { - IntResultHandler rh; - fv.iterateNested(path, rh); - uint8_t val = rh.value; - packer.AddByte(val); - break; } - case RES_BOOL: { - IntResultHandler rh; - fv.iterateNested(path, rh); - uint8_t val = rh.value; - packer.AddByte(val); - break; } - case RES_FLOAT: { - FloatResultHandler rh; - fv.iterateNested(path, rh); - float val = rh.value; - packer.AddFloat(val); - break; } - case RES_DOUBLE: { - DoubleResultHandler rh; - fv.iterateNested(path, rh); - double val = rh.value; - packer.AddDouble(val); - break; } - case RES_INT64: { - LongResultHandler rh; - fv.iterateNested(path, rh); - uint64_t val = rh.value; - packer.AddInt64(val); - break; } - case RES_STRING: - case RES_LONG_STRING: - { - StringResultHandler rh(type, packer); - // the string result handler adds the result to the packer - fv.iterateNested(path, rh); - } - break; - case RES_DATA: - case RES_LONG_DATA: - { - RawResultHandler rh(type, packer); - // the raw result handler adds the result to the packer - fv.iterateNested(path, rh); - } - break; - default: - LOG(warning, "Unknown docsum field type: %s", ResultConfig::GetResTypeName(type)); - packer.AddEmpty(); // unhandled output type - break; - } -} - - -void -DocsumFilter::writeSlimeField(const DocsumFieldSpec & fieldSpec, - const Document & docsum, - ResultPacker & packer) -{ - if (fieldSpec.getCommand() == VsmsummaryConfig::Fieldmap::Command::NONE) { - const DocsumFieldSpec::FieldIdentifier & fieldId = fieldSpec.getOutputField(); - const document::FieldValue * fv = docsum.getField(fieldId.getId()); - if (fv != nullptr) { - LOG(debug, "writeSlimeField: About to write field '%d' as Slime: field value = '%s'", - fieldId.getId(), fv->toString().c_str()); - CheckUndefinedValueVisitor check_undefined; - fv->accept(check_undefined); - if (!check_undefined.is_undefined()) { - SlimeFieldWriter writer; - if (! fieldSpec.hasIdentityMapping()) { - writer.setInputFields(fieldSpec.getInputFields()); - } - writer.convert(*fv); - const vespalib::stringref out = writer.out(); - packer.AddLongString(out.data(), out.size()); - } else { - packer.AddEmpty(); - } - } else { - LOG(debug, "writeSlimeField: Field value not set for field '%d'", fieldId.getId()); - packer.AddEmpty(); - } - } else { - LOG(debug, "writeSlimeField: Cannot handle this command"); - packer.AddEmpty(); - } -} - bool DocsumFilter::write_flatten_field(const DocsumFieldSpec& field_spec, const Document& doc) { @@ -484,118 +275,23 @@ DocsumFilter::write_flatten_field(const DocsumFieldSpec& field_spec, const Docum return true; } -void -DocsumFilter::writeFlattenField(const DocsumFieldSpec & fieldSpec, - const Document & docsum, - ResultPacker & packer) -{ - if (!write_flatten_field(fieldSpec, docsum)) { - packer.AddEmpty(); - return; - } - const CharBuffer & buf = _flattenWriter.getResult(); - switch (fieldSpec.getResultType()) { - case RES_STRING: - packer.AddString(buf.getBuffer(), buf.getPos()); - break; - case RES_LONG_STRING: - packer.AddLongString(buf.getBuffer(), buf.getPos()); - break; - default: - break; - } - _flattenWriter.clear(); -} - - -void -DocsumFilter::writeEmpty(ResType type, ResultPacker & packer) -{ - // use the 'notdefined' values when writing numeric values - switch (type) { - case RES_INT: - packer.AddInteger(std::numeric_limits<int32_t>::min()); - break; - case RES_SHORT: - packer.AddShort(std::numeric_limits<int16_t>::min()); - break; - case RES_BYTE: - packer.AddByte(std::numeric_limits<int8_t>::min()); - break; - case RES_FLOAT: - packer.AddFloat(std::numeric_limits<float>::quiet_NaN()); - break; - case RES_DOUBLE: - packer.AddDouble(std::numeric_limits<double>::quiet_NaN()); - break; - case RES_INT64: - packer.AddInt64(std::numeric_limits<int64_t>::min()); - break; - default: - packer.AddEmpty(); - break; - } -} - uint32_t DocsumFilter::getSummaryClassId() const { return _tools->getResultClass() ? _tools->getResultClass()->GetClassID() : ResultConfig::NoClassID(); } -DocsumStoreValue +std::unique_ptr<const IDocsumStoreDocument> DocsumFilter::getMappedDocsum(uint32_t id) { const ResultClass *resClass = _tools->getResultClass(); if (resClass == nullptr) { - return DocsumStoreValue(nullptr, 0); + return {}; } const Document & doc = _docsumCache->getDocSum(id); - _packer.Init(resClass->GetClassID()); - uint32_t entry_idx = 0; - for (FieldSpecList::iterator it(_fields.begin()), end = _fields.end(); it != end; ++it, ++entry_idx) { - if (entry_idx != _packer.get_entry_idx()) { - // Entry is not present in docsum blob - continue; - } - ResType type = it->getResultType(); - if (type == RES_JSONSTRING) { - // this really means 'structured data' - writeSlimeField(*it, doc, _packer); - } else { - if (it->getInputFields().size() == 1 && it->getCommand() == VsmsummaryConfig::Fieldmap::Command::NONE) { - const DocsumFieldSpec::FieldIdentifier & fieldId = it->getInputFields()[0]; - const document::FieldValue * field = doc.getField(fieldId.getId()); - if (field != nullptr) { - CheckUndefinedValueVisitor check_undefined; - field->accept(check_undefined); - if (!check_undefined.is_undefined()) { - writeField(*field, fieldId.getPath(), type, _packer); - } else { - writeEmpty(type, _packer); // void input - } - } else { - writeEmpty(type, _packer); // void input - } - } else if (it->getInputFields().size() == 0 && it->getCommand() == VsmsummaryConfig::Fieldmap::Command::NONE) { - LOG(spam, "0 inputfields for output field %u", it->getOutputField().getId()); - writeEmpty(type, _packer); // no input - } else { - writeFlattenField(*it, doc, _packer); - } - } - } - - const char *buf; - uint32_t buflen; - bool ok = _packer.GetDocsumBlob(&buf, &buflen); - if (ok) { - return DocsumStoreValue(buf, buflen, std::make_unique<DocsumStoreVsmDocument>(*this, doc)); - } else { - return DocsumStoreValue(nullptr, 0); - } + return std::make_unique<DocsumStoreVsmDocument>(*this, doc); } search::docsummary::DocsumStoreFieldValue diff --git a/streamingvisitors/src/vespa/vsm/vsm/docsumfilter.h b/streamingvisitors/src/vespa/vsm/vsm/docsumfilter.h index bcb89a59a12..17a85f142c8 100644 --- a/streamingvisitors/src/vespa/vsm/vsm/docsumfilter.h +++ b/streamingvisitors/src/vespa/vsm/vsm/docsumfilter.h @@ -8,14 +8,11 @@ #include <vespa/vsm/vsm/fieldsearchspec.h> #include <vespa/vsm/vsm/flattendocsumwriter.h> #include <vespa/vsm/vsm/vsm-adapter.h> -#include <vespa/searchsummary/docsummary/resultpacker.h> #include <vespa/searchsummary/docsummary/docsumstore.h> #include <vespa/searchsummary/docsummary/docsum_store_field_value.h> using search::docsummary::IDocsumStore; -using search::docsummary::DocsumStoreValue; using search::docsummary::ResType; -using search::docsummary::ResultPacker; namespace vsm { @@ -35,7 +32,6 @@ private: DocsumToolsPtr _tools; FieldSpecList _fields; // list of summary fields to generate size_t _highestFieldNo; - ResultPacker _packer; FlattenDocsumWriter _flattenWriter; const FieldModifierMap * _snippetModifiers; document::FieldValue::UP _cachedValue; @@ -48,11 +44,7 @@ private: const document::FieldValue * getFieldValue(const DocsumFieldSpec::FieldIdentifier & fieldId, VsmsummaryConfig::Fieldmap::Command command, const Document & docsum, bool & modified); - void writeField(const document::FieldValue & fv, const FieldPath & path, ResType type, ResultPacker & packer); - void writeSlimeField(const DocsumFieldSpec & fieldSpec, const Document & docsum, ResultPacker & packer); bool write_flatten_field(const DocsumFieldSpec& field_spec, const Document & docsum); - void writeFlattenField(const DocsumFieldSpec & fieldSpec, const Document & docsum, ResultPacker & packer); - void writeEmpty(ResType type, ResultPacker & packer); search::docsummary::DocsumStoreFieldValue get_struct_or_multivalue_summary_field(const DocsumFieldSpec& field_spec, const Document& doc); search::docsummary::DocsumStoreFieldValue get_flattened_summary_field(const DocsumFieldSpec& field_spec, const Document& doc); @@ -87,7 +79,7 @@ public: void setDocSumStore(const IDocSumCache & docsumCache) { _docsumCache = &docsumCache; } // Inherit doc from IDocsumStore - DocsumStoreValue getMappedDocsum(uint32_t id) override; + std::unique_ptr<const search::docsummary::IDocsumStoreDocument> getMappedDocsum(uint32_t id) override; uint32_t getNumDocs() const override; uint32_t getSummaryClassId() const override; diff --git a/streamingvisitors/src/vespa/vsm/vsm/vsm-adapter.cpp b/streamingvisitors/src/vespa/vsm/vsm/vsm-adapter.cpp index 206a73a632e..d4f470d9c47 100644 --- a/streamingvisitors/src/vespa/vsm/vsm/vsm-adapter.cpp +++ b/streamingvisitors/src/vespa/vsm/vsm/vsm-adapter.cpp @@ -9,7 +9,6 @@ LOG_SETUP(".vsm.vsm-adapter"); using search::docsummary::ResConfigEntry; -using search::docsummary::DocsumBlobEntryFilter; using search::docsummary::KeywordExtractor; using search::MatchingElements; using config::ConfigSnapshot; @@ -136,22 +135,7 @@ VSMAdapter::configure(const VSMConfigSnapshot & snapshot) LOG(debug, "configureVsmSummary(): outputclass='%s'", vsmSummary->outputclass.c_str()); // UlfC: debugging // init result config - DocsumBlobEntryFilter docsum_blob_entry_filter; - docsum_blob_entry_filter.add_skip(search::docsummary::RES_INT); - docsum_blob_entry_filter.add_skip(search::docsummary::RES_SHORT); - docsum_blob_entry_filter.add_skip(search::docsummary::RES_BOOL); - docsum_blob_entry_filter.add_skip(search::docsummary::RES_BYTE); - docsum_blob_entry_filter.add_skip(search::docsummary::RES_FLOAT); - docsum_blob_entry_filter.add_skip(search::docsummary::RES_DOUBLE); - docsum_blob_entry_filter.add_skip(search::docsummary::RES_INT64); - docsum_blob_entry_filter.add_skip(search::docsummary::RES_STRING); - docsum_blob_entry_filter.add_skip(search::docsummary::RES_DATA); - docsum_blob_entry_filter.add_skip(search::docsummary::RES_LONG_STRING); - docsum_blob_entry_filter.add_skip(search::docsummary::RES_LONG_DATA); - docsum_blob_entry_filter.add_skip(search::docsummary::RES_JSONSTRING); - docsum_blob_entry_filter.add_skip(search::docsummary::RES_TENSOR); - docsum_blob_entry_filter.add_skip(search::docsummary::RES_FEATUREDATA); - std::unique_ptr<ResultConfig> resCfg(new ResultConfig(docsum_blob_entry_filter)); + auto resCfg = std::make_unique<ResultConfig>(); if ( ! resCfg->ReadConfig(*summary.get(), _configId.c_str())) { throw std::runtime_error("(re-)configuration of VSM (docsum tools) failed due to bad summary config"); } |