summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-03-31 13:30:59 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-03-31 13:30:59 +0000
commitff6614989b542169bcb76e97bfe7aa80ab0928c9 (patch)
treef0d3ef6b0033ff3a0a6db9e06045e495b0535a06 /searchlib
parent4b64c06dfa47bf0d4130dfb2167ccece19419efe (diff)
Downgrade to string in case of trouble.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/query/querybuilder_test.cpp3
-rw-r--r--searchlib/src/vespa/searchlib/query/tree/termnodes.cpp17
-rw-r--r--searchlib/src/vespa/searchlib/query/tree/termnodes.h2
3 files changed, 21 insertions, 1 deletions
diff --git a/searchlib/src/tests/query/querybuilder_test.cpp b/searchlib/src/tests/query/querybuilder_test.cpp
index 47dccc76603..06098afe3eb 100644
--- a/searchlib/src/tests/query/querybuilder_test.cpp
+++ b/searchlib/src/tests/query/querybuilder_test.cpp
@@ -704,12 +704,13 @@ TEST("first string then integer MultiTerm") {
TEST("first integer then string MultiTerm") {
SimpleMultiTerm mt(7);
mt.addTerm(-3, Weight(-4));
+ EXPECT_TRUE(MultiTerm::Type::INTEGER == mt.getType());
for (int64_t i(1); i < mt.getNumTerms(); i++) {
char buf[24];
auto res = std::to_chars(buf, buf + sizeof(buf), i-3);
mt.addTerm(vespalib::stringref(buf, res.ptr - buf), Weight(i-4));
}
- EXPECT_TRUE(MultiTerm::Type::INTEGER == mt.getType());
+ EXPECT_TRUE(MultiTerm::Type::STRING == mt.getType());
verify_multiterm_get(mt);
}
diff --git a/searchlib/src/vespa/searchlib/query/tree/termnodes.cpp b/searchlib/src/vespa/searchlib/query/tree/termnodes.cpp
index 4caf3c2ff89..c5216f26faa 100644
--- a/searchlib/src/vespa/searchlib/query/tree/termnodes.cpp
+++ b/searchlib/src/vespa/searchlib/query/tree/termnodes.cpp
@@ -51,6 +51,7 @@ public:
Weight getWeight(uint32_t index) const override {
return _terms[index].second;
}
+ uint32_t size() const override { return _terms.size(); }
private:
std::vector<std::pair<vespalib::string, Weight>> _terms;
};
@@ -78,6 +79,7 @@ public:
Weight getWeight(uint32_t index) const override {
return _terms[index].second;
}
+ uint32_t size() const override { return _terms.size(); }
private:
std::vector<IntegerAndWeight> _terms;
mutable char _scratchPad[24];
@@ -93,12 +95,27 @@ MultiTerm::MultiTerm(uint32_t num_terms)
MultiTerm::~MultiTerm() = default;
+std::unique_ptr<MultiTerm::TermVector>
+MultiTerm::downgrade() {
+ // Downgrade all number to string. This should really not happen
+ auto new_terms = std::make_unique<StringTermVector>(_num_terms);
+ for (uint32_t i(0), m(_terms->size()); i < m; i++) {
+ auto v = _terms->getAsString(i);
+ new_terms->addTerm(v.first, v.second);
+ }
+ return new_terms;
+}
+
void
MultiTerm::addTerm(vespalib::stringref term, Weight weight) {
if ( ! _terms) {
_terms = std::make_unique<StringTermVector>(_num_terms);
_type = Type::STRING;
}
+ if (_type == Type::INTEGER) {
+ _terms = downgrade();
+ _type = Type::STRING;
+ }
_terms->addTerm(term, weight);
}
diff --git a/searchlib/src/vespa/searchlib/query/tree/termnodes.h b/searchlib/src/vespa/searchlib/query/tree/termnodes.h
index 8fbaacdd20d..0373ebbb653 100644
--- a/searchlib/src/vespa/searchlib/query/tree/termnodes.h
+++ b/searchlib/src/vespa/searchlib/query/tree/termnodes.h
@@ -167,6 +167,7 @@ public:
virtual StringAndWeight getAsString(uint32_t index) const = 0;
virtual IntegerAndWeight getAsInteger(uint32_t index) const = 0;
virtual Weight getWeight(uint32_t index) const = 0;
+ virtual uint32_t size() const = 0;
};
~MultiTerm() override;
void addTerm(vespalib::stringref term, Weight weight);
@@ -181,6 +182,7 @@ public:
protected:
MultiTerm(uint32_t num_terms);
private:
+ VESPA_DLL_LOCAL std::unique_ptr<TermVector> downgrade() __attribute__((noinline));
std::unique_ptr<TermVector> _terms;
uint32_t _num_terms;
Type _type;