diff options
author | Tor Egge <Tor.Egge@online.no> | 2022-07-06 11:28:21 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2022-07-06 11:28:21 +0200 |
commit | e6fa1adf5b6270e1fda479e89e79f00e47c99b26 (patch) | |
tree | df6f28f649ddec1151ede975b602aea5a92c689d /searchsummary/src | |
parent | 59bbee7e7130e482502761688057c4908d021682 (diff) |
Restore original semantics of ResultClass::GetIndexFromName() and
ResultClass::GetIndexFromEnumValue. Caller must check for entry being present.
Rename GeneralResult member functions that checks for entry being present.
Diffstat (limited to 'searchsummary/src')
10 files changed, 36 insertions, 45 deletions
diff --git a/searchsummary/src/tests/docsumformat/docsum-pack.cpp b/searchsummary/src/tests/docsumformat/docsum-pack.cpp index ed1ba23017c..07aceea83e0 100644 --- a/searchsummary/src/tests/docsumformat/docsum-pack.cpp +++ b/searchsummary/src/tests/docsumformat/docsum-pack.cpp @@ -113,7 +113,7 @@ MyApp::Equal(GeneralResult *a, GeneralResult *b) void MyApp::TestIntValue(uint32_t line, GeneralResult *gres, const char *field, uint32_t value) { - ResEntry *entry = (gres != nullptr) ? gres->GetEntry(field) : nullptr; + ResEntry *entry = (gres != nullptr) ? gres->GetPresentEntry(field) : nullptr; bool rc = (entry != nullptr && entry->_type == RES_INT && @@ -125,7 +125,7 @@ MyApp::TestIntValue(uint32_t line, GeneralResult *gres, const char *field, uint3 void MyApp::TestDoubleValue(uint32_t line, GeneralResult *gres, const char *field, double value) { - ResEntry *entry = (gres != nullptr) ? gres->GetEntry(field) : nullptr; + ResEntry *entry = (gres != nullptr) ? gres->GetPresentEntry(field) : nullptr; bool rc = (entry != nullptr && entry->_type == RES_DOUBLE && @@ -137,7 +137,7 @@ MyApp::TestDoubleValue(uint32_t line, GeneralResult *gres, const char *field, do void MyApp::TestInt64Value(uint32_t line, GeneralResult *gres, const char *field, uint64_t value) { - ResEntry *entry = (gres != nullptr) ? gres->GetEntry(field) : nullptr; + ResEntry *entry = (gres != nullptr) ? gres->GetPresentEntry(field) : nullptr; bool rc = (entry != nullptr && entry->_type == RES_INT64 && @@ -150,7 +150,7 @@ MyApp::TestInt64Value(uint32_t line, GeneralResult *gres, const char *field, uin void MyApp::TestStringValue(uint32_t line, GeneralResult *gres, const char *field, const char *value) { - ResEntry *entry = (gres != nullptr) ? gres->GetEntry(field) : nullptr; + ResEntry *entry = (gres != nullptr) ? gres->GetPresentEntry(field) : nullptr; bool rc = (entry != nullptr && entry->_type == RES_STRING && @@ -168,7 +168,7 @@ MyApp::TestStringValue(uint32_t line, GeneralResult *gres, const char *field, co void MyApp::TestDataValue(uint32_t line, GeneralResult *gres, const char *field, const char *value) { - ResEntry *entry = (gres != nullptr) ? gres->GetEntry(field) : nullptr; + ResEntry *entry = (gres != nullptr) ? gres->GetPresentEntry(field) : nullptr; bool rc = (entry != nullptr && entry->_type == RES_DATA && diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.cpp index 416526bead3..0f0ac9ddf72 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.cpp @@ -64,10 +64,10 @@ CopyDFW::Init(const ResultConfig & config, const char *inputField) LOG(warning, "no docsum format contains field '%s'; copied fields will be empty", inputField); } - for (const auto & field : config) { - const ResConfigEntry *entry = field.GetEntry(field.GetIndexFromEnumValue(_inputFieldEnumValue)); + for (const auto & result_class : config) { + const ResConfigEntry *entry = result_class.GetEntry(result_class.GetIndexFromEnumValue(_inputFieldEnumValue)); - if (entry != nullptr && + if (entry != nullptr && !entry->_not_present && !IsRuntimeCompatible(entry->_type, RES_INT) && !IsRuntimeCompatible(entry->_type, RES_DOUBLE) && !IsRuntimeCompatible(entry->_type, RES_INT64) && @@ -75,7 +75,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, field.GetClassID(), field.GetClassName()); + inputField, result_class.GetClassID(), result_class.GetClassName()); return false; } } @@ -87,7 +87,7 @@ CopyDFW::insertField(uint32_t /*docid*/, GeneralResult *gres, GetDocsumsState *, vespalib::slime::Inserter &target) { int idx = gres->GetClass()->GetIndexFromEnumValue(_inputFieldEnumValue); - ResEntry *entry = gres->GetEntry(idx); + ResEntry *entry = gres->GetPresentEntry(idx); if (entry == nullptr) { const auto* document = gres->get_document(); diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp index a5ad577e240..c6e5a224e21 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp @@ -201,7 +201,7 @@ DynamicDocsumWriter::insertDocsum(const ResolveClassInfo & rci, uint32_t docid, } else { int inIdx = rci.inputClass->GetIndexFromEnumValue(outCfg->_enumValue); const ResConfigEntry *inCfg = rci.inputClass->GetEntry(inIdx); - if (inCfg != nullptr && inCfg->_type == outCfg->_type) { + if (inCfg != nullptr && inCfg->_type == outCfg->_type && !inCfg->_not_present) { // copy field const ResEntry *entry = gres.GetEntry(inIdx); LOG_ASSERT(entry != nullptr); @@ -302,10 +302,10 @@ DynamicDocsumWriter::Override(const char *fieldName, IDocsumFieldWriter *writer) ++_numFieldWriterStates; } - for (auto & entry : *_resultConfig) { + for (auto & result_class : *_resultConfig) { - if (entry.GetIndexFromEnumValue(fieldEnumValue) >= 0) { - ResultClass::DynamicInfo *info = entry.getDynamicInfo(); + if (result_class.GetIndexFromEnumValue(fieldEnumValue) >= 0) { + ResultClass::DynamicInfo *info = result_class.getDynamicInfo(); info->_overrideCnt++; if (writer->IsGenerated()) info->_generateCnt++; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/dynamicteaserdfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/dynamicteaserdfw.cpp index ef1ffded941..57adbcc8163 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/dynamicteaserdfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/dynamicteaserdfw.cpp @@ -332,7 +332,7 @@ JuniperTeaserDFW::Init( const ResConfigEntry *entry = it->GetEntry(it->GetIndexFromEnumValue(_inputFieldEnumValue)); - if (entry != nullptr && + if (entry != nullptr && !entry->_not_present && !IsRuntimeCompatible(entry->_type, RES_STRING) && !IsRuntimeCompatible(entry->_type, RES_DATA)) { @@ -347,7 +347,7 @@ JuniperTeaserDFW::Init( vespalib::stringref DynamicTeaserDFW::getJuniperInput(GeneralResult *gres) { int idx = gres->GetClass()->GetIndexFromEnumValue(_inputFieldEnumValue); - ResEntry *entry = gres->GetEntry(idx); + ResEntry *entry = gres->GetPresentEntry(idx); if (entry != nullptr) { const char *buf; uint32_t buflen; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/general_result.cpp b/searchsummary/src/vespa/searchsummary/docsummary/general_result.cpp index 12391d26ce1..825c3b39c1b 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/general_result.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/general_result.cpp @@ -49,25 +49,17 @@ GeneralResult::~GeneralResult() } ResEntry * -GeneralResult::GetEntry(uint32_t idx) -{ - return (idx < _entrycnt) ? &_entries[idx] : nullptr; -} - -ResEntry * -GeneralResult::GetEntry(const char *name) +GeneralResult::GetPresentEntry(const char *name) { int idx = _resClass->GetIndexFromName(name); - - return (idx >= 0 && (uint32_t)idx < _entrycnt) ? &_entries[idx] : nullptr; + return GetPresentEntry(idx); } - ResEntry * -GeneralResult::GetEntryFromEnumValue(uint32_t value) +GeneralResult::GetPresentEntryFromEnumValue(uint32_t value) { int idx = _resClass->GetIndexFromEnumValue(value); - return (idx >= 0 && (uint32_t)idx < _entrycnt) ? &_entries[idx] : nullptr; + return GetPresentEntry(idx); } std::unique_ptr<document::FieldValue> diff --git a/searchsummary/src/vespa/searchsummary/docsummary/general_result.h b/searchsummary/src/vespa/searchsummary/docsummary/general_result.h index f23d5ff5ea7..cff27a496e3 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/general_result.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/general_result.h @@ -32,9 +32,16 @@ public: ~GeneralResult(); const ResultClass *GetClass() const { return _resClass; } - ResEntry *GetEntry(uint32_t idx); - ResEntry *GetEntry(const char *name); - ResEntry *GetEntryFromEnumValue(uint32_t val); + ResEntry *GetEntry(uint32_t idx) { return (idx < _entrycnt) ? &_entries[idx] : nullptr; } + ResEntry *GetPresentEntry(uint32_t idx) { + if (idx >= _entrycnt) { + return nullptr; + } + ResEntry* entry = &_entries[idx]; + return entry->_not_present ? nullptr : entry; + } + ResEntry *GetPresentEntry(const char *name); + ResEntry *GetPresentEntryFromEnumValue(uint32_t val); std::unique_ptr<document::FieldValue> get_field_value(const vespalib::string& field_name) const; bool unpack(const char *buf, const size_t buflen); diff --git a/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.cpp index fb53ddcc470..c2115201d9b 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.cpp @@ -93,7 +93,7 @@ filter_matching_elements_in_input_field_while_converting_to_slime(const FieldVal bool resolve_input_field_as_slime(GeneralResult& result, int entry_idx, Slime& input_field_as_slime) { - ResEntry* entry = result.GetEntry(entry_idx); + ResEntry* entry = result.GetPresentEntry(entry_idx); if (entry != nullptr) { decode_input_field_to_slime(*entry, input_field_as_slime); return true; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/resultclass.cpp b/searchsummary/src/vespa/searchsummary/docsummary/resultclass.cpp index ed1cd8b542b..65db72efc40 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/resultclass.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/resultclass.cpp @@ -26,11 +26,7 @@ int ResultClass::GetIndexFromName(const char* name) const { NameIdMap::const_iterator found(_nameMap.find(name)); - if (found == _nameMap.end()) { - return -1; - } - int idx = found->second; - return _entries[idx]._not_present ? -1 : idx; + return (found != _nameMap.end()) ? found->second : -1; } bool diff --git a/searchsummary/src/vespa/searchsummary/docsummary/resultclass.h b/searchsummary/src/vespa/searchsummary/docsummary/resultclass.h index 8865e28acc6..d6d247238cd 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/resultclass.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/resultclass.h @@ -238,7 +238,7 @@ public: * GeneralResult::GetEntry(string) method; no need to call it * directly. * - * @return field index or -1 if not found or _not_present is set. + * @return field index or -1 if not found **/ int GetIndexFromName(const char* name) const; @@ -255,15 +255,11 @@ public: * call it directly. NOTE3: You need to call the CreateEnumMap * method before calling this one. * - * @return field index or -1 if not found or _not_present is set. + * @return field index or -1 if not found **/ int GetIndexFromEnumValue(uint32_t value) const { - if (value >= _enumMap.size()) { - return -1; - } - int idx = _enumMap[value]; - return ((idx < 0) || _entries[idx]._not_present) ? -1 : idx; + return (value < _enumMap.size()) ? _enumMap[value] : -1; } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/textextractordfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/textextractordfw.cpp index c85a4fb5788..d12418dc254 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/textextractordfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/textextractordfw.cpp @@ -31,7 +31,7 @@ TextExtractorDFW::insertField(uint32_t, GeneralResult *gres, GetDocsumsState *, vespalib::slime::Inserter &target) { vespalib::string extracted; - ResEntry * entry = gres->GetEntryFromEnumValue(_inputFieldEnum); + ResEntry * entry = gres->GetPresentEntryFromEnumValue(_inputFieldEnum); if (entry != nullptr) { const char * buf = nullptr; uint32_t buflen = 0; |