aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-03-31 22:55:39 +0200
committerTor Egge <Tor.Egge@online.no>2022-03-31 22:55:39 +0200
commit6e40d2916852c286ca84ccbec5f21ffd5cd6afbd (patch)
tree49b41632ee972a0ac115dee3bd76be8e984cf364 /searchlib
parentffade9acb7b44f15104367aa69301bea05b6f252 (diff)
Factor out StringMatcher from StringSearchContext.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/attribute/CMakeLists.txt1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/string_matcher.cpp24
-rw-r--r--searchlib/src/vespa/searchlib/attribute/string_matcher.h35
-rw-r--r--searchlib/src/vespa/searchlib/attribute/stringbase.cpp11
-rw-r--r--searchlib/src/vespa/searchlib/attribute/stringbase.h15
5 files changed, 68 insertions, 18 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt b/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt
index fde1e4cdc4f..8d2e278fb5d 100644
--- a/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt
+++ b/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt
@@ -109,6 +109,7 @@ vespa_add_library(searchlib_attribute OBJECT
sourceselector.cpp
stringattribute.cpp
stringbase.cpp
+ string_matcher.cpp
string_search_helper.cpp
DEPENDS
)
diff --git a/searchlib/src/vespa/searchlib/attribute/string_matcher.cpp b/searchlib/src/vespa/searchlib/attribute/string_matcher.cpp
new file mode 100644
index 00000000000..bc3637e7215
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/attribute/string_matcher.cpp
@@ -0,0 +1,24 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "string_matcher.h"
+#include <vespa/searchlib/query/query_term_ucs4.h>
+
+namespace search::attribute {
+
+StringMatcher::StringMatcher(std::unique_ptr<QueryTermSimple> query_term, bool cased)
+ : _query_term(static_cast<QueryTermUCS4 *>(query_term.release())),
+ _helper(*_query_term, cased)
+{
+}
+
+StringMatcher::StringMatcher(StringMatcher&&) noexcept = default;
+
+StringMatcher::~StringMatcher() = default;
+
+bool
+StringMatcher::isValid() const
+{
+ return (_query_term && (!_query_term->empty()));
+}
+
+}
diff --git a/searchlib/src/vespa/searchlib/attribute/string_matcher.h b/searchlib/src/vespa/searchlib/attribute/string_matcher.h
new file mode 100644
index 00000000000..51cd3d238a6
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/attribute/string_matcher.h
@@ -0,0 +1,35 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include "string_search_helper.h"
+
+namespace search { class QueryTermSimple; }
+
+namespace search::attribute {
+
+/*
+ * Class used to determine if an attribute vector string value is a match for
+ * the query string value.
+ */
+class StringMatcher
+{
+private:
+ std::unique_ptr<QueryTermUCS4> _query_term;
+ attribute::StringSearchHelper _helper;
+protected:
+ StringMatcher(std::unique_ptr<QueryTermSimple> qTerm, bool cased);
+ StringMatcher(StringMatcher&&) noexcept;
+ ~StringMatcher();
+ bool isValid() const;
+ bool match(const char *src) const { return _helper.isMatch(src); }
+ bool isPrefix() const { return _helper.isPrefix(); }
+ bool isRegex() const { return _helper.isRegex(); }
+ bool isCased() const { return _helper.isCased(); }
+ bool isFuzzy() const { return _helper.isFuzzy(); }
+ const vespalib::Regex& getRegex() const { return _helper.getRegex(); }
+ const vespalib::FuzzyMatcher& getFuzzyMatcher() const { return _helper.getFuzzyMatcher(); }
+ const QueryTermUCS4* get_query_term_ptr() const noexcept { return _query_term.get(); }
+};
+
+}
diff --git a/searchlib/src/vespa/searchlib/attribute/stringbase.cpp b/searchlib/src/vespa/searchlib/attribute/stringbase.cpp
index d8ab577c6d3..35299400107 100644
--- a/searchlib/src/vespa/searchlib/attribute/stringbase.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/stringbase.cpp
@@ -220,10 +220,9 @@ StringAttribute::onSerializeForDescendingSort(DocId doc, void * serTo, long avai
}
StringAttribute::StringSearchContext::StringSearchContext(QueryTermSimple::UP qTerm,
- const StringAttribute & toBeSearched) :
- SearchContext(toBeSearched),
- _queryTerm(static_cast<QueryTermUCS4 *>(qTerm.release())),
- _helper(*_queryTerm, toBeSearched.getConfig().get_match() == Config::Match::CASED)
+ const StringAttribute & toBeSearched)
+ : StringMatcher(std::move(qTerm), toBeSearched.getConfig().get_match() == Config::Match::CASED),
+ SearchContext(toBeSearched)
{
}
@@ -234,13 +233,13 @@ StringAttribute::StringSearchContext::~StringSearchContext() = default;
bool
StringAttribute::StringSearchContext::valid() const
{
- return (_queryTerm && (!_queryTerm->empty()));
+ return isValid();
}
const QueryTermUCS4 *
StringAttribute::StringSearchContext::queryTerm() const
{
- return _queryTerm.get();
+ return get_query_term_ptr();
}
uint32_t
diff --git a/searchlib/src/vespa/searchlib/attribute/stringbase.h b/searchlib/src/vespa/searchlib/attribute/stringbase.h
index ffd285a9a73..630d85e23c3 100644
--- a/searchlib/src/vespa/searchlib/attribute/stringbase.h
+++ b/searchlib/src/vespa/searchlib/attribute/stringbase.h
@@ -8,7 +8,7 @@
#include "i_enum_store.h"
#include "loadedenumvalue.h"
#include "search_context.h"
-#include "string_search_helper.h"
+#include "string_matcher.h"
namespace search {
@@ -88,7 +88,7 @@ private:
long onSerializeForDescendingSort(DocId doc, void * serTo, long available, const common::BlobConverter * bc) const override;
protected:
- class StringSearchContext : public attribute::SearchContext {
+ class StringSearchContext : public attribute::StringMatcher, public attribute::SearchContext {
public:
StringSearchContext(QueryTermSimpleUP qTerm, const StringAttribute & toBeSearched);
StringSearchContext(StringSearchContext&&) noexcept;
@@ -96,13 +96,7 @@ protected:
protected:
bool valid() const override;
const QueryTermUCS4 * queryTerm() const override;
- bool isMatch(const char *src) const { return _helper.isMatch(src); }
- bool isPrefix() const { return _helper.isPrefix(); }
- bool isRegex() const { return _helper.isRegex(); }
- bool isCased() const { return _helper.isCased(); }
- bool isFuzzy() const { return _helper.isFuzzy(); }
- const vespalib::Regex & getRegex() const { return _helper.getRegex(); }
- const vespalib::FuzzyMatcher & getFuzzyMatcher() const { return _helper.getFuzzyMatcher(); }
+ bool isMatch(const char *src) const { return match(src); }
class CollectHitCount {
public:
@@ -140,9 +134,6 @@ protected:
}
return -1;
}
- private:
- std::unique_ptr<QueryTermUCS4> _queryTerm;
- attribute::StringSearchHelper _helper;
};
};