aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeir Storli <geirstorli@yahoo.no>2019-01-14 16:03:48 +0100
committerGitHub <noreply@github.com>2019-01-14 16:03:48 +0100
commit9d87962862867e67928363a3c6f0d64223228788 (patch)
tree9a4007473345adc8c2b7a58c8aebe45f3bc90dc2
parent3d0321eca4f93717e4afda679ca735b0b3535ce2 (diff)
parent923ee0d7b31034110c22d98c3cee28deec61e72e (diff)
Merge pull request #8134 from vespa-engine/balder/vsm-search-bool-too
Balder/vsm search bool too
-rw-r--r--document/src/vespa/document/fieldvalue/boolfieldvalue.h2
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.cpp2
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.h2
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/attributedfw.h2
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.h4
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.h2
-rw-r--r--vsm/src/tests/searcher/searcher.cpp26
-rw-r--r--vsm/src/vespa/vsm/searcher/CMakeLists.txt1
-rw-r--r--vsm/src/vespa/vsm/searcher/boolfieldsearcher.cpp52
-rw-r--r--vsm/src/vespa/vsm/searcher/boolfieldsearcher.h21
-rw-r--r--vsm/src/vespa/vsm/searcher/intfieldsearcher.cpp2
-rw-r--r--vsm/src/vespa/vsm/searcher/intfieldsearcher.h1
-rw-r--r--vsm/src/vespa/vsm/vsm/fieldsearchspec.cpp4
13 files changed, 110 insertions, 11 deletions
diff --git a/document/src/vespa/document/fieldvalue/boolfieldvalue.h b/document/src/vespa/document/fieldvalue/boolfieldvalue.h
index 689bd3f4d53..7d3b30787e9 100644
--- a/document/src/vespa/document/fieldvalue/boolfieldvalue.h
+++ b/document/src/vespa/document/fieldvalue/boolfieldvalue.h
@@ -7,7 +7,7 @@
namespace document {
/**
- * Represent the value in a filed of type 'bool' which can be either true or false.
+ * Represent the value in a field of type 'bool' which can be either true or false.
**/
class BoolFieldValue : public FieldValue {
bool _value;
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.cpp
index 153bcea886f..ef621dc5b4a 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.cpp
+++ b/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.cpp
@@ -90,7 +90,7 @@ StructFields::~StructFields() = default;
}
AttributeCombinerDFW::AttributeCombinerDFW(const vespalib::string &fieldName)
- : IDocsumFW(),
+ : ISimpleDFW(),
_stateIndex(0),
_fieldName(fieldName)
{
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.h b/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.h
index e58b0f740bf..6c0991fdf92 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.h
+++ b/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.h
@@ -15,7 +15,7 @@ class DynamicDocsumWriter;
* This class reads values from multiple struct field attributes and
* inserts them as an array of struct or a map of struct.
*/
-class AttributeCombinerDFW : public IDocsumFW
+class AttributeCombinerDFW : public ISimpleDFW
{
protected:
uint32_t _stateIndex;
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.h b/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.h
index d8102734452..211becea16c 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.h
+++ b/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.h
@@ -8,7 +8,7 @@ namespace search::attribute { class IAttributeVector; }
namespace search::docsummary {
-class AttrDFW : public IDocsumFW
+class AttrDFW : public ISimpleDFW
{
private:
vespalib::string _attrName;
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.h b/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.h
index 870e4fa8d83..1a904d4f858 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.h
+++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.h
@@ -43,7 +43,7 @@ private:
static const vespalib::string _empty;
};
-class IDocsumFW : public IDocsumFieldWriter
+class ISimpleDFW : public IDocsumFieldWriter
{
public:
virtual void insertField(uint32_t docid, GetDocsumsState *state, ResType type, vespalib::slime::Inserter &target) = 0;
@@ -56,7 +56,7 @@ public:
//--------------------------------------------------------------------------
-class EmptyDFW : public IDocsumFW
+class EmptyDFW : public ISimpleDFW
{
public:
EmptyDFW();
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.h b/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.h
index f1452d4c0a9..26eba78772c 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.h
+++ b/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.h
@@ -10,7 +10,7 @@ namespace search::docsummary {
class IDocsumEnvironment;
-class FeaturesDFW : public IDocsumFW
+class FeaturesDFW : public ISimpleDFW
{
protected:
void featureDump(vespalib::JSONStringer & json, vespalib::stringref name, double feature);
diff --git a/vsm/src/tests/searcher/searcher.cpp b/vsm/src/tests/searcher/searcher.cpp
index a83c4e6b348..f5f7508a256 100644
--- a/vsm/src/tests/searcher/searcher.cpp
+++ b/vsm/src/tests/searcher/searcher.cpp
@@ -6,6 +6,7 @@
#include <vespa/vsm/searcher/floatfieldsearcher.h>
#include <vespa/vsm/searcher/futf8strchrfieldsearcher.h>
#include <vespa/vsm/searcher/intfieldsearcher.h>
+#include <vespa/vsm/searcher/boolfieldsearcher.h>
#include <vespa/vsm/searcher/utf8flexiblestringfieldsearcher.h>
#include <vespa/vsm/searcher/utf8exactstringfieldsearcher.h>
#include <vespa/vsm/searcher/utf8substringsearcher.h>
@@ -113,7 +114,7 @@ SnippetModifierSetup::SnippetModifierSetup(const StringList & terms)
{
searcher->prepare(query.qtl, buf);
}
-SnippetModifierSetup::~SnippetModifierSetup() {}
+SnippetModifierSetup::~SnippetModifierSetup() = default;
// helper functions
ArrayFieldValue getFieldValue(const StringList &fv);
@@ -153,6 +154,13 @@ void assertInt(IntFieldSearcher & fs, const std::string &term, int64_t field, bo
assertInt(fs, StringList().add(term), field, BoolList().add(exp));
}
+void assertBool(BoolFieldSearcher & fs, const StringList &query, bool field, const BoolList &exp) {
+ assertNumeric(fs, query, BoolFieldValue(field), exp);
+}
+void assertBool(BoolFieldSearcher & fs, const std::string &term, bool field, bool exp) {
+ assertBool(fs, StringList().add(term), field, BoolList().add(exp));
+}
+
void assertInt(IntFieldSearcher & fs, const StringList &query, const LongList &field, const HitsList &exp) {
assertSearch(fs, query, getFieldValue(field), exp);
}
@@ -595,9 +603,23 @@ TEST("utf8 flexible searcher"){
EXPECT_TRUE(testStringFieldInfo(fs));
}
+TEST("bool search") {
+ BoolFieldSearcher fs(0);
+ TEST_DO(assertBool(fs, "true", true, true));
+ TEST_DO(assertBool(fs, "true", false, false));
+ TEST_DO(assertBool(fs, "1", true, true));
+ TEST_DO(assertBool(fs, "1", false, false));
+ TEST_DO(assertBool(fs, "false", true, false));
+ TEST_DO(assertBool(fs, "false", false, true));
+ TEST_DO(assertBool(fs, "0", true, false));
+ TEST_DO(assertBool(fs, "0", false, true));
+ TEST_DO(assertBool(fs, StringList().add("true").add("false").add("true"), true, BoolList().add(true).add(false).add(true)));
+ TEST_DO(assertBool(fs, StringList().add("true").add("false").add("true"), false, BoolList().add(false).add(true).add(false)));
+}
+
TEST("integer search")
{
- IntFieldSearcher fs;
+ IntFieldSearcher fs(0);
TEST_DO(assertInt(fs, "10", 10, true));
TEST_DO(assertInt(fs, "9", 10, false));
TEST_DO(assertInt(fs, ">9", 10, true));
diff --git a/vsm/src/vespa/vsm/searcher/CMakeLists.txt b/vsm/src/vespa/vsm/searcher/CMakeLists.txt
index 205a5abef42..cecdd2c5ca9 100644
--- a/vsm/src/vespa/vsm/searcher/CMakeLists.txt
+++ b/vsm/src/vespa/vsm/searcher/CMakeLists.txt
@@ -1,6 +1,7 @@
# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
vespa_add_library(vsm_vsmsearcher OBJECT
SOURCES
+ boolfieldsearcher.cpp
fieldsearcher.cpp
floatfieldsearcher.cpp
fold.cpp
diff --git a/vsm/src/vespa/vsm/searcher/boolfieldsearcher.cpp b/vsm/src/vespa/vsm/searcher/boolfieldsearcher.cpp
new file mode 100644
index 00000000000..bf40a679bab
--- /dev/null
+++ b/vsm/src/vespa/vsm/searcher/boolfieldsearcher.cpp
@@ -0,0 +1,52 @@
+// Copyright 2019 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include "boolfieldsearcher.h"
+#include <vespa/document/fieldvalue/boolfieldvalue.h>
+
+using search::QueryTerm;
+using search::QueryTermList;
+
+namespace vsm {
+
+namespace {
+vespalib::stringref TRUE = "true";
+vespalib::stringref FALSE = "false";
+}
+
+IMPLEMENT_DUPLICATE(BoolFieldSearcher);
+
+BoolFieldSearcher::BoolFieldSearcher(FieldIdT fId) :
+ FieldSearcher(fId),
+ _terms()
+{ }
+
+BoolFieldSearcher::~BoolFieldSearcher() = default;
+
+void BoolFieldSearcher::prepare(QueryTermList & qtl, const SharedSearcherBuf & buf)
+{
+ _terms.clear();
+ FieldSearcher::prepare(qtl, buf);
+ for (const QueryTerm * qt : qtl) {
+ if (TRUE == qt->getTerm()) {
+ _terms.push_back(true);
+ } else if (FALSE == qt->getTerm()) {
+ _terms.push_back(false);
+ } else {
+ int64_t low;
+ int64_t high;
+ bool valid = qt->getAsIntegerTerm(low, high);
+ _terms.push_back(valid && (low > 0));
+ }
+ }
+}
+
+void BoolFieldSearcher::onValue(const document::FieldValue & fv)
+{
+ for(size_t j=0, jm(_terms.size()); j < jm; j++) {
+ if (static_cast<const document::BoolFieldValue &>(fv).getValue() == _terms[j]) {
+ addHit(*_qtl[j], 0);
+ }
+ }
+ ++_words;
+}
+
+}
diff --git a/vsm/src/vespa/vsm/searcher/boolfieldsearcher.h b/vsm/src/vespa/vsm/searcher/boolfieldsearcher.h
new file mode 100644
index 00000000000..139645bf0ba
--- /dev/null
+++ b/vsm/src/vespa/vsm/searcher/boolfieldsearcher.h
@@ -0,0 +1,21 @@
+// Copyright 2019 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#pragma once
+
+#include "fieldsearcher.h"
+
+namespace vsm {
+
+class BoolFieldSearcher : public FieldSearcher
+{
+public:
+ DUPLICATE(BoolFieldSearcher);
+ BoolFieldSearcher(FieldIdT fId);
+ ~BoolFieldSearcher();
+ void prepare(search::QueryTermList & qtl, const SharedSearcherBuf & buf) override;
+ void onValue(const document::FieldValue & fv) override;
+private:
+ std::vector<bool> _terms;
+};
+
+}
+
diff --git a/vsm/src/vespa/vsm/searcher/intfieldsearcher.cpp b/vsm/src/vespa/vsm/searcher/intfieldsearcher.cpp
index 1f06d37b80f..30d9992e2d4 100644
--- a/vsm/src/vespa/vsm/searcher/intfieldsearcher.cpp
+++ b/vsm/src/vespa/vsm/searcher/intfieldsearcher.cpp
@@ -13,7 +13,7 @@ IntFieldSearcher::IntFieldSearcher(FieldIdT fId) :
_intTerm()
{ }
-IntFieldSearcher::~IntFieldSearcher() {}
+IntFieldSearcher::~IntFieldSearcher() = default;
void IntFieldSearcher::prepare(QueryTermList & qtl, const SharedSearcherBuf & buf)
{
diff --git a/vsm/src/vespa/vsm/searcher/intfieldsearcher.h b/vsm/src/vespa/vsm/searcher/intfieldsearcher.h
index 67c235f6577..3e158b2d93c 100644
--- a/vsm/src/vespa/vsm/searcher/intfieldsearcher.h
+++ b/vsm/src/vespa/vsm/searcher/intfieldsearcher.h
@@ -20,7 +20,6 @@ protected:
IntInfo(int64_t low, int64_t high, bool v) : _lower(low), _upper(high), _valid(v) { if (low > high) { _lower = high; _upper = low; } }
bool cmp(int64_t key) const { return (_lower <= key) && (key <= _upper); }
bool valid() const { return _valid; }
- void setValid(bool v) { _valid = v; }
private:
int64_t _lower;
int64_t _upper;
diff --git a/vsm/src/vespa/vsm/vsm/fieldsearchspec.cpp b/vsm/src/vespa/vsm/vsm/fieldsearchspec.cpp
index b21177a6810..351c2d1da0d 100644
--- a/vsm/src/vespa/vsm/vsm/fieldsearchspec.cpp
+++ b/vsm/src/vespa/vsm/vsm/fieldsearchspec.cpp
@@ -8,6 +8,7 @@
#include <vespa/vsm/searcher/utf8exactstringfieldsearcher.h>
#include <vespa/vsm/searcher/futf8strchrfieldsearcher.h>
#include <vespa/vsm/searcher/intfieldsearcher.h>
+#include <vespa/vsm/searcher/boolfieldsearcher.h>
#include <vespa/vsm/searcher/floatfieldsearcher.h>
#include <vespa/vespalib/util/regexp.h>
@@ -84,6 +85,9 @@ FieldSearchSpec::FieldSearchSpec(const FieldIdT & fid, const vespalib::string &
_searcher = FUTF8StrChrFieldSearcher(fid);
}
break;
+ case VsmfieldsConfig::Fieldspec::BOOL:
+ _searcher = BoolFieldSearcher(fid);
+ break;
case VsmfieldsConfig::Fieldspec::INT8:
case VsmfieldsConfig::Fieldspec::INT16:
case VsmfieldsConfig::Fieldspec::INT32: