Doxygen
Loading...
Searching...
No Matches
searchindex.h
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Copyright (C) 1997-2022 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
15
16/** @file
17 * @brief Web server based search engine.
18 *
19 * Comes in two flavors: internal (via generated index) or external (via doxyindexer + doxysearch)
20 */
21
22#ifndef SEARCHINDEX_H
23#define SEARCHINDEX_H
24
25#include <memory>
26#include <vector>
27#include <map>
28#include <unordered_map>
29#include <string>
30#include <array>
31#include <variant>
32
33#include "qcstring.h"
34#include "growbuf.h"
35
36class Definition;
37
38/*! Initialize the search indexer */
40/*! Cleanup the search indexer */
42
43// --- intermediate data collected by one thread ------
44
46{
47 SIData_CurrentDoc(const Definition *d,const QCString &a,bool b)
48 : ctx(d), anchor(a), isSourceFile(b) {}
49 const Definition *ctx = nullptr;
52};
53
55{
56 SIData_Word(const QCString &w,bool b)
57 : word(w), hiPrio(b) {}
59 bool hiPrio;
60};
61
62//-----------------------------
63
64/** Writes search index for doxygen provided server based search engine that uses PHP. */
66{
67 struct URL
68 {
69 URL(const QCString &n,const QCString &u) : name(n), url(u) {}
72 };
73
74 struct URLInfo
75 {
76 URLInfo(int idx,int f) : urlIdx(idx), freq(f) {}
77 int urlIdx;
78 int freq;
79 };
80
82 {
83 public:
84 using URLInfoMap = std::unordered_map<int,URLInfo>;
86 void addUrlIndex(int,bool);
87 URLInfoMap urls() const { return m_urls; }
88 QCString word() const { return m_word; }
89
90 private:
93 };
94
95 public:
97 void setCurrentDoc(const Definition *ctx,const QCString &anchor,bool isSourceFile);
98 void addWord(const QCString &word,bool hiPriority);
99 void write(const QCString &file);
100 private:
101 void addWordRec(const QCString &word,bool hiPrio,bool recurse);
102 std::unordered_map<std::string,int> m_words;
103 std::vector< std::vector< IndexWord> > m_index;
104 std::unordered_map<std::string,int> m_url2IdMap;
105 std::map<int,URL> m_urls;
106 int m_urlIndex = -1;
108};
109
110/** Writes search index that should be used with an externally provided search engine,
111 * e.g. doxyindexer and doxysearch.cgi.
112 */
114{
125
126 public:
128 void setCurrentDoc(const Definition *ctx,const QCString &anchor,bool isSourceFile);
129 void addWord(const QCString &word,bool hiPriority);
130 void write(const QCString &file);
131 private:
132 std::map<std::string,SearchDocEntry> m_docEntries;
134};
135
136/** Abstract proxy interface for non-javascript based search indices.
137 * It forwards calls to either SearchIndex or SearchIndexExternal depending
138 * on the Kind passed during construction.
139 */
141{
142 public:
143 using SearchIndexVariant = std::variant<std::monostate,SearchIndex,SearchIndexExternal>;
146 bool enabled() const { return m_kind!=Disabled; }
147
148 void setCurrentDoc(const Definition *ctx,const QCString &anchor,bool isSourceFile)
149 {
150 if (std::holds_alternative<SearchIndex>(m_variant))
151 {
152 std::get<SearchIndex>(m_variant).setCurrentDoc(ctx,anchor,isSourceFile);
153 }
154 else if (std::holds_alternative<SearchIndexExternal>(m_variant))
155 {
156 std::get<SearchIndexExternal>(m_variant).setCurrentDoc(ctx,anchor,isSourceFile);
157 }
158 }
159 void addWord(const QCString &word,bool hiPriority)
160 {
161 if (std::holds_alternative<SearchIndex>(m_variant))
162 {
163 std::get<SearchIndex>(m_variant).addWord(word,hiPriority);
164 }
165 else if (std::holds_alternative<SearchIndexExternal>(m_variant))
166 {
167 std::get<SearchIndexExternal>(m_variant).addWord(word,hiPriority);
168 }
169 }
170 void write(const QCString &file)
171 {
172 if (std::holds_alternative<SearchIndex>(m_variant))
173 {
174 std::get<SearchIndex>(m_variant).write(file);
175 }
176 else if (std::holds_alternative<SearchIndexExternal>(m_variant))
177 {
178 std::get<SearchIndexExternal>(m_variant).write(file);
179 }
180 }
181 void setKind(Kind k) {
182 m_kind=k;
183 switch (m_kind)
184 {
185 case Disabled: m_variant = std::monostate(); break;
186 case Internal: m_variant = SearchIndex(); break;
187 case External: m_variant = SearchIndexExternal(); break;
188 }
189 }
190 Kind kind() const { return m_kind; }
191 private:
194};
195
196
197#endif
The common base class of all entity definitions found in the sources.
Definition definition.h:76
Class representing a string buffer optimized for growing.
Definition growbuf.h:28
This is an alternative implementation of QCString.
Definition qcstring.h:101
void addUrlIndex(int, bool)
IndexWord(const QCString &word)
Definition searchindex.h:85
QCString word() const
Definition searchindex.h:88
std::unordered_map< int, URLInfo > URLInfoMap
Definition searchindex.h:84
URLInfoMap urls() const
Definition searchindex.h:87
Writes search index that should be used with an externally provided search engine,...
void addWord(const QCString &word, bool hiPriority)
SearchDocEntry * m_current
void write(const QCString &file)
std::map< std::string, SearchDocEntry > m_docEntries
void setCurrentDoc(const Definition *ctx, const QCString &anchor, bool isSourceFile)
Writes search index for doxygen provided server based search engine that uses PHP.
Definition searchindex.h:66
std::map< int, URL > m_urls
void addWordRec(const QCString &word, bool hiPrio, bool recurse)
void addWord(const QCString &word, bool hiPriority)
std::vector< std::vector< IndexWord > > m_index
std::unordered_map< std::string, int > m_words
std::unordered_map< std::string, int > m_url2IdMap
void write(const QCString &file)
void setCurrentDoc(const Definition *ctx, const QCString &anchor, bool isSourceFile)
void addWord(const QCString &word, bool hiPriority)
void setCurrentDoc(const Definition *ctx, const QCString &anchor, bool isSourceFile)
Kind kind() const
SearchIndexVariant m_variant
bool enabled() const
void setKind(Kind k)
std::variant< std::monostate, SearchIndex, SearchIndexExternal > SearchIndexVariant
void write(const QCString &file)
void initSearchIndexer()
void finalizeSearchIndexer()
const Definition * ctx
Definition searchindex.h:49
SIData_CurrentDoc(const Definition *d, const QCString &a, bool b)
Definition searchindex.h:47
SIData_Word(const QCString &w, bool b)
Definition searchindex.h:56
QCString word
Definition searchindex.h:58
URL(const QCString &n, const QCString &u)
Definition searchindex.h:69
URLInfo(int idx, int f)
Definition searchindex.h:76
QCString type
QCString extId
GrowBuf importantText
QCString name
QCString args
GrowBuf normalText
QCString url
std::string_view word
Definition util.cpp:980