blob: b3fe8d5c89630dc08bb39df43458c55c39aefa9e (
plain) (
blame)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "i_reprocessing_handler.h"
#include <vespa/searchlib/docstore/idocumentstore.h>
namespace proton {
/**
* Class that is a visitor over a document store and proxies all documents
* to the registered readers and rewriters upon visiting.
*/
class DocumentReprocessingHandler : public IReprocessingHandler,
public search::IDocumentStoreReadVisitor
{
private:
using ReaderVector = std::vector<IReprocessingReader::SP>;
using RewriterVector = std::vector<IReprocessingRewriter::SP>;
class RewriteVisitor : public search::IDocumentStoreRewriteVisitor
{
private:
DocumentReprocessingHandler &_handler;
public:
RewriteVisitor(DocumentReprocessingHandler &handler) : _handler(handler) {}
// Implements search::IDocumentStoreRewriteVisitor
virtual void visit(uint32_t lid, const std::shared_ptr<document::Document> &doc) override {
_handler.rewriteVisit(lid, doc);
}
};
ReaderVector _readers;
RewriterVector _rewriters;
RewriteVisitor _rewriteVisitor;
uint32_t _docIdLimit;
void rewriteVisit(uint32_t lid, const std::shared_ptr<document::Document> &doc);
public:
DocumentReprocessingHandler(uint32_t docIdLimit);
~DocumentReprocessingHandler();
bool hasReaders() const {
return !_readers.empty();
}
bool hasRewriters() const {
return !_rewriters.empty();
}
bool hasProcessors() const {
return hasReaders() || hasRewriters();
}
search::IDocumentStoreRewriteVisitor &getRewriteVisitor() {
return _rewriteVisitor;
}
// Implements IReprocessingHandler
virtual void addReader(const IReprocessingReader::SP &reader) override {
_readers.push_back(reader);
}
virtual void addRewriter(const IReprocessingRewriter::SP &rewriter) override {
_rewriters.push_back(rewriter);
}
// Implements search::IDocumentStoreReadVisitor
virtual void visit(uint32_t lid, const std::shared_ptr<document::Document> &doc) override;
virtual void visit(uint32_t lid) override;
void done();
};
} // namespace proton
|