23
23
#include <string>
24
24
#include <array>
25
25
#include <functional>
26
+ #include <variant>
26
27
27
28
#include "qcstring.h"
28
29
29
30
class Definition;
31
+ class SearchIndexIntf;
30
32
31
33
/*! Initialize the search indexer */
32
34
void initSearchIndexer();
@@ -35,6 +37,49 @@ void finalizeSearchIndexer();
35
37
36
38
//------- server side search index ----------------------
37
39
40
+
41
+ // --- intermediate data ------
42
+ struct SIData_CurrentDoc
43
+ {
44
+ SIData_CurrentDoc(const Definition *d,const QCString &a,bool b)
45
+ : ctx(d), anchor(a), isSourceFile(b) {}
46
+ const Definition *ctx = 0;
47
+ QCString anchor;
48
+ bool isSourceFile;
49
+ };
50
+
51
+ struct SIData_Word
52
+ {
53
+ SIData_Word(const QCString &w,bool b)
54
+ : word(w), hiPrio(b) {}
55
+ QCString word;
56
+ bool hiPrio;
57
+ };
58
+
59
+ // class to aggregate the search data collected on a worker thread
60
+ // and later transfer it to the search index on the main thread.
61
+ class SIDataCollection
62
+ {
63
+ public:
64
+ void setCurrentDoc(const Definition *ctx,const QCString &anchor,bool isSourceFile)
65
+ {
66
+ m_data.emplace_back(SIData_CurrentDoc(ctx,anchor,isSourceFile));
67
+ }
68
+ void addWord(const QCString &word,bool hiPriority)
69
+ {
70
+ m_data.emplace_back(SIData_Word(word,hiPriority));
71
+ }
72
+
73
+ // transfer the collected data to the given search index
74
+ void transfer(SearchIndexIntf &intf);
75
+
76
+ private:
77
+ using SIData = std::variant<SIData_CurrentDoc,SIData_Word>;
78
+ std::vector<SIData> m_data;
79
+ };
80
+
81
+ //-----------------------------
82
+
38
83
struct URL
39
84
{
40
85
URL(QCString n,QCString u) : name(n), url(u) {}
@@ -64,6 +109,7 @@ class IndexWord
64
109
URLInfoMap m_urls;
65
110
};
66
111
112
+
67
113
class SearchIndexIntf
68
114
{
69
115
public:
@@ -100,9 +146,9 @@ class SearchIndexExternal : public SearchIndexIntf
100
146
struct Private;
101
147
public:
102
148
SearchIndexExternal();
103
- void setCurrentDoc(const Definition *ctx,const QCString &anchor,bool isSourceFile);
104
- void addWord(const QCString &word,bool hiPriority);
105
- void write(const QCString &file);
149
+ void setCurrentDoc(const Definition *ctx,const QCString &anchor,bool isSourceFile) override ;
150
+ void addWord(const QCString &word,bool hiPriority) override ;
151
+ void write(const QCString &file) override ;
106
152
private:
107
153
std::unique_ptr<Private> p;
108
154
};
0 commit comments