summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-04-01 01:12:53 +0200
committerTor Egge <Tor.Egge@online.no>2022-04-01 08:58:41 +0200
commit573f686b07e6cc49d8e2316ab7c399fb9538e0f4 (patch)
tree540d9cb06f2380d06e6cfb62210f41216227f0be
parent305a641a418f0b7fcd869f5d21f5c740eaf63075 (diff)
Factor out MultiEnumSearchContext from MultiNumericEnumSearchContext.
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multi_enum_search_context.h61
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multi_enum_search_context.hpp18
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multi_numeric_enum_search_context.h43
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multi_numeric_enum_search_context.hpp10
-rw-r--r--searchlib/src/vespa/searchlib/attribute/numeric_range_matcher.h3
5 files changed, 87 insertions, 48 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/multi_enum_search_context.h b/searchlib/src/vespa/searchlib/attribute/multi_enum_search_context.h
new file mode 100644
index 00000000000..3426e2ca0f1
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/attribute/multi_enum_search_context.h
@@ -0,0 +1,61 @@
+// 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 "enumstore.h"
+#include "multi_value_mapping.h"
+
+namespace search::attribute {
+
+/*
+ * MultiEnumSearchContext handles the creation of search iterators for
+ * a query term on a multi value enumerated attribute vector.
+ * This class should be considered to be an abstract class.
+ */
+template <typename T, typename Matcher, typename M>
+class MultiEnumSearchContext : public Matcher, public SearchContext
+{
+protected:
+ const MultiValueMapping<M>& _mv_mapping;
+ const EnumStoreT<T>& _enum_store;
+
+ int32_t onFind(DocId docId, int32_t elemId, int32_t & weight) const override {
+ return find(docId, elemId, weight);
+ }
+
+ int32_t onFind(DocId docId, int32_t elemId) const override {
+ return find(docId, elemId);
+ }
+
+ bool valid() const override { return this->isValid(); }
+
+ MultiEnumSearchContext(Matcher&& matcher, const AttributeVector& toBeSearched, const MultiValueMapping<M>& mv_mapping, const EnumStoreT<T>& enum_store);
+
+public:
+ int32_t find(DocId doc, int32_t elemId, int32_t & weight) const {
+ auto indices(_mv_mapping.get(doc));
+ for (uint32_t i(elemId); i < indices.size(); i++) {
+ T v = _enum_store.get_value(indices[i].value_ref().load_acquire());
+ if (this->match(v)) {
+ weight = indices[i].weight();
+ return i;
+ }
+ }
+ weight = 0;
+ return -1;
+ }
+
+ int32_t find(DocId doc, int32_t elemId) const {
+ auto indices(_mv_mapping.get(doc));
+ for (uint32_t i(elemId); i < indices.size(); i++) {
+ T v = _enum_store.get_value(indices[i].value_ref().load_acquire());
+ if (this->match(v)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+};
+
+}
diff --git a/searchlib/src/vespa/searchlib/attribute/multi_enum_search_context.hpp b/searchlib/src/vespa/searchlib/attribute/multi_enum_search_context.hpp
new file mode 100644
index 00000000000..ce03f06472c
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/attribute/multi_enum_search_context.hpp
@@ -0,0 +1,18 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include "multi_enum_search_context.h"
+
+namespace search::attribute {
+
+template <typename T, typename Matcher, typename M>
+MultiEnumSearchContext<T, Matcher, M>::MultiEnumSearchContext(Matcher&& matcher, const AttributeVector& toBeSearched, const MultiValueMapping<M>& mv_mapping, const EnumStoreT<T>& enum_store)
+ : Matcher(std::move(matcher)),
+ SearchContext(toBeSearched),
+ _mv_mapping(mv_mapping),
+ _enum_store(enum_store)
+{
+}
+
+}
diff --git a/searchlib/src/vespa/searchlib/attribute/multi_numeric_enum_search_context.h b/searchlib/src/vespa/searchlib/attribute/multi_numeric_enum_search_context.h
index e381609bda1..7b0bc9de9d8 100644
--- a/searchlib/src/vespa/searchlib/attribute/multi_numeric_enum_search_context.h
+++ b/searchlib/src/vespa/searchlib/attribute/multi_numeric_enum_search_context.h
@@ -2,9 +2,7 @@
#pragma once
-#include "search_context.h"
-#include "enumstore.h"
-#include "multi_value_mapping.h"
+#include "multi_enum_search_context.h"
#include "numeric_range_matcher.h"
namespace search::attribute {
@@ -14,48 +12,11 @@ namespace search::attribute {
* a query term on a multi value numeric enumerated attribute vector.
*/
template <typename T, typename M>
-class MultiNumericEnumSearchContext : public NumericRangeMatcher<T>, public SearchContext
+class MultiNumericEnumSearchContext : public MultiEnumSearchContext<T, NumericRangeMatcher<T>, M>
{
-protected:
- const MultiValueMapping<M>& _mv_mapping;
- const EnumStoreT<T>& _enum_store;
-
- int32_t onFind(DocId docId, int32_t elemId, int32_t & weight) const override {
- return find(docId, elemId, weight);
- }
-
- int32_t onFind(DocId docId, int32_t elemId) const override {
- return find(docId, elemId);
- }
-
- bool valid() const override { return this->isValid(); }
-
public:
MultiNumericEnumSearchContext(std::unique_ptr<QueryTermSimple> qTerm, const AttributeVector& toBeSearched, const MultiValueMapping<M>& mv_mapping, const EnumStoreT<T>& enum_store);
- int32_t find(DocId doc, int32_t elemId, int32_t & weight) const {
- auto indices(_mv_mapping.get(doc));
- for (uint32_t i(elemId); i < indices.size(); i++) {
- T v = _enum_store.get_value(indices[i].value_ref().load_acquire());
- if (this->match(v)) {
- weight = indices[i].weight();
- return i;
- }
- }
- weight = 0;
- return -1;
- }
-
- int32_t find(DocId doc, int32_t elemId) const {
- auto indices(_mv_mapping.get(doc));
- for (uint32_t i(elemId); i < indices.size(); i++) {
- T v = _enum_store.get_value(indices[i].value_ref().load_acquire());
- if (this->match(v)) {
- return i;
- }
- }
- return -1;
- }
Int64Range getAsIntegerTerm() const override;
std::unique_ptr<queryeval::SearchIterator>
diff --git a/searchlib/src/vespa/searchlib/attribute/multi_numeric_enum_search_context.hpp b/searchlib/src/vespa/searchlib/attribute/multi_numeric_enum_search_context.hpp
index 38fd9f80535..2f9e698aaae 100644
--- a/searchlib/src/vespa/searchlib/attribute/multi_numeric_enum_search_context.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/multi_numeric_enum_search_context.hpp
@@ -3,6 +3,7 @@
#pragma once
#include "multi_numeric_enum_search_context.h"
+#include "multi_enum_search_context.hpp"
#include "attributeiterators.hpp"
#include <vespa/searchlib/queryeval/emptysearch.h>
@@ -10,10 +11,7 @@ namespace search::attribute {
template <typename T, typename M>
MultiNumericEnumSearchContext<T, M>::MultiNumericEnumSearchContext(std::unique_ptr<QueryTermSimple> qTerm, const AttributeVector& toBeSearched, const MultiValueMapping<M>& mv_mapping, const EnumStoreT<T>& enum_store)
- : NumericRangeMatcher<T>(*qTerm),
- SearchContext(toBeSearched),
- _mv_mapping(mv_mapping),
- _enum_store(enum_store)
+ : MultiEnumSearchContext<T, NumericRangeMatcher<T>, M>(NumericRangeMatcher<T>(*qTerm), toBeSearched, mv_mapping, enum_store)
{
}
@@ -28,10 +26,10 @@ template <typename T, typename M>
std::unique_ptr<queryeval::SearchIterator>
MultiNumericEnumSearchContext<T, M>::createFilterIterator(fef::TermFieldMatchData* matchData, bool strict)
{
- if (!valid()) {
+ if (!this->valid()) {
return std::make_unique<queryeval::EmptySearch>();
}
- if (getIsFilter()) {
+ if (this->getIsFilter()) {
return strict
? std::make_unique<FilterAttributeIteratorStrict<MultiNumericEnumSearchContext>>(*this, matchData)
: std::make_unique<FilterAttributeIteratorT<MultiNumericEnumSearchContext>>(*this, matchData);
diff --git a/searchlib/src/vespa/searchlib/attribute/numeric_range_matcher.h b/searchlib/src/vespa/searchlib/attribute/numeric_range_matcher.h
index d15df7e8ae7..3be73554268 100644
--- a/searchlib/src/vespa/searchlib/attribute/numeric_range_matcher.h
+++ b/searchlib/src/vespa/searchlib/attribute/numeric_range_matcher.h
@@ -23,8 +23,9 @@ private:
bool _valid;
int _limit;
size_t _max_per_group;
-protected:
+public:
NumericRangeMatcher(const QueryTermSimple& queryTerm, bool avoidUndefinedInRange=false);
+protected:
Int64Range getRange() const {
return Int64Range(static_cast<int64_t>(_low), static_cast<int64_t>(_high));
}