aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.h
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 /searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.h
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.
Diffstat (limited to 'searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.h')
-rw-r--r--searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.h58
1 files changed, 58 insertions, 0 deletions
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;
+};
+
+}