// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "extendableattributes.hpp" #include "extendable_numeric_array_multi_value_read_view.h" #include "extendable_numeric_weighted_set_multi_value_read_view.h" #include "extendable_string_array_multi_value_read_view.h" #include "extendable_string_weighted_set_multi_value_read_view.h" #include #include #include LOG_SETUP(".searchlib.attribute.extendable_attributes"); namespace search { //******************** CollectionType::SINGLE ********************// SingleStringExtAttribute::SingleStringExtAttribute(const vespalib::string & name) : StringDirectAttrVector< AttrVector::Features >(name, Config(BasicType::STRING, CollectionType::SINGLE)) { setEnum(false); } bool SingleStringExtAttribute::addDoc(DocId & docId) { size_t offset(_buffer.size()); _buffer.push_back('\0'); _buffer.push_back(0); docId = _offsets.size(); _offsets.push_back(offset); incNumDocs(); setCommittedDocIdLimit(getNumDocs()); return true; } bool SingleStringExtAttribute::add(const char * v, int32_t) { const size_t start(_offsets.back()); const size_t sz(strlen(v) + 1); _buffer.resize(start+sz); strcpy(&_buffer[start], v); return true; } //******************** CollectionType::ARRAY ********************// template const attribute::IMultiValueAttribute* MultiExtAttribute::as_multi_value_attribute() const { return this; } template const attribute::IArrayReadView* MultiExtAttribute::make_read_view(attribute::IMultiValueAttribute::ArrayTag, vespalib::Stash& stash) const { return &stash.create>(this->_data, this->_idx); } template const attribute::IWeightedSetReadView* MultiExtAttribute::make_read_view(attribute::IMultiValueAttribute::WeightedSetTag, vespalib::Stash& stash) const { return &stash.create, T>>(this->_data, this->_idx); } MultiStringExtAttribute::MultiStringExtAttribute(const vespalib::string & name, const CollectionType & ctype) : StringDirectAttrVector< AttrVector::Features > (name, Config(BasicType::STRING, ctype)) { setEnum(false); } MultiStringExtAttribute::MultiStringExtAttribute(const vespalib::string & name) : StringDirectAttrVector< AttrVector::Features > (name, Config(BasicType::STRING, CollectionType::ARRAY)) { setEnum(false); } bool MultiStringExtAttribute::addDoc(DocId & docId) { docId = _idx.size() - 1; _idx.push_back(_idx.back()); incNumDocs(); setCommittedDocIdLimit(getNumDocs()); return true; } bool MultiStringExtAttribute::add(const char * v, int32_t) { const size_t start(_buffer.size()); const size_t sz(strlen(v) + 1); _buffer.resize(start+sz); strcpy(&_buffer[start], v); _offsets.push_back(start); _idx.back()++; checkSetMaxValueCount(_idx.back() - _idx[_idx.size() - 2]); return true; } const attribute::IMultiValueAttribute* MultiStringExtAttribute::as_multi_value_attribute() const { return this; } const attribute::IArrayReadView* MultiStringExtAttribute::make_read_view(attribute::IMultiValueAttribute::ArrayTag, vespalib::Stash& stash) const { return &stash.create>(this->_buffer, this->_offsets, this->_idx); } const attribute::IWeightedSetReadView* MultiStringExtAttribute::make_read_view(attribute::IMultiValueAttribute::WeightedSetTag, vespalib::Stash& stash) const { return &stash.create>>(this->_buffer, this->_offsets, this->_idx); } //******************** CollectionType::WSET ********************// WeightedSetIntegerExtAttribute::WeightedSetIntegerExtAttribute(const vespalib::string & name) : WeightedSetExtAttributeBase(name) { } WeightedSetIntegerExtAttribute::~WeightedSetIntegerExtAttribute() = default; std::unique_ptr WeightedSetIntegerExtAttribute::getSearch(QueryTermSimpleUP term, const attribute::SearchContextParams & params) const { (void) term; (void) params; return {}; } bool WeightedSetIntegerExtAttribute::add(int64_t v, int32_t w) { addWeight(w); MultiIntegerExtAttribute::add(v); return true; } uint32_t WeightedSetIntegerExtAttribute::get(DocId doc, AttributeVector::WeightedInt * v, uint32_t sz) const { uint32_t valueCount = _idx[doc + 1] - _idx[doc]; uint32_t num2Read = std::min(valueCount, sz); for (uint32_t i = 0; i < num2Read; ++i) { v[i] = AttributeVector::WeightedInt(_data[_idx[doc] + i], getWeightHelper(doc, i)); } return valueCount; } const attribute::IWeightedSetReadView* WeightedSetIntegerExtAttribute::make_read_view(attribute::IMultiValueAttribute::WeightedSetTag, vespalib::Stash& stash) const { return &stash.create, int64_t>>(this->_data, this->_idx, this->get_weights()); } WeightedSetFloatExtAttribute::WeightedSetFloatExtAttribute(const vespalib::string & name) : WeightedSetExtAttributeBase(name) { } WeightedSetFloatExtAttribute::~WeightedSetFloatExtAttribute() = default; std::unique_ptr WeightedSetFloatExtAttribute::getSearch(QueryTermSimpleUP term, const attribute::SearchContextParams & params) const { (void) term; (void) params; return {}; } bool WeightedSetFloatExtAttribute::add(double v, int32_t w) { addWeight(w); MultiFloatExtAttribute::add(v); return true; } uint32_t WeightedSetFloatExtAttribute::get(DocId doc, AttributeVector::WeightedFloat * v, uint32_t sz) const { uint32_t valueCount = _idx[doc + 1] - _idx[doc]; uint32_t num2Read = std::min(valueCount, sz); for (uint32_t i = 0; i < num2Read; ++i) { v[i] = AttributeVector::WeightedFloat(_data[_idx[doc] + i], getWeightHelper(doc, i)); } return valueCount; } const attribute::IWeightedSetReadView* WeightedSetFloatExtAttribute::make_read_view(attribute::IMultiValueAttribute::WeightedSetTag, vespalib::Stash& stash) const { return &stash.create, double>>(this->_data, this->_idx, this->get_weights()); } WeightedSetStringExtAttribute::WeightedSetStringExtAttribute(const vespalib::string & name) : WeightedSetExtAttributeBase(name) { setEnum(false); } WeightedSetStringExtAttribute::~WeightedSetStringExtAttribute() {} bool WeightedSetStringExtAttribute::add(const char * v, int32_t w) { addWeight(w); MultiStringExtAttribute::add(v); return true; } uint32_t WeightedSetStringExtAttribute::get(DocId doc, AttributeVector::WeightedString * v, uint32_t sz) const { return getAllHelper(doc, v, sz); } uint32_t WeightedSetStringExtAttribute::get(DocId doc, AttributeVector::WeightedConstChar * v, uint32_t sz) const { return getAllHelper(doc, v, sz); } const attribute::IWeightedSetReadView* WeightedSetStringExtAttribute::make_read_view(attribute::IMultiValueAttribute::WeightedSetTag, vespalib::Stash& stash) const { return &stash.create>>(this->_buffer, this->_offsets, this->_idx, this->get_weights()); } template class MultiExtAttribute; template class MultiExtAttribute; template class MultiExtAttribute; template class MultiExtAttribute; template class MultiExtAttribute; template class SingleExtAttribute; template class SingleExtAttribute; template class SingleExtAttribute; template class SingleExtAttribute; template class SingleExtAttribute; }