diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-01-09 18:25:06 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-01-11 17:19:48 +0000 |
commit | 61a03191600c73942457902312f4669fa50b2801 (patch) | |
tree | e5d097352e01872b3b0e6e2dda31a2995bc547b1 | |
parent | 50d4755fedcec858bbc124f6a43db71685fea8c6 (diff) |
Handle bool in old summary framework too.
10 files changed, 146 insertions, 205 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/docsummary/documentstoreadapter.cpp b/searchcore/src/vespa/searchcore/proton/docsummary/documentstoreadapter.cpp index ea6a16e1547..c65d18a590f 100644 --- a/searchcore/src/vespa/searchcore/proton/docsummary/documentstoreadapter.cpp +++ b/searchcore/src/vespa/searchcore/proton/docsummary/documentstoreadapter.cpp @@ -24,9 +24,7 @@ const vespalib::string DOCUMENT_ID_FIELD("documentid"); } bool -DocumentStoreAdapter::writeStringField(const char * buf, - uint32_t buflen, - ResType type) +DocumentStoreAdapter::writeStringField(const char * buf, uint32_t buflen, ResType type) { switch (type) { case RES_STRING: @@ -47,6 +45,8 @@ DocumentStoreAdapter::writeField(const FieldValue &value, ResType type) switch (type) { case RES_BYTE: return _resultPacker.AddByte(value.getAsInt()); + case RES_BOOL: + return _resultPacker.AddByte(value.getAsInt()); case RES_SHORT: return _resultPacker.AddShort(value.getAsInt()); case RES_INT: @@ -63,8 +63,7 @@ DocumentStoreAdapter::writeField(const FieldValue &value, ResType type) case RES_JSONSTRING: { if (value.getClass().inherits(LiteralFieldValueB::classId)) { - const LiteralFieldValueB & lfv = - static_cast<const LiteralFieldValueB &>(value); + auto & lfv = static_cast<const LiteralFieldValueB &>(value); vespalib::stringref s = lfv.getValueRef(); return writeStringField(s.data(), s.size(), type); } else { @@ -86,7 +85,7 @@ DocumentStoreAdapter::writeField(const FieldValue &value, ResType type) { vespalib::nbostream serialized; if (value.getClass().inherits(TensorFieldValue::classId)) { - const TensorFieldValue &tvalue = static_cast<const TensorFieldValue &>(value); + const auto &tvalue = static_cast<const TensorFieldValue &>(value); const std::unique_ptr<Tensor> &tensor = tvalue.getAsTensorPtr(); if (tensor) { vespalib::tensor::TypedBinaryFormat::serialize(serialized, *tensor); @@ -95,9 +94,7 @@ DocumentStoreAdapter::writeField(const FieldValue &value, ResType type) return _resultPacker.AddSerializedTensor(serialized.peek(), serialized.size()); } default: - LOG(warning, - "Unknown docsum field type: %s. Add empty field", - ResultConfig::GetResTypeName(type)); + LOG(warning, "Unknown docsum field type: %s. Add empty field",ResultConfig::GetResTypeName(type)); return _resultPacker.AddEmpty(); } return false; @@ -114,46 +111,32 @@ DocumentStoreAdapter::convertFromSearchDoc(Document &doc, uint32_t docId) if (fieldName == DOCUMENT_ID_FIELD) { StringFieldValue value(doc.getId().toString()); if (!writeField(value, entry->_type)) { - LOG(warning, "Error while writing field '%s' for docId %u", - fieldName.c_str(), docId); + LOG(warning, "Error while writing field '%s' for docId %u", fieldName.c_str(), docId); } continue; } const Field *field = _fieldCache->getField(i); if (!field) { - LOG(debug, - "Did not find field '%s' in the document " - "for docId %u. Adding empty field", + LOG(debug, "Did not find field '%s' in the document for docId %u. Adding empty field", fieldName.c_str(), docId); _resultPacker.AddEmpty(); continue; } FieldValue::UP fieldValue = doc.getValue(*field); - if (fieldValue.get() == NULL) { - LOG(spam, - "No field value for field '%s' in the document " - "for docId %u. Adding empty field", + if ( ! fieldValue) { + LOG(spam, "No field value for field '%s' in the document for docId %u. Adding empty field", fieldName.c_str(), docId); _resultPacker.AddEmpty(); continue; } - LOG(spam, - "writeField(%s): value(%s), type(%d)", - fieldName.c_str(), fieldValue->toString().c_str(), - entry->_type); - FieldValue::UP convertedFieldValue = - SummaryFieldConverter::convertSummaryField(markup, *fieldValue); - if (convertedFieldValue.get() != NULL) { + LOG(spam, "writeField(%s): value(%s), type(%d)", fieldName.c_str(), fieldValue->toString().c_str(), entry->_type); + FieldValue::UP convertedFieldValue = SummaryFieldConverter::convertSummaryField(markup, *fieldValue); + if (convertedFieldValue) { if (!writeField(*convertedFieldValue, entry->_type)) { - LOG(warning, - "Error while writing field '%s' for docId %u", - fieldName.c_str(), docId); + LOG(warning, "Error while writing field '%s' for docId %u", fieldName.c_str(), docId); } } else { - LOG(spam, - "No converted field value for field '%s' " - " in the document " - "for docId %u. Adding empty field", + LOG(spam, "No converted field value for field '%s' in the document for docId %u. Adding empty field", fieldName.c_str(), docId); _resultPacker.AddEmpty(); } @@ -171,46 +154,33 @@ DocumentStoreAdapter(const search::IDocumentStore & docStore, _repo(repo), _resultConfig(resultConfig), _resultClass(resultConfig. - LookupResultClass(resultConfig. - LookupResultClassId(resultClassName. - c_str()))), + LookupResultClass(resultConfig.LookupResultClassId(resultClassName.c_str()))), _resultPacker(&_resultConfig), _fieldCache(fieldCache), _markupFields(markupFields) { } -DocumentStoreAdapter::~DocumentStoreAdapter() {} +DocumentStoreAdapter::~DocumentStoreAdapter() = default; DocsumStoreValue DocumentStoreAdapter::getMappedDocsum(uint32_t docId) { if (!_resultPacker.Init(getSummaryClassId())) { - LOG(warning, - "Error during init of result class '%s' with class id %u", - _resultClass->GetClassName(), getSummaryClassId()); + LOG(warning, "Error during init of result class '%s' with class id %u", _resultClass->GetClassName(), getSummaryClassId()); return DocsumStoreValue(); } Document::UP document = _docStore.read(docId, _repo); - if (document.get() == NULL) { - LOG(debug, - "Did not find summary document for docId %u. " - "Returning empty docsum", - docId); + if ( ! document) { + LOG(debug, "Did not find summary document for docId %u. Returning empty docsum", docId); return DocsumStoreValue(); } - LOG(spam, - "getMappedDocSum(%u): document={\n%s\n}", - docId, - document->toString(true).c_str()); + LOG(spam, "getMappedDocSum(%u): document={\n%s\n}", docId, document->toString(true).c_str()); convertFromSearchDoc(*document, docId); const char * buf; uint32_t buflen; if (!_resultPacker.GetDocsumBlob(&buf, &buflen)) { - LOG(warning, - "Error while getting the docsum blob for docId %u. " - "Returning empty docsum", - docId); + LOG(warning, "Error while getting the docsum blob for docId %u. Returning empty docsum", docId); return DocsumStoreValue(); } return DocsumStoreValue(buf, buflen); diff --git a/searchcore/src/vespa/searchcore/proton/docsummary/summarymanager.cpp b/searchcore/src/vespa/searchcore/proton/docsummary/summarymanager.cpp index 54961d10fd3..1abe9540859 100644 --- a/searchcore/src/vespa/searchcore/proton/docsummary/summarymanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/docsummary/summarymanager.cpp @@ -51,7 +51,7 @@ public: SerialNum flushedSerialNum, Time lastFlushTime, searchcorespi::index::IThreadService & summaryService, std::shared_ptr<ICompactableLidSpace> target); - ~ShrinkSummaryLidSpaceFlushTarget(); + ~ShrinkSummaryLidSpaceFlushTarget() override; Task::UP initFlush(SerialNum currentSerial) override; }; @@ -65,7 +65,7 @@ ShrinkSummaryLidSpaceFlushTarget(const vespalib::string &name, Type type, Compon { } -ShrinkSummaryLidSpaceFlushTarget::~ShrinkSummaryLidSpaceFlushTarget() {} +ShrinkSummaryLidSpaceFlushTarget::~ShrinkSummaryLidSpaceFlushTarget() = default; IFlushTarget::Task::UP ShrinkSummaryLidSpaceFlushTarget::initFlush(SerialNum currentSerial) @@ -93,7 +93,7 @@ SummarySetup(const vespalib::string & baseDir, const DocTypeName & docTypeName, _repo(repo), _markupFields() { - std::unique_ptr<ResultConfig> resultConfig(new ResultConfig()); + auto resultConfig = std::make_unique<ResultConfig>(); if (!resultConfig->ReadConfig(summaryCfg, make_string("SummaryManager(%s)", baseDir.c_str()).c_str())) { std::ostringstream oss; config::OstreamConfigWriter writer(oss); @@ -103,12 +103,11 @@ SummarySetup(const vespalib::string & baseDir, const DocTypeName & docTypeName, baseDir.c_str(), oss.str().c_str())); } - _juniperConfig.reset(new juniper::Juniper(&_juniperProps, &_wordFolder)); - _docsumWriter.reset(new DynamicDocsumWriter(resultConfig.release(), NULL)); + _juniperConfig = std::make_unique<juniper::Juniper>(&_juniperProps, &_wordFolder); + _docsumWriter = std::make_unique<DynamicDocsumWriter>(resultConfig.release(), nullptr); DynamicDocsumConfig dynCfg(this, _docsumWriter.get()); dynCfg.configure(summarymapCfg); - for (size_t i = 0; i < summarymapCfg.override.size(); ++i) { - const SummarymapConfig::Override & o = summarymapCfg.override[i]; + for (const auto & o : summarymapCfg.override) { if (o.command == "dynamicteaser" || o.command == "textextractor") { vespalib::string markupField = o.arguments; if (markupField.empty()) @@ -118,11 +117,11 @@ SummarySetup(const vespalib::string & baseDir, const DocTypeName & docTypeName, } } const DocumentType *docType = repo->getDocumentType(docTypeName.getName()); - if (docType != NULL) { - _fieldCacheRepo.reset(new FieldCacheRepo(getResultConfig(), *docType)); + if (docType != nullptr) { + _fieldCacheRepo = std::make_unique<FieldCacheRepo>(getResultConfig(), *docType); } else if (getResultConfig().GetNumResultClasses() == 0) { LOG(debug, "Create empty field cache repo for document type '%s'", docTypeName.toString().c_str()); - _fieldCacheRepo.reset(new FieldCacheRepo()); + _fieldCacheRepo = std::make_unique<FieldCacheRepo>(); } else { throw IllegalArgumentException(make_string("Did not find document type '%s' in current document type repo." " Cannot setup field cache repo for the summary setup", @@ -212,7 +211,7 @@ IFlushTarget::List SummaryManager::getFlushTargets(searchcorespi::index::IThread } void SummaryManager::reconfigure(const LogDocumentStore::Config & config) { - LogDocumentStore & docStore = dynamic_cast<LogDocumentStore &> (*_docStore); + auto & docStore = dynamic_cast<LogDocumentStore &> (*_docStore); docStore.reconfigure(config); } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.cpp index 18e7e471663..1eb8399845c 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.cpp @@ -29,10 +29,10 @@ IDocsumFieldWriter::setFieldWriterStateIndex(uint32_t) //-------------------------------------------------------------------------- -EmptyDFW::EmptyDFW() { } +EmptyDFW::EmptyDFW() = default; -EmptyDFW::~EmptyDFW() { } +EmptyDFW::~EmptyDFW() = default; void EmptyDFW::insertField(uint32_t /*docid*/, @@ -55,9 +55,7 @@ CopyDFW::CopyDFW() } -CopyDFW::~CopyDFW() -{ -} +CopyDFW::~CopyDFW() = default; bool @@ -69,11 +67,10 @@ CopyDFW::Init(const ResultConfig & config, const char *inputField) LOG(warning, "no docsum format contains field '%s'; copied fields will be empty", inputField); } - for (ResultConfig::const_iterator it(config.begin()), mt(config.end()); it != mt; it++) { - const ResConfigEntry *entry = - it->GetEntry(it->GetIndexFromEnumValue(_inputFieldEnumValue)); + for (const auto & field : config) { + const ResConfigEntry *entry = field.GetEntry(field.GetIndexFromEnumValue(_inputFieldEnumValue)); - if (entry != NULL && + if (entry != nullptr && !IsRuntimeCompatible(entry->_type, RES_INT) && !IsRuntimeCompatible(entry->_type, RES_DOUBLE) && !IsRuntimeCompatible(entry->_type, RES_INT64) && @@ -81,7 +78,7 @@ CopyDFW::Init(const ResultConfig & config, const char *inputField) !IsRuntimeCompatible(entry->_type, RES_DATA)) { LOG(warning, "cannot use docsum field '%s' as input to copy; type conflict with result class %d (%s)", - inputField, it->GetClassID(), it->GetClassName()); + inputField, field.GetClassID(), field.GetClassName()); return false; } } @@ -90,16 +87,13 @@ CopyDFW::Init(const ResultConfig & config, const char *inputField) void -CopyDFW::insertField(uint32_t /*docid*/, - GeneralResult *gres, - GetDocsumsState *state, - ResType type, - vespalib::slime::Inserter &target) +CopyDFW::insertField(uint32_t /*docid*/, GeneralResult *gres, GetDocsumsState *state, ResType type, + vespalib::slime::Inserter &target) { int idx = gres->GetClass()->GetIndexFromEnumValue(_inputFieldEnumValue); ResEntry *entry = gres->GetEntry(idx); - if (entry != NULL && + if (entry != nullptr && IsRuntimeCompatible(entry->_type, type)) { switch (type) { @@ -117,6 +111,9 @@ CopyDFW::insertField(uint32_t /*docid*/, uint8_t val8 = entry->_intval; target.insertLong(val8); break; } + case RES_BOOL: { + target.insertBool(entry->_intval != 0); + break; } case RES_FLOAT: { float valfloat = entry->_doubleval; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp index 722ea9d9000..72dbddda0b4 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp @@ -78,23 +78,23 @@ DynamicDocsumWriter::resolveInputClass(ResolveClassInfo &rci, uint32_t id) const } } -static void convertEntry(GetDocsumsState *state, - const ResConfigEntry *resCfg, - const ResEntry *entry, - Inserter &inserter, - Slime &slime) +static void convertEntry(GetDocsumsState *state, const ResConfigEntry *resCfg, const ResEntry *entry, + Inserter &inserter, Slime &slime) { using vespalib::slime::BinaryFormat; const char *ptr; uint32_t len; - LOG_ASSERT(resCfg != 0 && entry != 0); + LOG_ASSERT(resCfg != nullptr && entry != nullptr); switch (resCfg->_type) { case RES_INT: case RES_SHORT: case RES_BYTE: inserter.insertLong(entry->_intval); break; + case RES_BOOL: + inserter.insertBool(entry->_intval != 0); + break; case RES_FLOAT: case RES_DOUBLE: inserter.insertDouble(entry->_doubleval); @@ -130,12 +130,8 @@ static void convertEntry(GetDocsumsState *state, void -DynamicDocsumWriter::insertDocsum(const ResolveClassInfo & rci, - uint32_t docid, - GetDocsumsState *state, - IDocsumStore *docinfos, - vespalib::Slime & slime, - vespalib::slime::Inserter & topInserter) +DynamicDocsumWriter::insertDocsum(const ResolveClassInfo & rci, uint32_t docid, GetDocsumsState *state, + IDocsumStore *docinfos, vespalib::Slime & slime, vespalib::slime::Inserter & topInserter) { if (rci.allGenerated) { // generate docsum entry on-the-fly @@ -144,8 +140,7 @@ DynamicDocsumWriter::insertDocsum(const ResolveClassInfo & rci, const ResConfigEntry *resCfg = rci.outputClass->GetEntry(i); IDocsumFieldWriter *writer = _overrideTable[resCfg->_enumValue]; if (! writer->isDefaultValue(docid, state)) { - const Memory field_name(resCfg->_bindname.data(), - resCfg->_bindname.size()); + const Memory field_name(resCfg->_bindname.data(), resCfg->_bindname.size()); ObjectInserter inserter(docsum, field_name); writer->insertField(docid, nullptr, state, resCfg->_type, inserter); } @@ -272,10 +267,10 @@ DynamicDocsumWriter::Override(const char *fieldName, IDocsumFieldWriter *writer) ++_numFieldWriterStates; } - for (ResultConfig::iterator it(_resultConfig->begin()), mt(_resultConfig->end()); it != mt; it++) { + for (auto & entry : *_resultConfig) { - if (it->GetIndexFromEnumValue(fieldEnumValue) >= 0) { - ResultClass::DynamicInfo *info = it->getDynamicInfo(); + if (entry.GetIndexFromEnumValue(fieldEnumValue) >= 0) { + ResultClass::DynamicInfo *info = entry.getDynamicInfo(); info->_overrideCnt++; if (writer->IsGenerated()) info->_generateCnt++; @@ -306,15 +301,11 @@ DynamicDocsumWriter::InitState(IAttributeManager & attrMan, GetDocsumsState *sta uint32_t -DynamicDocsumWriter::WriteDocsum(uint32_t docid, - GetDocsumsState *state, - IDocsumStore *docinfos, - search::RawBuf *target) +DynamicDocsumWriter::WriteDocsum(uint32_t docid, GetDocsumsState *state, IDocsumStore *docinfos, search::RawBuf *target) { vespalib::Slime slime; vespalib::slime::SlimeInserter inserter(slime); - ResolveClassInfo rci = resolveClassInfo(state->_args.getResultClassName(), - docinfos->getSummaryClassId()); + ResolveClassInfo rci = resolveClassInfo(state->_args.getResultClassName(), docinfos->getSummaryClassId()); insertDocsum(rci, docid, state, docinfos, slime, inserter); return slime2RawBuf(slime, *target); } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/resultclass.h b/searchsummary/src/vespa/searchsummary/docsummary/resultclass.h index e7c7c799b5f..52e331cd365 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/resultclass.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/resultclass.h @@ -18,6 +18,7 @@ namespace search::docsummary { enum ResType { RES_INT = 0, RES_SHORT, + RES_BOOL, RES_BYTE, RES_FLOAT, RES_DOUBLE, diff --git a/searchsummary/src/vespa/searchsummary/docsummary/resultconfig.cpp b/searchsummary/src/vespa/searchsummary/docsummary/resultconfig.cpp index 1c42709826f..3758ca27adf 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/resultconfig.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/resultconfig.cpp @@ -45,6 +45,7 @@ ResultConfig::GetResTypeName(ResType type) case RES_INT: return "integer"; case RES_SHORT: return "short"; case RES_BYTE: return "byte"; + case RES_BOOL: return "bool"; case RES_FLOAT: return "float"; case RES_DOUBLE: return "double"; case RES_INT64: return "int64"; @@ -73,15 +74,14 @@ ResultConfig::Reset() ResultClass * ResultConfig::AddResultClass(const char *name, uint32_t id) { - ResultClass *ret = NULL; + ResultClass *ret = nullptr; if (id != NoClassID() && (_classLookup.find(id) == _classLookup.end())) { ResultClass::UP rc(new ResultClass(name, id, _fieldEnum)); ret = rc.get(); _classLookup[id] = std::move(rc); if (_nameLookup.find(name) != _nameLookup.end()) { - LOG(warning, "Duplicate result class name: %s " - "(now maps to class id %u)", name, id); + LOG(warning, "Duplicate result class name: %s (now maps to class id %u)", name, id); } _nameLookup[name] = id; } @@ -93,7 +93,7 @@ const ResultClass* ResultConfig::LookupResultClass(uint32_t id) const { IdMap::const_iterator it(_classLookup.find(id)); - return (it != _classLookup.end()) ? it->second.get() : NULL; + return (it != _classLookup.end()) ? it->second.get() : nullptr; } uint32_t @@ -113,8 +113,8 @@ ResultConfig::LookupResultClassId(const vespalib::string &name) const void ResultConfig::CreateEnumMaps() { - for (IdMap::iterator it(_classLookup.begin()), mt(_classLookup.end()); it != mt; it++) { - it ->second->CreateEnumMap(); + for (auto & entry : _classLookup) { + entry.second->CreateEnumMap(); } } @@ -137,14 +137,12 @@ ResultConfig::ReadConfig(const vespa::config::search::SummaryConfig &cfg, const break; } ResultClass *resClass = AddResultClass(cfg.classes[i].name.c_str(), classID); - if (resClass == NULL) { - LOG(error, - "%s: unable to add classes[%d] name %s", - configId, i, cfg.classes[i].name.c_str()); + if (resClass == nullptr) { + LOG(error,"%s: unable to add classes[%d] name %s", configId, i, cfg.classes[i].name.c_str()); rc = false; break; } - for (unsigned int j = 0; rc && j < cfg.classes[i].fields.size(); j++) { + for (unsigned int j = 0; rc && (j < cfg.classes[i].fields.size()); j++) { const char *fieldtype = cfg.classes[i].fields[j].type.c_str(); const char *fieldname = cfg.classes[i].fields[j].name.c_str(); LOG(debug, "Reconfiguring class '%s' field '%s' of type '%s'", cfg.classes[i].name.c_str(), fieldname, fieldtype); @@ -152,6 +150,8 @@ ResultConfig::ReadConfig(const vespa::config::search::SummaryConfig &cfg, const rc = resClass->AddConfigEntry(fieldname, RES_INT); } else if (strcmp(fieldtype, "short") == 0) { rc = resClass->AddConfigEntry(fieldname, RES_SHORT); + } else if (strcmp(fieldtype, "bool") == 0) { + rc = resClass->AddConfigEntry(fieldname, RES_BOOL); } else if (strcmp(fieldtype, "byte") == 0) { rc = resClass->AddConfigEntry(fieldname, RES_BYTE); } else if (strcmp(fieldtype, "float") == 0) { @@ -176,17 +176,13 @@ ResultConfig::ReadConfig(const vespa::config::search::SummaryConfig &cfg, const rc = resClass->AddConfigEntry(fieldname, RES_TENSOR); } else if (strcmp(fieldtype, "featuredata") == 0) { rc = resClass->AddConfigEntry(fieldname, RES_FEATUREDATA); - } else { // FAIL: unknown field type - LOG(error, - "%s %s.fields[%d]: unknown type '%s'", - configId, cfg.classes[i].name.c_str(), j, fieldtype); + } else { + LOG(error, "%s %s.fields[%d]: unknown type '%s'", configId, cfg.classes[i].name.c_str(), j, fieldtype); rc = false; break; } - if (!rc) { // FAIL: duplicate field name - LOG(error, - "%s %s.fields[%d]: duplicate name '%s'", - configId, cfg.classes[i].name.c_str(), j, fieldname); + if (!rc) { + LOG(error, "%s %s.fields[%d]: duplicate name '%s'", configId, cfg.classes[i].name.c_str(), j, fieldname); break; } } @@ -213,14 +209,11 @@ ResultConfig::GetClassID(const char *buf, uint32_t buflen) } urlresult* -ResultConfig::Unpack(uint32_t partition, - uint32_t docid, - HitRank metric, - const char *buf, - uint32_t buflen) const +ResultConfig::Unpack(uint32_t partition, uint32_t docid, HitRank metric, + const char *buf, uint32_t buflen) const { - urlresult *ret = NULL; - const ResultClass *resClass = NULL; + urlresult *ret = nullptr; + const ResultClass *resClass = nullptr; uint32_t tmp32; if (buflen >= sizeof(tmp32)) { @@ -230,15 +223,15 @@ ResultConfig::Unpack(uint32_t partition, resClass = LookupResultClass(tmp32); } - if (resClass != NULL && (buflen > 0)) { - ret = new GeneralResult(resClass, partition, docid, metric); + if (resClass != nullptr && (buflen > 0)) { + ret = new GeneralResult(resClass, partition, docid, metric); if (ret->unpack(buf, buflen) != 0) { // FAIL: unpack delete ret; - ret = NULL; + ret = nullptr; } } - return (ret != NULL) ? ret : new badurlresult(partition, docid, metric); + return (ret != nullptr) ? ret : new badurlresult(partition, docid, metric); } } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/resultconfig.h b/searchsummary/src/vespa/searchsummary/docsummary/resultconfig.h index eac6d4b113f..f9c8ccbaa40 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/resultconfig.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/resultconfig.h @@ -115,6 +115,9 @@ public: return true; } switch (a) { + case RES_BYTE: + case RES_BOOL: + return (b == RES_BYTE || b == RES_BOOL); case RES_STRING: case RES_DATA: return (b == RES_STRING || b == RES_DATA); @@ -147,7 +150,8 @@ public: case RES_INT: case RES_SHORT: case RES_BYTE: - return (b == RES_INT || b == RES_SHORT || b == RES_BYTE); + case RES_BOOL: + return (b == RES_INT || b == RES_SHORT || b == RES_BYTE || b == RES_BOOL); case RES_FLOAT: case RES_DOUBLE: return (b == RES_FLOAT || b == RES_DOUBLE); @@ -287,11 +291,7 @@ public: * @param buflen length of docsum blob. **/ urlresult * - Unpack(uint32_t partition, - uint32_t docid, - HitRank metric, - const char *buf, - uint32_t buflen) const; + Unpack(uint32_t partition, uint32_t docid, HitRank metric, const char *buf, uint32_t buflen) const; }; } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/resultpacker.cpp b/searchsummary/src/vespa/searchsummary/docsummary/resultpacker.cpp index 178e1a90667..c9642b80e56 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/resultpacker.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/resultpacker.cpp @@ -23,7 +23,7 @@ bool ResultPacker::CheckEntry(ResType type) if (_error) return false; - bool rc = (_cfgEntry != NULL && + bool rc = (_cfgEntry != nullptr && IsBinaryCompatible(_cfgEntry->_type, type)); if (rc) { @@ -43,7 +43,7 @@ ResultPacker::SetFormatError(ResType type) { _error = true; - if (_cfgEntry != NULL) { + if (_cfgEntry != nullptr) { LOG(error, "ResultPacker: format error: got '%s', expected '%s'", GetResTypeName(type), @@ -60,17 +60,15 @@ ResultPacker::ResultPacker(const ResultConfig *resConfig) : _buf(32768), _cbuf(32768), _resConfig(resConfig), - _resClass(NULL), + _resClass(nullptr), _entryIdx(0), - _cfgEntry(NULL), + _cfgEntry(nullptr), _error(true) { } -ResultPacker::~ResultPacker() -{ -} +ResultPacker::~ResultPacker() = default; void ResultPacker::InitPlain() @@ -82,16 +80,16 @@ bool ResultPacker::Init(uint32_t classID) { _buf.reset(); - _resClass = (_resConfig != NULL) ? - _resConfig->LookupResultClass(classID) : NULL; + _resClass = (_resConfig != nullptr) ? + _resConfig->LookupResultClass(classID) : nullptr; _entryIdx = 0; - if (_resClass != NULL) { + if (_resClass != nullptr) { uint32_t id = _resClass->GetClassID(); _buf.append(&id, sizeof(id)); _cfgEntry = _resClass->GetEntry(_entryIdx); _error = false; } else { - _cfgEntry = NULL; + _cfgEntry = nullptr; _error = true; LOG(error, "ResultPacker: resultclass %d does not exist", classID); @@ -104,22 +102,23 @@ ResultPacker::Init(uint32_t classID) bool ResultPacker::AddEmpty() { - if (!_error && _cfgEntry != NULL) { + if (!_error && _cfgEntry != nullptr) { switch (_cfgEntry->_type) { case RES_INT: return AddInteger(search::attribute::getUndefined<int32_t>()); case RES_SHORT: return AddShort(search::attribute::getUndefined<int16_t>()); + case RES_BOOL: return AddByte(0); case RES_BYTE: return AddByte(search::attribute::getUndefined<int8_t>()); case RES_FLOAT: return AddFloat(search::attribute::getUndefined<float>()); case RES_DOUBLE: return AddDouble(search::attribute::getUndefined<double>()); case RES_INT64: return AddInt64(search::attribute::getUndefined<int64_t>()); - case RES_STRING: return AddString(NULL, 0); - case RES_DATA: return AddData(NULL, 0); + case RES_STRING: return AddString(nullptr, 0); + case RES_DATA: return AddData(nullptr, 0); case RES_XMLSTRING: case RES_JSONSTRING: case RES_FEATUREDATA: - case RES_LONG_STRING: return AddLongString(NULL, 0); - case RES_TENSOR: return AddSerializedTensor(NULL, 0); - case RES_LONG_DATA: return AddLongData(NULL, 0); + case RES_LONG_STRING: return AddLongString(nullptr, 0); + case RES_TENSOR: return AddSerializedTensor(nullptr, 0); + case RES_LONG_DATA: return AddLongData(nullptr, 0); } } return AddInteger(0); // to provoke error condition @@ -271,7 +270,7 @@ ResultPacker::GetDocsumBlob(const char **buf, uint32_t *buflen) _resClass->GetNumEntries() - _entryIdx); } if (_error) { - *buf = NULL; + *buf = nullptr; *buflen = 0; return false; } else { diff --git a/searchsummary/src/vespa/searchsummary/docsummary/urlresult.cpp b/searchsummary/src/vespa/searchsummary/docsummary/urlresult.cpp index 9cd5c58f971..646a167b5a8 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/urlresult.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/urlresult.cpp @@ -17,7 +17,7 @@ urlresult::urlresult(uint32_t partition, uint32_t docid, HitRank metric) { } -urlresult::~urlresult() { } +urlresult::~urlresult() = default; /*===============================================================*/ @@ -33,14 +33,12 @@ badurlresult::badurlresult(uint32_t partition, uint32_t docid, HitRank metric) { } -badurlresult::~badurlresult() { } +badurlresult::~badurlresult() = default; int -badurlresult::unpack(const char *buf, const size_t buflen) +badurlresult::unpack(const char *, const size_t ) { - (void) buf; - (void) buflen; LOG(warning, "badurlresult::unpack"); return 0; } @@ -60,10 +58,10 @@ GeneralResult::AllocEntries(uint32_t buflen, bool inplace) if (cnt > 0) { _entrycnt = cnt; _entries = (ResEntry *) malloc(needMem); - assert(_entries != NULL); + assert(_entries != nullptr); if (inplace) { - _buf = NULL; - _bufEnd = NULL; + _buf = nullptr; + _bufEnd = nullptr; } else { _buf = ((char *)_entries) + cnt * sizeof(ResEntry); _bufEnd = _buf + buflen + 1; @@ -71,9 +69,9 @@ GeneralResult::AllocEntries(uint32_t buflen, bool inplace) memset(_entries, 0, cnt * sizeof(ResEntry)); } else { _entrycnt = 0; - _entries = NULL; - _buf = NULL; - _bufEnd = NULL; + _entries = nullptr; + _buf = nullptr; + _bufEnd = nullptr; } } @@ -83,8 +81,8 @@ GeneralResult::FreeEntries() { uint32_t cnt = _entrycnt; - // (_buf == NULL) <=> (_inplace_unpack() || (cnt == 0)) - if (_buf != NULL) { + // (_buf == nullptr) <=> (_inplace_unpack() || (cnt == 0)) + if (_buf != nullptr) { for (uint32_t i = 0; i < cnt; i++) { if (ResultConfig::IsVariableSize(_entries[i]._type) && !InBuf(_entries[i]._stringval)) @@ -96,15 +94,13 @@ GeneralResult::FreeEntries() -GeneralResult::GeneralResult(const ResultClass *resClass, - uint32_t partition, uint32_t docid, - HitRank metric) +GeneralResult::GeneralResult(const ResultClass *resClass, uint32_t partition, uint32_t docid, HitRank metric) : urlresult(partition, docid, metric), _resClass(resClass), _entrycnt(0), - _entries(NULL), - _buf(NULL), - _bufEnd(NULL) + _entries(nullptr), + _buf(nullptr), + _bufEnd(nullptr) { } @@ -118,7 +114,7 @@ GeneralResult::~GeneralResult() ResEntry * GeneralResult::GetEntry(uint32_t idx) { - return (idx < _entrycnt) ? &_entries[idx] : NULL; + return (idx < _entrycnt) ? &_entries[idx] : nullptr; } @@ -128,7 +124,7 @@ GeneralResult::GetEntry(const char *name) int idx = _resClass->GetIndexFromName(name); return (idx >= 0 && (uint32_t)idx < _entrycnt) ? - &_entries[idx] : NULL; + &_entries[idx] : nullptr; } @@ -138,7 +134,7 @@ GeneralResult::GetEntryFromEnumValue(uint32_t value) int idx = _resClass->GetIndexFromEnumValue(value); return (idx >= 0 && (uint32_t)idx < _entrycnt) ? - &_entries[idx] : NULL; + &_entries[idx] : nullptr; } @@ -149,7 +145,7 @@ GeneralResult::unpack(const char *buf, const size_t buflen) const char *ebuf = buf + buflen; // Ref to first after buffer const char *p = buf; // current position in buffer - if (_entries != NULL) + if (_entries != nullptr) FreeEntries(); AllocEntries(buflen); @@ -195,6 +191,7 @@ GeneralResult::unpack(const char *buf, const size_t buflen) break; } + case RES_BOOL: case RES_BYTE: { uint8_t byteval; @@ -360,7 +357,7 @@ GeneralResult::unpack(const char *buf, const size_t buflen) if (realLen > 0) { _entries[i]._stringval = new char[realLen + 1]; } - if (_entries[i]._stringval != NULL) { + if (_entries[i]._stringval != nullptr) { uLongf rlen = realLen; if ((uncompress((Bytef *)_entries[i]._stringval, &rlen, (const Bytef *)(p + sizeof(realLen)), @@ -376,11 +373,11 @@ GeneralResult::unpack(const char *buf, const size_t buflen) LOG(warning, "Cannot uncompress docsum field %s; decompression error", entry->_bindname.c_str()); delete [] _entries[i]._stringval; - _entries[i]._stringval = NULL; + _entries[i]._stringval = nullptr; } } // insert empty field if decompress failed - if (_entries[i]._stringval == NULL) { + if (_entries[i]._stringval == nullptr) { _entries[i]._stringval = _buf + (p - buf); _entries[i]._stringval[0] = '\0'; _entries[i]._stringlen = 0; @@ -438,7 +435,7 @@ GeneralResult::unpack(const char *buf, const size_t buflen) if (realLen > 0) { _entries[i]._dataval = new char [realLen + 1]; } - if (_entries[i]._dataval != NULL) { + if (_entries[i]._dataval != nullptr) { uLongf rlen = realLen; if ((uncompress((Bytef *)_entries[i]._dataval, &rlen, (const Bytef *)(p + sizeof(realLen)), @@ -454,12 +451,12 @@ GeneralResult::unpack(const char *buf, const size_t buflen) LOG(warning, "Cannot uncompress docsum field %s; decompression error", entry->_bindname.c_str()); delete [] _entries[i]._dataval; - _entries[i]._dataval = NULL; + _entries[i]._dataval = nullptr; } } // insert empty field if decompress failed - if (_entries[i]._dataval == NULL) { + if (_entries[i]._dataval == nullptr) { _entries[i]._dataval = _buf + (p - buf); _entries[i]._dataval[0] = '\0'; _entries[i]._datalen = 0; @@ -512,9 +509,9 @@ GeneralResult::unpack(const char *buf, const size_t buflen) // clean up on failure FreeEntries(); _entrycnt = 0; - _entries = NULL; - _buf = NULL; - _bufEnd = NULL; + _entries = nullptr; + _buf = nullptr; + _bufEnd = nullptr; return -1; // FAIL } @@ -527,7 +524,7 @@ GeneralResult::_inplace_unpack(const char *buf, const size_t buflen) const char *ebuf = buf + buflen; // Ref to first after buffer const char *p = buf; // current position in buffer - if (_entries != NULL) + if (_entries != nullptr) FreeEntries(); AllocEntries(buflen, true); @@ -547,8 +544,7 @@ GeneralResult::_inplace_unpack(const char *buf, const size_t buflen) } else { - LOG(debug, - "GeneralResult::_inplace_unpack: p + sizeof(..._intval) > ebuf"); + LOG(debug, "GeneralResult::_inplace_unpack: p + sizeof(..._intval) > ebuf"); LOG(error, "Document summary too short, couldn't unpack"); rc = false; } @@ -567,14 +563,13 @@ GeneralResult::_inplace_unpack(const char *buf, const size_t buflen) } else { - LOG(debug, - "GeneralResult::_inplace_unpack: p + sizeof(shortval) > ebuf"); + LOG(debug, "GeneralResult::_inplace_unpack: p + sizeof(shortval) > ebuf"); LOG(error, "Document summary too short, couldn't unpack"); rc = false; } break; } - + case RES_BOOL: case RES_BYTE: { uint8_t byteval; @@ -587,8 +582,7 @@ GeneralResult::_inplace_unpack(const char *buf, const size_t buflen) } else { - LOG(debug, - "GeneralResult::_inplace_unpack: p + sizeof(byteval) > ebuf"); + LOG(debug, "GeneralResult::_inplace_unpack: p + sizeof(byteval) > ebuf"); LOG(error, "Document summary too short, couldn't unpack"); rc = false; } @@ -782,9 +776,7 @@ GeneralResult::_inplace_unpack(const char *buf, const size_t buflen) } default: - LOG(warning, - "GeneralResult::_inplace_unpack: no such type:%d", - entry->_type); + LOG(warning, "GeneralResult::_inplace_unpack: no such type:%d", entry->_type); LOG(error, "Incorrect type in document summary, couldn't unpack"); rc = false; break; @@ -803,9 +795,9 @@ GeneralResult::_inplace_unpack(const char *buf, const size_t buflen) // clean up on failure FreeEntries(); _entrycnt = 0; - _entries = NULL; - _buf = NULL; - _bufEnd = NULL; + _entries = nullptr; + _buf = nullptr; + _bufEnd = nullptr; return false; // FAIL } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/urlresult.h b/searchsummary/src/vespa/searchsummary/docsummary/urlresult.h index 4d1fca0992d..31128c73ca2 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/urlresult.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/urlresult.h @@ -60,8 +60,7 @@ private: bool _inplace_unpack(const char *buf, const size_t buflen); public: - GeneralResult(const ResultClass *resClass, uint32_t partition, - uint32_t docid, HitRank metric); + GeneralResult(const ResultClass *resClass, uint32_t partition, uint32_t docid, HitRank metric); ~GeneralResult(); const ResultClass *GetClass() const { return _resClass; } @@ -73,7 +72,7 @@ public: bool inplaceUnpack(const DocsumStoreValue &value) { if (value.valid()) { - return _inplace_unpack(value.fieldsPt(), value.fieldsSz()); + return _inplace_unpack(value.fieldsPt(), value.fieldsSz()); } else { return false; } |