-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21958 from vespa-engine/toregge/factor-out-single…
…-small-numeric-search-context-from-single-small-numeric-attribute Factor out SingleSmallNumericSearchContext from SingleSmallNumericAttribute.
- Loading branch information
Showing
5 changed files
with
96 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters