Doxygen
searchindex.h
浏览该文件的文档.
1 /******************************************************************************
2  *
3  * Copyright (C) 1997-2020 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 #ifndef SEARCHINDEX_H
17 #define SEARCHINDEX_H
18 
19 #include <memory>
20 #include <vector>
21 #include <map>
22 #include <unordered_map>
23 #include <string>
24 #include <array>
25 #include <functional>
26 
27 #include "qcstring.h"
28 
29 class Definition;
30 
31 /*! Initialize the search indexer */
32 void initSearchIndexer();
33 /*! Cleanup the search indexer */
35 
36 //------- server side search index ----------------------
37 
38 struct URL
39 {
40  URL(QCString n,QCString u) : name(n), url(u) {}
43 };
44 
45 
46 struct URLInfo
47 {
48  URLInfo(int idx,int f) : urlIdx(idx), freq(f) {}
49  int urlIdx;
50  int freq;
51 };
52 
53 class IndexWord
54 {
55  public:
56  using URLInfoMap = std::unordered_map<int,URLInfo>;
58  void addUrlIndex(int,bool);
59  URLInfoMap urls() const { return m_urls; }
60  QCString word() const { return m_word; }
61 
62  private:
65 };
66 
68 {
69  public:
70  enum Kind { Internal, External };
72  virtual ~SearchIndexIntf() {}
73  virtual void setCurrentDoc(const Definition *ctx,const QCString &anchor,bool isSourceFile) = 0;
74  virtual void addWord(const QCString &word,bool hiPriority) = 0;
75  virtual void write(const QCString &file) = 0;
76  Kind kind() const { return m_kind; }
77  private:
79 };
80 
82 {
83  public:
84  SearchIndex();
85  void setCurrentDoc(const Definition *ctx,const QCString &anchor,bool isSourceFile) override;
86  void addWord(const QCString &word,bool hiPriority) override;
87  void write(const QCString &file) override;
88  private:
89  void addWord(const QCString &word,bool hiPrio,bool recurse);
90  std::unordered_map<std::string,int> m_words;
91  std::vector< std::vector< IndexWord> > m_index;
92  std::unordered_map<std::string,int> m_url2IdMap;
93  std::map<int,URL> m_urls;
94  int m_urlIndex = -1;
95 };
96 
97 
99 {
100  struct Private;
101  public:
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);
106  private:
107  std::unique_ptr<Private> p;
108 };
109 
110 //------- client side search index ----------------------
111 
112 #define NUM_SEARCH_INDICES 21
113 
114 QCString searchId(const Definition *d);
115 QCString searchName(const Definition *d);
116 
117 using SearchIndexList = std::vector<const Definition *>;
118 using SearchIndexMap = std::map<std::string,SearchIndexList>;
119 
121 {
122  void add(const std::string &letter,const Definition *def);
124  std::function<QCString()> getText;
126 };
127 
130 const std::array<SearchIndexInfo,NUM_SEARCH_INDICES> &getSearchIndices();
131 
132 #endif
URLInfo
Definition: searchindex.h:46
URL::name
QCString name
Definition: searchindex.h:41
IndexWord
Definition: searchindex.h:53
URL
Definition: searchindex.h:38
IndexWord::IndexWord
IndexWord(QCString word)
Definition: searchindex.cpp:60
SearchIndexInfo::name
QCString name
Definition: searchindex.h:123
Definition
The common base class of all entity definitions found in the sources.
Definition: definition.h:76
SearchIndexExternal::p
std::unique_ptr< Private > p
Definition: searchindex.h:107
SearchIndex::setCurrentDoc
void setCurrentDoc(const Definition *ctx, const QCString &anchor, bool isSourceFile) override
Definition: searchindex.cpp:85
IndexWord::addUrlIndex
void addUrlIndex(int, bool)
Definition: searchindex.cpp:65
SearchIndexInfo
Definition: searchindex.h:120
IndexWord::m_urls
URLInfoMap m_urls
Definition: searchindex.h:64
SearchIndexExternal::SearchIndexExternal
SearchIndexExternal()
Definition: searchindex.cpp:410
SearchIndex::m_urls
std::map< int, URL > m_urls
Definition: searchindex.h:93
SearchIndex::m_urlIndex
int m_urlIndex
Definition: searchindex.h:94
SearchIndexMap
std::map< std::string, SearchIndexList > SearchIndexMap
Definition: searchindex.h:118
SearchIndexIntf::kind
Kind kind() const
Definition: searchindex.h:76
SearchIndex::write
void write(const QCString &file) override
Definition: searchindex.cpp:261
SearchIndexExternal::write
void write(const QCString &file)
Definition: searchindex.cpp:506
URL::URL
URL(QCString n, QCString u)
Definition: searchindex.h:40
IndexWord::word
QCString word() const
Definition: searchindex.h:60
URLInfo::urlIdx
int urlIdx
Definition: searchindex.h:49
getSearchIndices
const std::array< SearchIndexInfo, NUM_SEARCH_INDICES > & getSearchIndices()
Definition: searchindex.cpp:1235
URLInfo::URLInfo
URLInfo(int idx, int f)
Definition: searchindex.h:48
SearchIndexIntf::Internal
@ Internal
Definition: searchindex.h:70
IndexWord::URLInfoMap
std::unordered_map< int, URLInfo > URLInfoMap
Definition: searchindex.h:56
qcstring.h
SearchIndexExternal
Definition: searchindex.h:98
SearchIndexIntf::m_kind
Kind m_kind
Definition: searchindex.h:78
SearchIndexInfo::getText
std::function< QCString()> getText
Definition: searchindex.h:124
IndexWord::m_word
QCString m_word
Definition: searchindex.h:63
IndexWord::urls
URLInfoMap urls() const
Definition: searchindex.h:59
SearchIndexList
std::vector< const Definition * > SearchIndexList
Definition: searchindex.h:117
SearchIndex::SearchIndex
SearchIndex()
Definition: searchindex.cpp:80
URLInfo::freq
int freq
Definition: searchindex.h:50
SearchIndexIntf::~SearchIndexIntf
virtual ~SearchIndexIntf()
Definition: searchindex.h:72
SearchIndexIntf::addWord
virtual void addWord(const QCString &word, bool hiPriority)=0
writeJavaScriptSearchIndex
void writeJavaScriptSearchIndex()
Definition: searchindex.cpp:905
SearchIndexExternal::Private
Definition: searchindex.cpp:404
finalizeSearchIndexer
void finalizeSearchIndexer()
Definition: searchindex.cpp:1264
createJavaScriptSearchIndex
void createJavaScriptSearchIndex()
Definition: searchindex.cpp:751
SearchIndex
Definition: searchindex.h:81
searchName
QCString searchName(const Definition *d)
Definition: searchindex.cpp:546
SearchIndex::m_index
std::vector< std::vector< IndexWord > > m_index
Definition: searchindex.h:91
SearchIndex::m_words
std::unordered_map< std::string, int > m_words
Definition: searchindex.h:90
SearchIndexExternal::setCurrentDoc
void setCurrentDoc(const Definition *ctx, const QCString &anchor, bool isSourceFile)
Definition: searchindex.cpp:471
SearchIndex::addWord
void addWord(const QCString &word, bool hiPriority) override
Definition: searchindex.cpp:241
SearchIndex::m_url2IdMap
std::unordered_map< std::string, int > m_url2IdMap
Definition: searchindex.h:92
SearchIndexExternal::addWord
void addWord(const QCString &word, bool hiPriority)
Definition: searchindex.cpp:497
initSearchIndexer
void initSearchIndexer()
Definition: searchindex.cpp:1242
SearchIndexInfo::symbolMap
SearchIndexMap symbolMap
Definition: searchindex.h:125
SearchIndexIntf::write
virtual void write(const QCString &file)=0
SearchIndexIntf::External
@ External
Definition: searchindex.h:70
SearchIndexIntf::setCurrentDoc
virtual void setCurrentDoc(const Definition *ctx, const QCString &anchor, bool isSourceFile)=0
URL::url
QCString url
Definition: searchindex.h:42
SearchIndexIntf::SearchIndexIntf
SearchIndexIntf(Kind k)
Definition: searchindex.h:71
SearchIndexIntf
Definition: searchindex.h:67
searchId
QCString searchId(const Definition *d)
Definition: searchindex.cpp:553
SearchIndexInfo::add
void add(const std::string &letter, const Definition *def)
Definition: searchindex.cpp:1221
SearchIndexIntf::Kind
Kind
Definition: searchindex.h:70
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108