-
Notifications
You must be signed in to change notification settings - Fork 620
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 #32435 from vespa-engine/toregge/add-raw-features-…
…collector Add raw features collector.
- Loading branch information
Showing
3 changed files
with
75 additions
and
50 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
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
52 changes: 52 additions & 0 deletions
52
searchlib/src/vespa/searchlib/bitcompression/raw_features_collector.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,52 @@ | ||
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. | ||
|
||
#pragma once | ||
|
||
#include "compression.h" | ||
|
||
namespace search::bitcompression { | ||
|
||
/* | ||
* Class collecting raw features data for a (word, document tuple), used by | ||
* EG2PosOccDecodeContext::readFeatures and EG2PosOccDecodeContext::readFeatures. | ||
* Disk index fusion uses raw features when feature parameters are identical to | ||
* improve fusion speed, cf. FieldMerger::select_cooked_or_raw_features. | ||
*/ | ||
class RawFeaturesCollector { | ||
uint64_t _start_offset; | ||
const uint64_t* _raw_features; | ||
|
||
void collect(search::index::DocIdAndFeatures& features, const uint64_t* compr) { | ||
auto& blob = features.blob(); | ||
auto* raw_features = _raw_features; | ||
while (raw_features < compr) { | ||
blob.emplace_back(*raw_features); | ||
++raw_features; | ||
} | ||
} | ||
|
||
public: | ||
RawFeaturesCollector(const DecodeContext64Base& dc, search::index::DocIdAndFeatures& features) | ||
: _start_offset(dc.getReadOffset()), | ||
_raw_features(dc.getCompr()) | ||
{ | ||
features.clear_features(dc.getBitOffset()); | ||
features.set_has_raw_data(true); | ||
} | ||
|
||
void collect_before_read_compr_buffer(const DecodeContext64Base& dc, search::index::DocIdAndFeatures& features) { | ||
collect(features, dc._valI); | ||
} | ||
|
||
void fixup_after_read_compr_buffer(const DecodeContext64Base& dc) { | ||
_raw_features = dc._valI; | ||
} | ||
|
||
void finish(const DecodeContext64Base& dc, search::index::DocIdAndFeatures& features) { | ||
collect(features, dc._valI); | ||
auto end_offset = dc.getReadOffset(); | ||
features.set_bit_length( end_offset - _start_offset); | ||
} | ||
}; | ||
|
||
} |