aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-04-03 23:34:15 +0200
committerGitHub <noreply@github.com>2022-04-03 23:34:15 +0200
commit00641e5eef7d792ff376d20922f451de042539c2 (patch)
tree0a0de0af7cb72067f062675b2937bf90051c5604
parentab62199275b7b92c57507c342381c02a60e5b5af (diff)
parenta9197eae34dd3d0bec1e0c55e52aa37f5cfcd1a3 (diff)
Merge pull request #21958 from vespa-engine/toregge/factor-out-single-small-numeric-search-context-from-single-small-numeric-attributev7.569.71
Factor out SingleSmallNumericSearchContext from SingleSmallNumericAttribute.
-rw-r--r--searchlib/src/vespa/searchlib/attribute/CMakeLists.txt1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.cpp35
-rw-r--r--searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.h58
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp39
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.h50
5 files changed, 96 insertions, 87 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt b/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt
index 3c34bf8a57d..b3aa3bd958b 100644
--- a/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt
+++ b/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt
@@ -110,6 +110,7 @@ vespa_add_library(searchlib_attribute OBJECT
singlestringpostattribute.cpp
single_numeric_enum_search_context.cpp
single_numeric_search_context.cpp
+ single_small_numeric_search_context.cpp
single_string_enum_search_context.cpp
single_string_enum_hint_search_context.cpp
sourceselector.cpp
diff --git a/searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.cpp b/searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.cpp
new file mode 100644
index 00000000000..5eeef7cd61a
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.cpp
@@ -0,0 +1,35 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "single_small_numeric_search_context.h"
+#include "attributeiterators.hpp"
+#include <vespa/searchlib/queryeval/emptysearch.h>
+
+namespace search::attribute {
+
+SingleSmallNumericSearchContext::SingleSmallNumericSearchContext(std::unique_ptr<QueryTermSimple> qTerm, const AttributeVector& toBeSearched, const Word* word_data, Word value_mask, uint32_t value_shift_shift, uint32_t value_shift_mask, uint32_t word_shift)
+ : NumericSearchContext<NumericRangeMatcher<T>>(toBeSearched, *qTerm, false),
+ _wordData(word_data),
+ _valueMask(value_mask),
+ _valueShiftShift(value_shift_shift),
+ _valueShiftMask(value_shift_mask),
+ _wordShift(word_shift)
+{
+}
+
+std::unique_ptr<queryeval::SearchIterator>
+SingleSmallNumericSearchContext::createFilterIterator(fef::TermFieldMatchData* matchData, bool strict)
+{
+ if (!valid()) {
+ return std::make_unique<queryeval::EmptySearch>();
+ }
+ if (getIsFilter()) {
+ return strict
+ ? std::make_unique<FilterAttributeIteratorStrict<SingleSmallNumericSearchContext>>(*this, matchData)
+ : std::make_unique<FilterAttributeIteratorT<SingleSmallNumericSearchContext>>(*this, matchData);
+ }
+ return strict
+ ? std::make_unique<AttributeIteratorStrict<SingleSmallNumericSearchContext>>(*this, matchData)
+ : std::make_unique<AttributeIteratorT<SingleSmallNumericSearchContext>>(*this, matchData);
+}
+
+}
diff --git a/searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.h b/searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.h
new file mode 100644
index 00000000000..46ed02b3eca
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.h
@@ -0,0 +1,58 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include "numeric_search_context.h"
+#include "numeric_range_matcher.h"
+#include <vespa/vespalib/util/atomic.h>
+
+namespace search::attribute {
+
+/*
+ * SingleSmallNumericSearchContext handles the creation of search iterators for
+ * a query term on a single value small numeric attribute vector.
+ */
+class SingleSmallNumericSearchContext : public NumericSearchContext<NumericRangeMatcher<int8_t>>
+{
+private:
+ using Word = uint32_t;
+ using T = int8_t;
+ const Word *_wordData;
+ Word _valueMask;
+ uint32_t _valueShiftShift;
+ uint32_t _valueShiftMask;
+ uint32_t _wordShift;
+
+ int32_t onFind(DocId docId, int32_t elementId, int32_t & weight) const override {
+ return find(docId, elementId, weight);
+ }
+
+ int32_t onFind(DocId docId, int32_t elementId) const override {
+ return find(docId, elementId);
+ }
+
+public:
+ SingleSmallNumericSearchContext(std::unique_ptr<QueryTermSimple> qTerm, const AttributeVector& toBeSearched, const Word* word_data, Word value_mask, uint32_t value_shift_shift, uint32_t value_shift_mask, uint32_t word_shift);
+
+ int32_t find(DocId docId, int32_t elemId, int32_t & weight) const {
+ if ( elemId != 0) return -1;
+ const Word &word = _wordData[docId >> _wordShift];
+ uint32_t valueShift = (docId & _valueShiftMask) << _valueShiftShift;
+ T v = (vespalib::atomic::load_ref_relaxed(word) >> valueShift) & _valueMask;
+ weight = 1;
+ return match(v) ? 0 : -1;
+ }
+
+ int32_t find(DocId docId, int32_t elemId) const {
+ if ( elemId != 0) return -1;
+ const Word &word = _wordData[docId >> _wordShift];
+ uint32_t valueShift = (docId & _valueShiftMask) << _valueShiftShift;
+ T v = (vespalib::atomic::load_ref_relaxed(word) >> valueShift) & _valueMask;
+ return match(v) ? 0 : -1;
+ }
+
+ std::unique_ptr<queryeval::SearchIterator>
+ createFilterIterator(fef::TermFieldMatchData* matchData, bool strict) override;
+};
+
+}
diff --git a/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp b/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp
index 009078447dc..eca74255026 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp
@@ -1,12 +1,11 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "singlesmallnumericattribute.h"
-#include "attributeiterators.hpp"
#include "attributevector.hpp"
#include "iattributesavetarget.h"
#include "primitivereader.h"
+#include "single_small_numeric_search_context.h"
#include <vespa/searchlib/query/query_term_simple.h>
-#include <vespa/searchlib/queryeval/emptysearch.h>
#include <vespa/searchlib/util/file_settings.h>
#include <vespa/vespalib/data/databuffer.h>
#include <vespa/vespalib/util/size_literals.h>
@@ -172,7 +171,7 @@ std::unique_ptr<attribute::SearchContext>
SingleValueSmallNumericAttribute::getSearch(std::unique_ptr<QueryTermSimple> qTerm,
const attribute::SearchContextParams &) const
{
- return std::make_unique<SingleSearchContext>(std::move(qTerm), *this);
+ return std::make_unique<attribute::SingleSmallNumericSearchContext>(std::move(qTerm), *this, &_wordData.acquire_elem_ref(0), _valueMask, _valueShiftShift, _valueShiftMask, _wordShift);
}
void
@@ -208,40 +207,6 @@ SingleValueSmallNumericAttribute::getEstimatedSaveByteSize() const
return headerSize + sz;
}
-bool SingleValueSmallNumericAttribute::SingleSearchContext::valid() const { return this->isValid(); }
-
-
-SingleValueSmallNumericAttribute::SingleSearchContext::SingleSearchContext(std::unique_ptr<QueryTermSimple> qTerm,
- const SingleValueSmallNumericAttribute & toBeSearched)
- : attribute::NumericRangeMatcher<T>(*qTerm),
- SearchContext(toBeSearched), _wordData(&toBeSearched._wordData.acquire_elem_ref(0)),
- _valueMask(toBeSearched._valueMask),
- _valueShiftShift(toBeSearched._valueShiftShift),
- _valueShiftMask(toBeSearched._valueShiftMask),
- _wordShift(toBeSearched._wordShift)
-{ }
-
-Int64Range
-SingleValueSmallNumericAttribute::SingleSearchContext::getAsIntegerTerm() const {
- return this->getRange();
-}
-
-std::unique_ptr<queryeval::SearchIterator>
-SingleValueSmallNumericAttribute::SingleSearchContext::createFilterIterator(fef::TermFieldMatchData * matchData, bool strict)
-{
- if (!valid()) {
- return std::make_unique<queryeval::EmptySearch>();
- }
- if (getIsFilter()) {
- return strict
- ? std::make_unique<FilterAttributeIteratorStrict<SingleSearchContext>>(*this, matchData)
- : std::make_unique<FilterAttributeIteratorT<SingleSearchContext>>(*this, matchData);
- }
- return strict
- ? std::make_unique<AttributeIteratorStrict<SingleSearchContext>>(*this, matchData)
- : std::make_unique<AttributeIteratorT<SingleSearchContext>>(*this, matchData);
-}
-
namespace {
template <typename TT>
diff --git a/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.h b/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.h
index 77c4133817c..f6059d3d510 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.h
@@ -3,8 +3,6 @@
#pragma once
#include "integerbase.h"
-#include "floatbase.h"
-#include "numeric_range_matcher.h"
#include "search_context.h"
#include <vespa/vespalib/util/atomic.h>
#include <vespa/vespalib/util/rcuvector.h>
@@ -15,7 +13,6 @@ namespace search {
class SingleValueSmallNumericAttribute : public IntegerAttributeTemplate<int8_t>
{
private:
-// friend class attribute::SearchContext;
typedef IntegerAttributeTemplate<int8_t> B;
typedef B::BaseType T;
typedef B::DocId DocId;
@@ -58,53 +55,6 @@ protected:
public:
- /*
- * Specialization of SearchContext
- */
- class SingleSearchContext : public attribute::NumericRangeMatcher<T>, public attribute::SearchContext
- {
- private:
- const Word *_wordData;
- Word _valueMask;
- uint32_t _valueShiftShift;
- uint32_t _valueShiftMask;
- uint32_t _wordShift;
-
- int32_t onFind(DocId docId, int32_t elementId, int32_t & weight) const override {
- return find(docId, elementId, weight);
- }
-
- int32_t onFind(DocId docId, int32_t elementId) const override {
- return find(docId, elementId);
- }
-
- bool valid() const override;
-
- public:
- SingleSearchContext(std::unique_ptr<QueryTermSimple> qTerm, const SingleValueSmallNumericAttribute & toBeSearched);
-
- int32_t find(DocId docId, int32_t elemId, int32_t & weight) const {
- if ( elemId != 0) return -1;
- const Word &word = _wordData[docId >> _wordShift];
- uint32_t valueShift = (docId & _valueShiftMask) << _valueShiftShift;
- T v = (vespalib::atomic::load_ref_relaxed(word) >> valueShift) & _valueMask;
- weight = 1;
- return match(v) ? 0 : -1;
- }
-
- int32_t find(DocId docId, int32_t elemId) const {
- if ( elemId != 0) return -1;
- const Word &word = _wordData[docId >> _wordShift];
- uint32_t valueShift = (docId & _valueShiftMask) << _valueShiftShift;
- T v = (vespalib::atomic::load_ref_relaxed(word) >> valueShift) & _valueMask;
- return match(v) ? 0 : -1;
- }
-
- Int64Range getAsIntegerTerm() const override;
-
- std::unique_ptr<queryeval::SearchIterator>
- createFilterIterator(fef::TermFieldMatchData * matchData, bool strict) override;
- };
SingleValueSmallNumericAttribute(const vespalib::string & baseFileName, const Config &c, Word valueMask,
uint32_t valueShiftShift, uint32_t valueShiftMask, uint32_t wordShift);