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 /searchcore | |
parent | 50d4755fedcec858bbc124f6a43db71685fea8c6 (diff) |
Handle bool in old summary framework too.
Diffstat (limited to 'searchcore')
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/docsummary/documentstoreadapter.cpp | 74 | ||||
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/docsummary/summarymanager.cpp | 21 |
2 files changed, 32 insertions, 63 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); } |