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
35class Definition;
36
37/*! Initialize the search indexer */
39/*! Cleanup the search indexer */
41
42// --- intermediate data collected by one thread ------
43
45{
46 SIData_CurrentDoc(const Definition *d,const QCString &a,bool b)
47 : ctx(d), anchor(a), isSourceFile(b) {}
48 const Definition *ctx = nullptr;
51};
52
54{
55 SIData_Word(const QCString &w,bool b)
56 : word(w), hiPrio(b) {}
58 bool hiPrio;
59};
60
61//-----------------------------
62
63/** Writes search index for doxygen provided server based search engine that uses PHP. */
65{
66 struct URL
67 {
68 URL(const QCString &n,const QCString &u) : name(n), url(u) {}
71 };
72
73 struct URLInfo
74 {
75 URLInfo(int idx,int f) : urlIdx(idx), freq(f) {}
76 int urlIdx;
77 int freq;
78 };
79
81 {
82 public:
83 using URLInfoMap = std::unordered_map<int,URLInfo>;
85 void addUrlIndex(int,bool);
86 URLInfoMap urls() const { return m_urls; }
87 QCString word() const { return m_word; }
88
89 private:
92 };
93
94 public:
96 void setCurrentDoc(const Definition *ctx,const QCString &anchor,bool isSourceFile);
97 void addWord(const QCString &word,bool hiPriority);
98 void write(const QCString &file);
99 private:
100 void addWordRec(const QCString &word,bool hiPrio,bool recurse);
101 std::unordered_map<std::string,int> m_words;
102 std::vector< std::vector< IndexWord> > m_index;
103 std::unordered_map<std::string,int> m_url2IdMap;
104 std::map<int,URL> m_urls;
105 int m_urlIndex = -1;
107};
108
109/** Writes search index that should be used with an externally provided search engine,
110 * e.g. doxyindexer and doxysearch.cgi.
111 */
113{
124
125 public:
127 void setCurrentDoc(const Definition *ctx,const QCString &anchor,bool isSourceFile);
128 void addWord(const QCString &word,bool hiPriority);
129 void write(const QCString &file);
130 private:
131 std::map<std::string,SearchDocEntry> m_docEntries;
133};
134
135/** Abstract proxy interface for non-javascript based search indices.
136 * It forwards calls to either SearchIndex or SearchIndexExternal depending
137 * on the Kind passed during construction.
138 */
140{
141 public:
142 using SearchIndexVariant = std::variant<std::monostate,SearchIndex,SearchIndexExternal>;
145 bool enabled() const { return m_kind!=Disabled; }
146
147 void setCurrentDoc(const Definition *ctx,const QCString &anchor,bool isSourceFile)
148 {
149 if (std::holds_alternative<SearchIndex>(m_variant))
150 {
151 std::get<SearchIndex>(m_variant).setCurrentDoc(ctx,anchor,isSourceFile);
152 }
153 else if (std::holds_alternative<SearchIndexExternal>(m_variant))
154 {
155 std::get<SearchIndexExternal>(m_variant).setCurrentDoc(ctx,anchor,isSourceFile);
156 }
157 }
158 void addWord(const QCString &word,bool hiPriority)
159 {
160 if (std::holds_alternative<SearchIndex>(m_variant))
161 {
162 std::get<SearchIndex>(m_variant).addWord(word,hiPriority);
163 }
164 else if (std::holds_alternative<SearchIndexExternal>(m_variant))
165 {
166 std::get<SearchIndexExternal>(m_variant).addWord(word,hiPriority);
167 }
168 }
169 void write(const QCString &file)
170 {
171 if (std::holds_alternative<SearchIndex>(m_variant))
172 {
173 std::get<SearchIndex>(m_variant).write(file);
174 }
175 else if (std::holds_alternative<SearchIndexExternal>(m_variant))
176 {
177 std::get<SearchIndexExternal>(m_variant).write(file);
178 }
179 }
180 void setKind(Kind k) {
181 m_kind=k;
182 switch (m_kind)
183 {
184 case Disabled: m_variant = std::monostate(); break;
185 case Internal: m_variant = SearchIndex(); break;
186 case External: m_variant = SearchIndexExternal(); break;
187 }
188 }
189 Kind kind() const { return m_kind; }
190 private:
193};
194
195
196#endif
The common base class of all entity definitions found in the sources.
Definition definition.h:76
This is an alternative implementation of QCString.
Definition qcstring.h:101
void addUrlIndex(int, bool)
IndexWord(const QCString &word)
Definition searchindex.h:84
QCString word() const
Definition searchindex.h:87
std::unordered_map< int, URLInfo > URLInfoMap
Definition searchindex.h:83
URLInfoMap urls() const
Definition searchindex.h:86
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:65
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:48
SIData_CurrentDoc(const Definition *d, const QCString &a, bool b)
Definition searchindex.h:46
SIData_Word(const QCString &w, bool b)
Definition searchindex.h:55
QCString word
Definition searchindex.h:57
URL(const QCString &n, const QCString &u)
Definition searchindex.h:68
URLInfo(int idx, int f)
Definition searchindex.h:75
QCString type
QCString extId
QCString importantText
QCString name
QCString args
QCString normalText
QCString url