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 <map>
26#include <memory>
27#include <string>
28#include <unordered_map>
29#include <variant>
30#include <vector>
31
32#include "dstring.h"
33
34class Definition;
35
36/*! Initialize the search indexer */
38/*! Cleanup the search indexer */
40
41// --- intermediate data collected by one thread ------
42
44{
45 SIData_CurrentDoc(const Definition *d,const DString &a,bool b)
46 : ctx(d), anchor(a), isSourceFile(b) {}
47 const Definition *ctx = nullptr;
50};
51
53{
54 SIData_Word(const DString &w,bool b)
55 : word(w), hiPrio(b) {}
57 bool hiPrio;
58};
59
60//-----------------------------
61
62/** Writes search index for doxygen provided server based search engine that uses PHP. */
64{
65 struct URL
66 {
67 URL(const DString &n,const DString &u) : name(n), url(u) {}
70 };
71
72 struct URLInfo
73 {
74 URLInfo(int idx,int f) : urlIdx(idx), freq(f) {}
75 int urlIdx;
76 int freq;
77 };
78
80 {
81 public:
82 using URLInfoMap = std::unordered_map<int,URLInfo>;
84 void addUrlIndex(int,bool);
85 URLInfoMap urls() const { return m_urls; }
86 DString word() const { return m_word; }
87
88 private:
91 };
92
93 public:
95 void setCurrentDoc(const Definition *ctx,const DString &anchor,bool isSourceFile);
96 void addWord(const DString &word,bool hiPriority);
97 void write(const DString &file);
98 private:
99 void addWordRec(const DString &word,bool hiPrio,bool recurse);
100 std::unordered_map<std::string,int> m_words;
101 std::vector< std::vector< IndexWord> > m_index;
102 std::unordered_map<std::string,int> m_url2IdMap;
103 std::map<int,URL> m_urls;
104 int m_urlIndex = -1;
106};
107
108/** Writes search index that should be used with an externally provided search engine,
109 * e.g\. doxyindexer and doxysearch.cgi.
110 */
112{
123
124 public:
126 void setCurrentDoc(const Definition *ctx,const DString &anchor,bool isSourceFile);
127 void addWord(const DString &word,bool hiPriority);
128 void write(const DString &file);
129 private:
130 std::map<std::string,SearchDocEntry> m_docEntries;
132};
133
134/** Abstract proxy interface for non-javascript based search indices.
135 * It forwards calls to either SearchIndex or SearchIndexExternal depending
136 * on the Kind passed during construction.
137 */
139{
140 public:
141 using SearchIndexVariant = std::variant<std::monostate,SearchIndex,SearchIndexExternal>;
144 bool enabled() const { return m_kind!=Disabled; }
145
146 void setCurrentDoc(const Definition *ctx,const DString &anchor,bool isSourceFile)
147 {
148 if (std::holds_alternative<SearchIndex>(m_variant))
149 {
150 std::get<SearchIndex>(m_variant).setCurrentDoc(ctx,anchor,isSourceFile);
151 }
152 else if (std::holds_alternative<SearchIndexExternal>(m_variant))
153 {
154 std::get<SearchIndexExternal>(m_variant).setCurrentDoc(ctx,anchor,isSourceFile);
155 }
156 }
157 void addWord(const DString &word,bool hiPriority)
158 {
159 if (std::holds_alternative<SearchIndex>(m_variant))
160 {
161 std::get<SearchIndex>(m_variant).addWord(word,hiPriority);
162 }
163 else if (std::holds_alternative<SearchIndexExternal>(m_variant))
164 {
165 std::get<SearchIndexExternal>(m_variant).addWord(word,hiPriority);
166 }
167 }
168 void write(const DString &file)
169 {
170 if (std::holds_alternative<SearchIndex>(m_variant))
171 {
172 std::get<SearchIndex>(m_variant).write(file);
173 }
174 else if (std::holds_alternative<SearchIndexExternal>(m_variant))
175 {
176 std::get<SearchIndexExternal>(m_variant).write(file);
177 }
178 }
179 void setKind(Kind k) {
180 m_kind=k;
181 switch (m_kind)
182 {
183 case Disabled: m_variant = std::monostate(); break;
184 case Internal: m_variant = SearchIndex(); break;
185 case External: m_variant = SearchIndexExternal(); break;
186 }
187 }
188 Kind kind() const { return m_kind; }
189 private:
192};
193
194
195#endif
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
The common base class of all entity definitions found in the sources.
Definition definition.h:77
DString word() const
Definition searchindex.h:86
void addUrlIndex(int, bool)
std::unordered_map< int, URLInfo > URLInfoMap
Definition searchindex.h:82
IndexWord(const DString &word)
Definition searchindex.h:83
URLInfoMap urls() const
Definition searchindex.h:85
Writes search index that should be used with an externally provided search engine,...
void setCurrentDoc(const Definition *ctx, const DString &anchor, bool isSourceFile)
SearchDocEntry * m_current
void write(const DString &file)
std::map< std::string, SearchDocEntry > m_docEntries
void addWord(const DString &word, bool hiPriority)
Writes search index for doxygen provided server based search engine that uses PHP.
Definition searchindex.h:64
void addWord(const DString &word, bool hiPriority)
std::map< int, URL > m_urls
std::vector< std::vector< IndexWord > > m_index
void write(const DString &file)
std::unordered_map< std::string, int > m_words
std::unordered_map< std::string, int > m_url2IdMap
void addWordRec(const DString &word, bool hiPrio, bool recurse)
void setCurrentDoc(const Definition *ctx, const DString &anchor, bool isSourceFile)
void addWord(const DString &word, bool hiPriority)
void setCurrentDoc(const Definition *ctx, const DString &anchor, bool isSourceFile)
Kind kind() const
SearchIndexVariant m_variant
bool enabled() const
void setKind(Kind k)
void write(const DString &file)
std::variant< std::monostate, SearchIndex, SearchIndexExternal > SearchIndexVariant
void initSearchIndexer()
void finalizeSearchIndexer()
const Definition * ctx
Definition searchindex.h:47
SIData_CurrentDoc(const Definition *d, const DString &a, bool b)
Definition searchindex.h:45
DString word
Definition searchindex.h:56
SIData_Word(const DString &w, bool b)
Definition searchindex.h:54
URL(const DString &n, const DString &u)
Definition searchindex.h:67
URLInfo(int idx, int f)
Definition searchindex.h:74
DString extId
DString name
DString type
DString normalText
DString url
DString importantText
DString args