summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-04-02 10:14:10 +0200
committerGitHub <noreply@github.com>2022-04-02 10:14:10 +0200
commitcaa488658d2b5c812e2450f7d91d2a9fb672618f (patch)
treedf72ee2f5268254dde3388b3eb18cc874c383919
parentd17cff94bee770644abe701ab49c7e5f6f68f095 (diff)
parentdb7e62c0af77cb5b0ccd048bb667a285f8fb905b (diff)
Merge pull request #21948 from vespa-engine/toregge/mostly-move-string-search-context
Mostly move StringSearchContext.
-rw-r--r--searchlib/src/vespa/searchlib/attribute/CMakeLists.txt1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multistringattribute.hpp21
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlestringattribute.hpp21
-rw-r--r--searchlib/src/vespa/searchlib/attribute/string_search_context.cpp58
-rw-r--r--searchlib/src/vespa/searchlib/attribute/string_search_context.h35
-rw-r--r--searchlib/src/vespa/searchlib/attribute/stringbase.cpp15
-rw-r--r--searchlib/src/vespa/searchlib/attribute/stringbase.h5
8 files changed, 101 insertions, 57 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt b/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt
index ba4ec2b3f12..2558b9878ed 100644
--- a/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt
+++ b/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt
@@ -112,6 +112,7 @@ vespa_add_library(searchlib_attribute OBJECT
stringattribute.cpp
stringbase.cpp
string_matcher.cpp
+ string_search_context.cpp
string_search_helper.cpp
DEPENDS
)
diff --git a/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.h b/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.h
index 7042de9ddb8..0342976ffd6 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.h
+++ b/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.h
@@ -31,9 +31,11 @@ protected:
uint64_t numValues);
~EnumHintSearchContext() override;
+public:
void lookupTerm(const vespalib::datastore::EntryComparator &comp);
void lookupRange(const vespalib::datastore::EntryComparator &low, const vespalib::datastore::EntryComparator &high);
+protected:
std::unique_ptr<queryeval::SearchIterator>
createPostingIterator(fef::TermFieldMatchData *matchData, bool strict) override;
diff --git a/searchlib/src/vespa/searchlib/attribute/multistringattribute.hpp b/searchlib/src/vespa/searchlib/attribute/multistringattribute.hpp
index 454913c3990..a6825cfb9bd 100644
--- a/searchlib/src/vespa/searchlib/attribute/multistringattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/multistringattribute.hpp
@@ -114,26 +114,7 @@ StringTemplSearchContext(QueryTermSimpleUP qTerm, const AttrType & toBeSearched)
toBeSearched.getCommittedDocIdLimit(),
toBeSearched.getStatus().getNumValues())
{
- const EnumStore &enumStore(toBeSearched.getEnumStore());
-
- this->_plsc = static_cast<attribute::IPostingListSearchContext *>(this);
- if (this->valid()) {
- if (this->isPrefix()) {
- auto comp = enumStore.make_folded_comparator_prefix(queryTerm()->getTerm());
- lookupRange(comp, comp);
- } else if (this->isRegex()) {
- vespalib::string prefix(vespalib::RegexpUtil::get_prefix(this->queryTerm()->getTerm()));
- auto comp = enumStore.make_folded_comparator_prefix(prefix.c_str());
- lookupRange(comp, comp);
- } else if (this->isFuzzy()) {
- vespalib::string prefix(this->getFuzzyMatcher().getPrefix());
- auto comp = enumStore.make_folded_comparator_prefix(prefix.c_str());
- lookupRange(comp, comp);
- } else {
- auto comp = enumStore.make_folded_comparator(queryTerm()->getTerm());
- lookupTerm(comp);
- }
- }
+ this->setup_enum_hint_sc(toBeSearched.getEnumStore(), *this);
}
} // namespace search
diff --git a/searchlib/src/vespa/searchlib/attribute/singlestringattribute.hpp b/searchlib/src/vespa/searchlib/attribute/singlestringattribute.hpp
index 6c99db68bd4..e4027c928a0 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlestringattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/singlestringattribute.hpp
@@ -50,26 +50,7 @@ SingleValueStringAttributeT<B>::StringTemplSearchContext::StringTemplSearchConte
toBeSearched.getCommittedDocIdLimit(),
toBeSearched.getStatus().getNumValues())
{
- const EnumStore &enumStore(toBeSearched.getEnumStore());
-
- this->_plsc = static_cast<attribute::IPostingListSearchContext *>(this);
- if (this->valid()) {
- if (this->isPrefix()) {
- auto comp = enumStore.make_folded_comparator_prefix(queryTerm()->getTerm());
- lookupRange(comp, comp);
- } else if (this->isRegex()) {
- vespalib::string prefix(vespalib::RegexpUtil::get_prefix(this->queryTerm()->getTerm()));
- auto comp = enumStore.make_folded_comparator_prefix(prefix.c_str());
- lookupRange(comp, comp);
- } else if (this->isFuzzy()) {
- vespalib::string prefix(this->getFuzzyMatcher().getPrefix());
- auto comp = enumStore.make_folded_comparator_prefix(prefix.c_str());
- lookupRange(comp, comp);
- } else {
- auto comp = enumStore.make_folded_comparator(queryTerm()->getTerm());
- lookupTerm(comp);
- }
- }
+ this->setup_enum_hint_sc(toBeSearched.getEnumStore(), *this);
}
}
diff --git a/searchlib/src/vespa/searchlib/attribute/string_search_context.cpp b/searchlib/src/vespa/searchlib/attribute/string_search_context.cpp
new file mode 100644
index 00000000000..aa7aa016720
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/attribute/string_search_context.cpp
@@ -0,0 +1,58 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "string_search_context.h"
+#include "enumhintsearchcontext.h"
+#include "enumstore.h"
+#include <vespa/vespalib/util/regexp.h>
+#include <vespa/searchlib/query/query_term_ucs4.h>
+
+namespace search::attribute {
+
+StringSearchContext::StringSearchContext(const AttributeVector& to_be_searched, std::unique_ptr<QueryTermSimple> query_term, bool cased)
+ : SearchContext(to_be_searched),
+ StringMatcher(std::move(query_term), cased)
+{
+}
+
+StringSearchContext::StringSearchContext(const AttributeVector& to_be_searched, StringMatcher &&matcher)
+ : SearchContext(to_be_searched),
+ StringMatcher(std::move(matcher))
+{
+}
+
+const QueryTermUCS4*
+StringSearchContext::queryTerm() const
+{
+ return get_query_term_ptr();
+}
+
+bool
+StringSearchContext::valid() const
+{
+ return StringMatcher::isValid();
+}
+
+void
+StringSearchContext::setup_enum_hint_sc(const EnumStoreT<const char*>& enum_store, EnumHintSearchContext& enum_hint_sc)
+{
+ _plsc = &enum_hint_sc;
+ if (valid()) {
+ if (isPrefix()) {
+ auto comp = enum_store.make_folded_comparator_prefix(queryTerm()->getTerm());
+ enum_hint_sc.lookupRange(comp, comp);
+ } else if (isRegex()) {
+ vespalib::string prefix(vespalib::RegexpUtil::get_prefix(queryTerm()->getTerm()));
+ auto comp = enum_store.make_folded_comparator_prefix(prefix.c_str());
+ enum_hint_sc.lookupRange(comp, comp);
+ } else if (isFuzzy()) {
+ vespalib::string prefix(getFuzzyMatcher().getPrefix());
+ auto comp = enum_store.make_folded_comparator_prefix(prefix.c_str());
+ enum_hint_sc.lookupRange(comp, comp);
+ } else {
+ auto comp = enum_store.make_folded_comparator(queryTerm()->getTerm());
+ enum_hint_sc.lookupTerm(comp);
+ }
+ }
+}
+
+}
diff --git a/searchlib/src/vespa/searchlib/attribute/string_search_context.h b/searchlib/src/vespa/searchlib/attribute/string_search_context.h
new file mode 100644
index 00000000000..fc9f3688a7a
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/attribute/string_search_context.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 "search_context.h"
+#include "string_matcher.h"
+
+namespace search {
+
+template <class EntryT> class EnumStoreT;
+
+}
+
+namespace search::attribute {
+
+class EnumHintSearchContext;
+
+/*
+ * StringSearchContext is an abstract base class for search contexts
+ * handling a query term on a string attribute vector.
+ */
+class StringSearchContext : public SearchContext, public StringMatcher
+{
+protected:
+ using MatcherType = StringMatcher;
+public:
+ StringSearchContext(const AttributeVector& to_be_searched, std::unique_ptr<QueryTermSimple> query_term, bool cased);
+ StringSearchContext(const AttributeVector& to_be_searched, StringMatcher&& matcher);
+ const QueryTermUCS4* queryTerm() const override;
+ bool valid() const override;
+
+ void setup_enum_hint_sc(const EnumStoreT<const char*>& enum_store, EnumHintSearchContext& enum_hint_sc);
+};
+
+}
diff --git a/searchlib/src/vespa/searchlib/attribute/stringbase.cpp b/searchlib/src/vespa/searchlib/attribute/stringbase.cpp
index 355e14bee45..f30792099f8 100644
--- a/searchlib/src/vespa/searchlib/attribute/stringbase.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/stringbase.cpp
@@ -154,8 +154,7 @@ StringAttribute::onSerializeForDescendingSort(DocId doc, void * serTo, long avai
StringAttribute::StringSearchContext::StringSearchContext(QueryTermSimple::UP qTerm,
const StringAttribute & toBeSearched)
- : StringMatcher(std::move(qTerm), toBeSearched.getConfig().get_match() == Config::Match::CASED),
- SearchContext(toBeSearched)
+ : attribute::StringSearchContext(toBeSearched, std::move(qTerm), toBeSearched.getConfig().get_match() == Config::Match::CASED)
{
}
@@ -163,18 +162,6 @@ StringAttribute::StringSearchContext::StringSearchContext(StringSearchContext&&)
StringAttribute::StringSearchContext::~StringSearchContext() = default;
-bool
-StringAttribute::StringSearchContext::valid() const
-{
- return isValid();
-}
-
-const QueryTermUCS4 *
-StringAttribute::StringSearchContext::queryTerm() const
-{
- return get_query_term_ptr();
-}
-
uint32_t
StringAttribute::clearDoc(DocId doc)
{
diff --git a/searchlib/src/vespa/searchlib/attribute/stringbase.h b/searchlib/src/vespa/searchlib/attribute/stringbase.h
index 630d85e23c3..366fd89c62d 100644
--- a/searchlib/src/vespa/searchlib/attribute/stringbase.h
+++ b/searchlib/src/vespa/searchlib/attribute/stringbase.h
@@ -9,6 +9,7 @@
#include "loadedenumvalue.h"
#include "search_context.h"
#include "string_matcher.h"
+#include "string_search_context.h"
namespace search {
@@ -88,14 +89,12 @@ private:
long onSerializeForDescendingSort(DocId doc, void * serTo, long available, const common::BlobConverter * bc) const override;
protected:
- class StringSearchContext : public attribute::StringMatcher, public attribute::SearchContext {
+ class StringSearchContext : public attribute::StringSearchContext {
public:
StringSearchContext(QueryTermSimpleUP qTerm, const StringAttribute & toBeSearched);
StringSearchContext(StringSearchContext&&) noexcept;
~StringSearchContext() override;
protected:
- bool valid() const override;
- const QueryTermUCS4 * queryTerm() const override;
bool isMatch(const char *src) const { return match(src); }
class CollectHitCount {