1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "field_index_remover.h"
#include "i_field_index_remove_listener.h"
#include "word_store.h"
#include <vespa/searchlib/common/sort.h>
namespace search::memoryindex {
using Builder = CompactWordsStore::Builder;
using Iterator = CompactWordsStore::Iterator;
FieldIndexRemover::FieldIndexRemover(const WordStore &wordStore)
: _store(),
_builder(),
_wordFieldDocTuples(),
_wordStore(wordStore)
{
}
FieldIndexRemover::~FieldIndexRemover() = default;
void
FieldIndexRemover::remove(uint32_t docId, IFieldIndexRemoveListener &listener)
{
Iterator itr = _store.get(docId);
if (itr.valid()) {
for (; itr.valid(); ++itr) {
vespalib::stringref word = _wordStore.getWord(itr.wordRef());
listener.remove(word, docId);
}
_store.remove(docId);
}
}
void
FieldIndexRemover::insert(vespalib::datastore::EntryRef wordRef, uint32_t docId)
{
_wordFieldDocTuples.emplace_back(wordRef, docId);
}
void
FieldIndexRemover::flush()
{
if (_wordFieldDocTuples.empty()) {
_store.commit();
return;
}
ShiftBasedRadixSorter<WordFieldDocTuple, WordFieldDocTuple::Radix, std::less<WordFieldDocTuple>, 24, true>::
radix_sort(WordFieldDocTuple::Radix(), std::less<WordFieldDocTuple>(), &_wordFieldDocTuples[0], _wordFieldDocTuples.size(), 16);
auto builder = std::make_unique<Builder>(_wordFieldDocTuples[0]._docId);
for (const auto &tuple : _wordFieldDocTuples) {
if (builder->docId() != tuple._docId) {
_store.insert(*builder);
builder = std::make_unique<Builder>(tuple._docId);
}
builder->insert(tuple._wordRef);
}
_store.insert(*builder);
_store.commit();
_wordFieldDocTuples.clear();
}
}
|