summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/attribute/attribute_test.cpp30
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attributevector.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attributevector.h7
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attributevector.hpp28
-rw-r--r--searchlib/src/vespa/searchlib/attribute/changevector.h1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/floatbase.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/attribute/floatbase.h1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/integerbase.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/attribute/integerbase.h1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multienumattribute.hpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multivalueattribute.hpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/stringbase.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/attribute/stringbase.h1
13 files changed, 82 insertions, 15 deletions
diff --git a/searchlib/src/tests/attribute/attribute_test.cpp b/searchlib/src/tests/attribute/attribute_test.cpp
index f402f536ae2..4715292f86a 100644
--- a/searchlib/src/tests/attribute/attribute_test.cpp
+++ b/searchlib/src/tests/attribute/attribute_test.cpp
@@ -3,6 +3,7 @@
#include <vespa/document/fieldvalue/intfieldvalue.h>
#include <vespa/document/fieldvalue/stringfieldvalue.h>
#include <vespa/document/update/arithmeticvalueupdate.h>
+#include <vespa/document/update/assignvalueupdate.h>
#include <vespa/document/update/mapvalueupdate.h>
#include <vespa/fastlib/io/bufferedfile.h>
#include <vespa/searchlib/attribute/attribute.h>
@@ -1493,20 +1494,21 @@ AttributeTest::testMapValueUpdate(const AttributePtr & ptr, BufferType initValue
typedef ArithmeticValueUpdate ArithVU;
auto & vec = static_cast<VectorType &>(*ptr.get());
- addDocs(ptr, 6);
- for (uint32_t doc = 0; doc < 6; ++doc) {
+ addDocs(ptr, 7);
+ for (uint32_t doc = 0; doc < 7; ++doc) {
ASSERT_TRUE(vec.append(doc, initValue.getValue(), 100));
}
- EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 6u);
+ EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 7u);
EXPECT_EQUAL(ptr->getStatus().getNonIdempotentUpdateCount(), 0u);
EXPECT_TRUE(ptr->apply(0, MapVU(initFieldValue, ArithVU(ArithVU::Add, 10))));
EXPECT_TRUE(ptr->apply(1, MapVU(initFieldValue, ArithVU(ArithVU::Sub, 10))));
EXPECT_TRUE(ptr->apply(2, MapVU(initFieldValue, ArithVU(ArithVU::Mul, 10))));
EXPECT_TRUE(ptr->apply(3, MapVU(initFieldValue, ArithVU(ArithVU::Div, 10))));
+ EXPECT_TRUE(ptr->apply(6, MapVU(initFieldValue, AssignValueUpdate(IntFieldValue(70)))));
ptr->commit();
- EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 10u);
- EXPECT_EQUAL(ptr->getStatus().getNonIdempotentUpdateCount(), 4u);
+ EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 12u);
+ EXPECT_EQUAL(ptr->getStatus().getNonIdempotentUpdateCount(), 5u);
std::vector<BufferType> buf(2);
ptr->get(0, &buf[0], 2);
@@ -1517,6 +1519,8 @@ AttributeTest::testMapValueUpdate(const AttributePtr & ptr, BufferType initValue
EXPECT_EQUAL(buf[0].getWeight(), 1000);
ptr->get(3, &buf[0], 2);
EXPECT_EQUAL(buf[0].getWeight(), 10);
+ ptr->get(6, &buf[0], 2);
+ EXPECT_EQUAL(buf[0].getWeight(), 70);
// removeifzero
EXPECT_TRUE(ptr->apply(4, MapVU(initFieldValue, ArithVU(ArithVU::Sub, 100))));
@@ -1527,8 +1531,8 @@ AttributeTest::testMapValueUpdate(const AttributePtr & ptr, BufferType initValue
EXPECT_EQUAL(ptr->get(4, &buf[0], 2), uint32_t(1));
EXPECT_EQUAL(buf[0].getWeight(), 0);
}
- EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 11u);
- EXPECT_EQUAL(ptr->getStatus().getNonIdempotentUpdateCount(), 5u);
+ EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 13u);
+ EXPECT_EQUAL(ptr->getStatus().getNonIdempotentUpdateCount(), 6u);
// createifnonexistant
EXPECT_TRUE(ptr->apply(5, MapVU(nonExistant, ArithVU(ArithVU::Add, 10))));
@@ -1542,18 +1546,18 @@ AttributeTest::testMapValueUpdate(const AttributePtr & ptr, BufferType initValue
EXPECT_EQUAL(ptr->get(5, &buf[0], 2), uint32_t(1));
EXPECT_EQUAL(buf[0].getWeight(), 100);
}
- EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 12u);
- EXPECT_EQUAL(ptr->getStatus().getNonIdempotentUpdateCount(), 6u);
+ EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 14u);
+ EXPECT_EQUAL(ptr->getStatus().getNonIdempotentUpdateCount(), 7u);
// try divide by zero (should be ignored)
vec.clearDoc(0);
- EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 13u);
+ EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 15u);
ASSERT_TRUE(vec.append(0, initValue.getValue(), 12345));
- EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 14u);
+ EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 16u);
EXPECT_TRUE(ptr->apply(0, MapVU(initFieldValue, ArithVU(ArithVU::Div, 0))));
- EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 14u);
- EXPECT_EQUAL(ptr->getStatus().getNonIdempotentUpdateCount(), 6u);
+ EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 16u);
+ EXPECT_EQUAL(ptr->getStatus().getNonIdempotentUpdateCount(), 7u);
ptr->commit();
ptr->get(0, &buf[0], 1);
EXPECT_EQUAL(buf[0].getWeight(), 12345);
diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.cpp b/searchlib/src/vespa/searchlib/attribute/attributevector.cpp
index 1f002ce612c..08c7186e8c7 100644
--- a/searchlib/src/vespa/searchlib/attribute/attributevector.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/attributevector.cpp
@@ -11,6 +11,7 @@
#include "ipostinglistattributebase.h"
#include "ipostinglistsearchcontext.h"
#include "stringbase.h"
+#include <vespa/document/update/assignvalueupdate.h>
#include <vespa/document/update/mapvalueupdate.h>
#include <vespa/fastlib/io/bufferedfile.h>
#include <vespa/searchlib/common/tunefileinfo.h>
@@ -28,6 +29,7 @@ LOG_SETUP(".searchlib.attribute.attributevector");
using vespalib::getLastErrorString;
using document::ValueUpdate;
+using document::AssignValueUpdate;
using vespalib::make_string;
using vespalib::Array;
using vespalib::IllegalStateException;
@@ -467,6 +469,9 @@ AttributeVector::apply(DocId doc, const MapValueUpdate &map) {
if (vu.inherits(ArithmeticValueUpdate::classId)) {
const ArithmeticValueUpdate &au(static_cast<const ArithmeticValueUpdate &>(vu));
retval = applyWeight(doc, map.getKey(), au);
+ } else if (vu.inherits(AssignValueUpdate::classId)) {
+ const AssignValueUpdate &au(static_cast<const AssignValueUpdate &>(vu));
+ retval = applyWeight(doc, map.getKey(), au);
} else {
retval = false;
}
@@ -477,6 +482,7 @@ AttributeVector::apply(DocId doc, const MapValueUpdate &map) {
bool AttributeVector::applyWeight(DocId, const FieldValue &, const ArithmeticValueUpdate &) { return false; }
+bool AttributeVector::applyWeight(DocId, const FieldValue&, const AssignValueUpdate&) { return false; }
void
AttributeVector::removeAllOldGenerations() {
diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.h b/searchlib/src/vespa/searchlib/attribute/attributevector.h
index 4a53f2dd5a2..75699868691 100644
--- a/searchlib/src/vespa/searchlib/attribute/attributevector.h
+++ b/searchlib/src/vespa/searchlib/attribute/attributevector.h
@@ -30,6 +30,7 @@ class FastOS_FileInterface;
namespace document {
class ArithmeticValueUpdate;
+ class AssignValueUpdate;
class MapValueUpdate;
class FieldValue;
}
@@ -332,6 +333,9 @@ protected:
template<typename T>
bool adjustWeight(ChangeVectorT< ChangeTemplate<T> > &changes, DocId doc, const T &v, const ArithmeticValueUpdate &wd);
+ template<typename T>
+ bool adjustWeight(ChangeVectorT< ChangeTemplate<T> > &changes, DocId doc, const T &v, const document::AssignValueUpdate &wu);
+
template <typename T>
static int32_t
applyWeightChange(int32_t weight, const ChangeTemplate<T> &weightChange) {
@@ -341,6 +345,8 @@ protected:
return weight * weightChange._weight;
} else if (weightChange._type == ChangeBase::DIVWEIGHT) {
return weight / weightChange._weight;
+ } else if (weightChange._type == ChangeBase::SETWEIGHT) {
+ return weightChange._weight;
}
return weight;
}
@@ -561,6 +567,7 @@ private:
virtual void onAddDocs(DocId docIdLimit) = 0;
void divideByZeroWarning();
virtual bool applyWeight(DocId doc, const FieldValue &fv, const ArithmeticValueUpdate &wAdjust);
+ virtual bool applyWeight(DocId doc, const FieldValue& fv, const document::AssignValueUpdate& wAdjust);
virtual void onSave(IAttributeSaveTarget & saveTarget);
virtual bool onLoad();
diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.hpp b/searchlib/src/vespa/searchlib/attribute/attributevector.hpp
index 66c2678497a..efc96bc57c2 100644
--- a/searchlib/src/vespa/searchlib/attribute/attributevector.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/attributevector.hpp
@@ -3,7 +3,9 @@
#include "attributevector.h"
#include "integerbase.h"
+#include <vespa/document/fieldvalue/intfieldvalue.h>
#include <vespa/document/update/arithmeticvalueupdate.h>
+#include <vespa/document/update/assignvalueupdate.h>
#include <cmath>
namespace search {
@@ -61,6 +63,32 @@ AttributeVector::adjustWeight(ChangeVectorT< ChangeTemplate<T> > & changes, DocI
template<typename T>
bool
+AttributeVector::adjustWeight(ChangeVectorT< ChangeTemplate<T> >& changes, DocId doc, const T& v, const document::AssignValueUpdate& wu)
+{
+ bool retval(hasWeightedSetType() && (doc < getNumDocs()));
+ if (retval) {
+ size_t oldSz(changes.size());
+ if (wu.hasValue()) {
+ const FieldValue &wv = wu.getValue();
+ if (wv.inherits(document::IntFieldValue::classId)) {
+ changes.push_back(ChangeTemplate<T>(ChangeBase::SETWEIGHT, doc, v, wv.getAsInt()));
+ } else {
+ retval = false;
+ }
+ } else {
+ retval = false;
+ }
+ if (retval) {
+ const size_t diff = changes.size() - oldSz;
+ _status.incNonIdempotentUpdates(diff);
+ _status.incUpdates(diff);
+ }
+ }
+ return retval;
+}
+
+template<typename T>
+bool
AttributeVector::applyArithmetic(ChangeVectorT< ChangeTemplate<T> > & changes, DocId doc, const T & v,
const ArithmeticValueUpdate & arithm)
{
diff --git a/searchlib/src/vespa/searchlib/attribute/changevector.h b/searchlib/src/vespa/searchlib/attribute/changevector.h
index 75eac911f6c..af4a4fd6618 100644
--- a/searchlib/src/vespa/searchlib/attribute/changevector.h
+++ b/searchlib/src/vespa/searchlib/attribute/changevector.h
@@ -18,6 +18,7 @@ struct ChangeBase {
INCREASEWEIGHT,
MULWEIGHT,
DIVWEIGHT,
+ SETWEIGHT,
ADD,
SUB,
MUL,
diff --git a/searchlib/src/vespa/searchlib/attribute/floatbase.cpp b/searchlib/src/vespa/searchlib/attribute/floatbase.cpp
index 813180bc5d7..4ffc6e333b6 100644
--- a/searchlib/src/vespa/searchlib/attribute/floatbase.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/floatbase.cpp
@@ -76,6 +76,12 @@ bool FloatingPointAttribute::applyWeight(DocId doc, const FieldValue & fv, const
return AttributeVector::adjustWeight(_changes, doc, NumericChangeData<double>(v), wAdjust);
}
+bool FloatingPointAttribute::applyWeight(DocId doc, const FieldValue& fv, const document::AssignValueUpdate& wAdjust)
+{
+ double v = fv.getAsDouble();
+ return AttributeVector::adjustWeight(_changes, doc, NumericChangeData<double>(v), wAdjust);
+}
+
bool FloatingPointAttribute::apply(DocId doc, const ArithmeticValueUpdate & op)
{
bool retval(doc < getNumDocs());
diff --git a/searchlib/src/vespa/searchlib/attribute/floatbase.h b/searchlib/src/vespa/searchlib/attribute/floatbase.h
index ce8d22c2706..65a146d7ba7 100644
--- a/searchlib/src/vespa/searchlib/attribute/floatbase.h
+++ b/searchlib/src/vespa/searchlib/attribute/floatbase.h
@@ -28,6 +28,7 @@ public:
}
bool apply(DocId doc, const ArithmeticValueUpdate & op);
bool applyWeight(DocId doc, const FieldValue & fv, const ArithmeticValueUpdate & wAdjust) override;
+ bool applyWeight(DocId doc, const FieldValue& fv, const document::AssignValueUpdate& wAdjust) override;
uint32_t clearDoc(DocId doc) override;
protected:
const char * getString(DocId doc, char * s, size_t sz) const override;
diff --git a/searchlib/src/vespa/searchlib/attribute/integerbase.cpp b/searchlib/src/vespa/searchlib/attribute/integerbase.cpp
index f065bc63648..a150b5e1699 100644
--- a/searchlib/src/vespa/searchlib/attribute/integerbase.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/integerbase.cpp
@@ -80,6 +80,12 @@ bool IntegerAttribute::applyWeight(DocId doc, const FieldValue & fv, const Arith
return AttributeVector::adjustWeight(_changes, doc, NumericChangeData<largeint_t>(v), wAdjust);
}
+bool IntegerAttribute::applyWeight(DocId doc, const FieldValue& fv, const document::AssignValueUpdate& wAdjust)
+{
+ largeint_t v = fv.getAsLong();
+ return AttributeVector::adjustWeight(_changes, doc, NumericChangeData<largeint_t>(v), wAdjust);
+}
+
bool IntegerAttribute::apply(DocId doc, const ArithmeticValueUpdate & op)
{
bool retval(doc < getNumDocs());
diff --git a/searchlib/src/vespa/searchlib/attribute/integerbase.h b/searchlib/src/vespa/searchlib/attribute/integerbase.h
index 46774f9cebf..4e5fe8fec19 100644
--- a/searchlib/src/vespa/searchlib/attribute/integerbase.h
+++ b/searchlib/src/vespa/searchlib/attribute/integerbase.h
@@ -28,6 +28,7 @@ public:
}
bool apply(DocId doc, const ArithmeticValueUpdate & op);
bool applyWeight(DocId doc, const FieldValue & fv, const ArithmeticValueUpdate & wAdjust) override;
+ bool applyWeight(DocId doc, const FieldValue& fv, const document::AssignValueUpdate& wAdjust) override;
uint32_t clearDoc(DocId doc) override;
protected:
IntegerAttribute(const vespalib::string & name, const Config & c);
diff --git a/searchlib/src/vespa/searchlib/attribute/multienumattribute.hpp b/searchlib/src/vespa/searchlib/attribute/multienumattribute.hpp
index 219b3dd2473..40f211c2621 100644
--- a/searchlib/src/vespa/searchlib/attribute/multienumattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/multienumattribute.hpp
@@ -37,7 +37,7 @@ MultiValueEnumAttribute<B, M>::considerAttributeChange(const Change & c, UniqueS
{
if (c._type == ChangeBase::APPEND ||
(this->getInternalCollectionType().createIfNonExistant() &&
- (c._type >= ChangeBase::INCREASEWEIGHT && c._type <= ChangeBase::DIVWEIGHT)))
+ (c._type >= ChangeBase::INCREASEWEIGHT && c._type <= ChangeBase::SETWEIGHT)))
{
EnumIndex idx;
if (!this->_enumStore.find_index(c._data.raw(), idx)) {
diff --git a/searchlib/src/vespa/searchlib/attribute/multivalueattribute.hpp b/searchlib/src/vespa/searchlib/attribute/multivalueattribute.hpp
index b23860ebd31..0ae536aee23 100644
--- a/searchlib/src/vespa/searchlib/attribute/multivalueattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/multivalueattribute.hpp
@@ -172,7 +172,7 @@ MultiValueAttribute<B, M>::apply_attribute_changes_to_wset(DocumentValues& docVa
wset_inserted[data] = current->_weight;
} else if (current->_type == ChangeBase::REMOVE) {
wset_inserted.erase(data);
- } else if ((current->_type >= ChangeBase::INCREASEWEIGHT) && (current->_type <= ChangeBase::DIVWEIGHT)) {
+ } else if ((current->_type >= ChangeBase::INCREASEWEIGHT) && (current->_type <= ChangeBase::SETWEIGHT)) {
auto existing = wset_inserted.find(data);
if (existing != wset_inserted.end()) {
existing->second = this->applyWeightChange(existing->second, *current);
diff --git a/searchlib/src/vespa/searchlib/attribute/stringbase.cpp b/searchlib/src/vespa/searchlib/attribute/stringbase.cpp
index 40e706e924d..d888ead21bf 100644
--- a/searchlib/src/vespa/searchlib/attribute/stringbase.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/stringbase.cpp
@@ -309,6 +309,12 @@ bool StringAttribute::applyWeight(DocId doc, const FieldValue & fv, const Arithm
return AttributeVector::adjustWeight(_changes, doc, StringChangeData(v), wAdjust);
}
+bool StringAttribute::applyWeight(DocId doc, const FieldValue& fv, const document::AssignValueUpdate& wAdjust)
+{
+ vespalib::string v = fv.getAsString();
+ return AttributeVector::adjustWeight(_changes, doc, StringChangeData(v), wAdjust);
+}
+
bool StringAttribute::apply(DocId, const ArithmeticValueUpdate & )
{
return false;
diff --git a/searchlib/src/vespa/searchlib/attribute/stringbase.h b/searchlib/src/vespa/searchlib/attribute/stringbase.h
index 3518544cbdc..e6238cc0f94 100644
--- a/searchlib/src/vespa/searchlib/attribute/stringbase.h
+++ b/searchlib/src/vespa/searchlib/attribute/stringbase.h
@@ -44,6 +44,7 @@ public:
}
bool apply(DocId doc, const ArithmeticValueUpdate & op);
bool applyWeight(DocId doc, const FieldValue & fv, const ArithmeticValueUpdate & wAdjust) override;
+ bool applyWeight(DocId doc, const FieldValue& fv, const document::AssignValueUpdate& wAdjust) override;
bool findEnum(const char * value, EnumHandle & e) const override = 0;
std::vector<EnumHandle> findFoldedEnums(const char *value) const override = 0;
uint32_t get(DocId doc, largeint_t * v, uint32_t sz) const override;