Doxygen
SearchIndex类 参考

#include <searchindex.h>

+ 类 SearchIndex 继承关系图:
+ SearchIndex 的协作图:

Public 成员函数

 SearchIndex ()
 
void setCurrentDoc (const Definition *ctx, const QCString &anchor, bool isSourceFile) override
 
void addWord (const QCString &word, bool hiPriority) override
 
void write (const QCString &file) override
 
- Public 成员函数 继承自 SearchIndexIntf
 SearchIndexIntf (Kind k)
 
virtual ~SearchIndexIntf ()
 
Kind kind () const
 

Private 成员函数

void addWord (const QCString &word, bool hiPrio, bool recurse)
 

Private 属性

std::unordered_map< std::string, int > m_words
 
std::vector< std::vector< IndexWord > > m_index
 
std::unordered_map< std::string, int > m_url2IdMap
 
std::map< int, URLm_urls
 
int m_urlIndex = -1
 

额外继承的成员函数

- Public 类型 继承自 SearchIndexIntf
enum  Kind { Internal, External }
 

详细描述

在文件 searchindex.h81 行定义.

构造及析构函数说明

◆ SearchIndex()

SearchIndex::SearchIndex ( )

在文件 searchindex.cpp80 行定义.

81 {
82  m_index.resize(numIndexEntries);
83 }

引用了 m_index , 以及 numIndexEntries.

成员函数说明

◆ addWord() [1/2]

void SearchIndex::addWord ( const QCString word,
bool  hiPrio,
bool  recurse 
)
private

在文件 searchindex.cpp199 行定义.

200 {
201  if (word.isEmpty()) return;
202  QCString wStr = QCString(word).lower();
203  //printf("SearchIndex::addWord(%s,%d) wStr=%s\n",word,hiPriority,qPrint(wStr));
204  int idx=charsToIndex(wStr);
205  if (idx<0 || idx>=static_cast<int>(m_index.size())) return;
206  auto it = m_words.find(wStr.str());
207  if (it==m_words.end())
208  {
209  //fprintf(stderr,"addWord(%s) at index %d\n",word,idx);
210  m_index[idx].push_back(IndexWord(wStr));
211  it = m_words.insert({ wStr.str(), static_cast<int>(m_index[idx].size())-1 }).first;
212  }
213  m_index[idx][it->second].addUrlIndex(m_urlIndex,hiPriority);
214  int i;
215  bool found=FALSE;
216  if (!recurse) // the first time we check if we can strip the prefix
217  {
218  i=getPrefixIndex(word);
219  if (i>0)
220  {
221  addWord(word.data()+i,hiPriority,TRUE);
222  found=TRUE;
223  }
224  }
225  if (!found) // no prefix stripped
226  {
227  i=0;
228  while (word[i]!=0 &&
229  !((word[i]=='_' || word[i]==':' || (word[i]>='a' && word[i]<='z')) && // [_a-z:]
230  (word[i+1]>='A' && word[i+1]<='Z'))) // [A-Z]
231  {
232  i++;
233  }
234  if (word[i]!=0 && i>=1)
235  {
236  addWord(word.data()+i+1,hiPriority,TRUE);
237  }
238  }
239 }

引用了 addWord(), charsToIndex(), QCString::data(), FALSE, getPrefixIndex(), QCString::isEmpty(), QCString::lower(), m_index, m_urlIndex, m_words, QCString::str() , 以及 TRUE.

◆ addWord() [2/2]

void SearchIndex::addWord ( const QCString word,
bool  hiPriority 
)
overridevirtual

实现了 SearchIndexIntf.

在文件 searchindex.cpp241 行定义.

242 {
243  addWord(word,hiPriority,FALSE);
244 }

引用了 FALSE.

被这些函数引用 addWord().

◆ setCurrentDoc()

void SearchIndex::setCurrentDoc ( const Definition ctx,
const QCString anchor,
bool  isSourceFile 
)
overridevirtual

实现了 SearchIndexIntf.

在文件 searchindex.cpp85 行定义.

86 {
87  if (ctx==0) return;
88  assert(!isSourceFile || ctx->definitionType()==Definition::TypeFile);
89  //printf("SearchIndex::setCurrentDoc(%s,%s,%s)\n",name,baseName,anchor);
90  QCString url=isSourceFile ? (toFileDef(ctx))->getSourceFileBase() : ctx->getOutputFileBase();
91  url+=Config_getString(HTML_FILE_EXTENSION);
92  QCString baseUrl = url;
93  if (!anchor.isEmpty()) url+=QCString("#")+anchor;
94  if (!isSourceFile) baseUrl=url;
97  {
98  const MemberDef *md = toMemberDef(ctx);
99  name.prepend((md->getLanguage()==SrcLangExt_Fortran ?
102  }
103  else // compound type
104  {
105  SrcLangExt lang = ctx->getLanguage();
107  if (sep!="::")
108  {
109  name = substitute(name,"::",sep);
110  }
111  switch (ctx->definitionType())
112  {
114  {
115  const PageDef *pd = toPageDef(ctx);
116  if (pd->hasTitle())
117  {
118  name = theTranslator->trPage(TRUE,TRUE)+" "+pd->title();
119  }
120  else
121  {
122  name = theTranslator->trPage(TRUE,TRUE)+" "+pd->name();
123  }
124  }
125  break;
127  {
128  const ClassDef *cd = toClassDef(ctx);
129  name.prepend(cd->compoundTypeString()+" ");
130  }
131  break;
133  {
134  if (lang==SrcLangExt_Java || lang==SrcLangExt_CSharp)
135  {
137  }
138  else if (lang==SrcLangExt_Fortran)
139  {
140  name.prepend(theTranslator->trModule(TRUE,TRUE)+" ");
141  }
142  else
143  {
144  name.prepend(theTranslator->trNamespace(TRUE,TRUE)+" ");
145  }
146  }
147  break;
149  {
150  const GroupDef *gd = toGroupDef(ctx);
151  if (!gd->groupTitle().isEmpty())
152  {
154  }
155  else
156  {
157  name.prepend(theTranslator->trGroup(TRUE,TRUE)+" ");
158  }
159  }
160  break;
161  default:
162  break;
163  }
164  }
165 
166  auto it = m_url2IdMap.find(baseUrl.str());
167  if (it == m_url2IdMap.end())
168  {
169  ++m_urlIndex;
170  m_url2IdMap.insert(std::make_pair(baseUrl.str(),m_urlIndex));
171  m_urls.insert(std::make_pair(m_urlIndex,URL(name,url)));
172  }
173  else
174  {
175  m_urls.insert(std::make_pair(it->second,URL(name,url)));
176  }
177 }

引用了 ClassDef::compoundTypeString(), Config_getString, Definition::definitionType(), Definition::getLanguage(), getLanguageSpecificSeparator(), Definition::getOutputFileBase(), GroupDef::groupTitle(), PageDef::hasTitle(), QCString::isEmpty(), m_url2IdMap, m_urlIndex, m_urls, Definition::name(), QCString::prepend(), Definition::qualifiedName(), SrcLangExt_CSharp, SrcLangExt_Fortran, SrcLangExt_Java, QCString::str(), substitute(), theTranslator, PageDef::title(), toClassDef(), toFileDef(), toGroupDef(), toMemberDef(), toPageDef(), Translator::trGroup(), Translator::trMember(), Translator::trModule(), Translator::trNamespace(), Translator::trPackage(), Translator::trPage(), Translator::trSubprogram(), TRUE, Definition::TypeClass, Definition::TypeFile, Definition::TypeGroup, Definition::TypeMember, Definition::TypeNamespace , 以及 Definition::TypePage.

◆ write()

void SearchIndex::write ( const QCString file)
overridevirtual

实现了 SearchIndexIntf.

在文件 searchindex.cpp261 行定义.

262 {
263  size_t i;
264  size_t size=4; // for the header
265  size+=4*numIndexEntries; // for the index
266  size_t wordsOffset = size;
267  // first pass: compute the size of the wordlist
268  for (i=0;i<numIndexEntries;i++)
269  {
270  const auto &wlist = m_index[i];
271  if (!wlist.empty())
272  {
273  for (const auto &iw : wlist)
274  {
275  int ws = iw.word().length()+1;
276  size+=ws+4; // word + url info list offset
277  }
278  size+=1; // zero list terminator
279  }
280  }
281 
282  // second pass: compute the offsets in the index
283  size_t indexOffsets[numIndexEntries];
284  size_t offset=wordsOffset;
285  for (i=0;i<numIndexEntries;i++)
286  {
287  const auto &wlist = m_index[i];
288  if (!wlist.empty())
289  {
290  indexOffsets[i]=offset;
291  for (const auto &iw : wlist)
292  {
293  offset+= iw.word().length()+1;
294  offset+=4; // word + offset to url info array
295  }
296  offset+=1; // zero list terminator
297  }
298  else
299  {
300  indexOffsets[i]=0;
301  }
302  }
303  size_t padding = size;
304  size = (size+3)&~3; // round up to 4 byte boundary
305  padding = size - padding;
306 
307  std::vector<size_t> wordStatOffsets(m_words.size());
308 
309  int count=0;
310 
311  // third pass: compute offset to stats info for each word
312  for (i=0;i<numIndexEntries;i++)
313  {
314  const auto &wlist = m_index[i];
315  if (!wlist.empty())
316  {
317  for (const auto &iw : wlist)
318  {
319  //printf("wordStatOffsets[%d]=%d\n",count,size);
320  wordStatOffsets[count++] = size;
321  size+=4 + iw.urls().size() * 8; // count + (url_index,freq) per url
322  }
323  }
324  }
325  std::vector<size_t> urlOffsets(m_urls.size());
326  for (const auto &udi : m_urls)
327  {
328  urlOffsets[udi.first]=size;
329  size+=udi.second.name.length()+1+
330  udi.second.url.length()+1;
331  }
332 
333  //printf("Total size %x bytes (word=%x stats=%x urls=%x)\n",size,wordsOffset,statsOffset,urlsOffset);
334  std::ofstream f(fileName.str(),std::ofstream::out | std::ofstream::binary);
335  if (f.is_open())
336  {
337  // write header
338  f.put('D'); f.put('O'); f.put('X'); f.put('S');
339  // write index
340  for (i=0;i<numIndexEntries;i++)
341  {
342  writeInt(f,indexOffsets[i]);
343  }
344  // write word lists
345  count=0;
346  for (i=0;i<numIndexEntries;i++)
347  {
348  const auto &wlist = m_index[i];
349  if (!wlist.empty())
350  {
351  for (const auto &iw : wlist)
352  {
353  writeString(f,iw.word());
354  writeInt(f,wordStatOffsets[count++]);
355  }
356  f.put(0);
357  }
358  }
359  // write extra padding bytes
360  for (i=0;i<padding;i++) f.put(0);
361  // write word statistics
362  for (i=0;i<numIndexEntries;i++)
363  {
364  const auto &wlist = m_index[i];
365  if (!wlist.empty())
366  {
367  for (const auto &iw : wlist)
368  {
369  size_t numUrls = iw.urls().size();
370  writeInt(f,numUrls);
371  for (const auto &ui : iw.urls())
372  {
373  writeInt(f,urlOffsets[ui.second.urlIdx]);
374  writeInt(f,ui.second.freq);
375  }
376  }
377  }
378  }
379  // write urls
380  for (const auto &udi : m_urls)
381  {
382  writeString(f,udi.second.name);
383  writeString(f,udi.second.url);
384  }
385  }
386 
387 }

引用了 m_index, m_urls, m_words, numIndexEntries, QCString::str(), writeInt() , 以及 writeString().

类成员变量说明

◆ m_index

std::vector< std::vector< IndexWord> > SearchIndex::m_index
private

在文件 searchindex.h91 行定义.

被这些函数引用 addWord(), SearchIndex() , 以及 write().

◆ m_url2IdMap

std::unordered_map<std::string,int> SearchIndex::m_url2IdMap
private

在文件 searchindex.h92 行定义.

被这些函数引用 setCurrentDoc().

◆ m_urlIndex

int SearchIndex::m_urlIndex = -1
private

在文件 searchindex.h94 行定义.

被这些函数引用 addWord() , 以及 setCurrentDoc().

◆ m_urls

std::map<int,URL> SearchIndex::m_urls
private

在文件 searchindex.h93 行定义.

被这些函数引用 setCurrentDoc() , 以及 write().

◆ m_words

std::unordered_map<std::string,int> SearchIndex::m_words
private

在文件 searchindex.h90 行定义.

被这些函数引用 addWord() , 以及 write().


该类的文档由以下文件生成:
Translator::trSubprogram
virtual QCString trSubprogram(bool first_capital, bool singular)=0
IndexWord
Definition: searchindex.h:53
numIndexEntries
const size_t numIndexEntries
Definition: searchindex.cpp:56
Rtf_Style_Default::name
const char * name
Definition: rtfstyle.h:40
toGroupDef
GroupDef * toGroupDef(Definition *d)
Definition: groupdef.cpp:1766
URL
Definition: searchindex.h:38
Definition::TypeMember
@ TypeMember
Definition: definition.h:90
ClassDef::compoundTypeString
virtual QCString compoundTypeString() const =0
Returns the type of compound as a string
QCString::isEmpty
bool isEmpty() const
Returns TRUE iff the string is empty
Definition: qcstring.h:144
SearchIndex::m_urls
std::map< int, URL > m_urls
Definition: searchindex.h:93
Translator::trPackage
virtual QCString trPackage(const QCString &name)=0
GroupDef::groupTitle
virtual QCString groupTitle() const =0
Definition::TypePage
@ TypePage
Definition: definition.h:93
SearchIndex::m_urlIndex
int m_urlIndex
Definition: searchindex.h:94
toMemberDef
MemberDef * toMemberDef(Definition *d)
Definition: memberdef.cpp:6088
writeInt
static void writeInt(std::ostream &f, size_t index)
Definition: searchindex.cpp:246
SrcLangExt
SrcLangExt
Language as given by extension
Definition: types.h:41
QCString::str
std::string str() const
Definition: qcstring.h:442
charsToIndex
static int charsToIndex(const QCString &word)
Definition: searchindex.cpp:179
Definition::TypeGroup
@ TypeGroup
Definition: definition.h:91
SrcLangExt_Java
@ SrcLangExt_Java
Definition: types.h:45
SearchIndexIntf::Internal
@ Internal
Definition: searchindex.h:70
Definition::getLanguage
virtual SrcLangExt getLanguage() const =0
Returns the programming language this definition was written in.
toPageDef
PageDef * toPageDef(Definition *d)
Definition: pagedef.cpp:408
PageDef
A model of a page symbol.
Definition: pagedef.h:25
GroupDef
A model of a group of symbols.
Definition: groupdef.h:49
Definition::qualifiedName
virtual QCString qualifiedName() const =0
MemberDef
A model of a class/file/namespace member symbol.
Definition: memberdef.h:45
Definition::TypeNamespace
@ TypeNamespace
Definition: definition.h:89
ClassDef
A abstract class representing of a compound symbol.
Definition: classdef.h:103
Definition::TypeFile
@ TypeFile
Definition: definition.h:88
theTranslator
Translator * theTranslator
Definition: language.cpp:156
Definition::name
virtual QCString name() const =0
QCString::lower
QCString lower() const
Definition: qcstring.h:232
getLanguageSpecificSeparator
QCString getLanguageSpecificSeparator(SrcLangExt lang, bool classScope)
Returns the scope separator to use given the programming language lang
Definition: util.cpp:6545
TRUE
#define TRUE
Definition: qcstring.h:36
SrcLangExt_Fortran
@ SrcLangExt_Fortran
Definition: types.h:53
PageDef::hasTitle
virtual bool hasTitle() const =0
SearchIndex::m_index
std::vector< std::vector< IndexWord > > m_index
Definition: searchindex.h:91
toClassDef
ClassDef * toClassDef(Definition *d)
Definition: classdef.cpp:4907
SearchIndex::m_words
std::unordered_map< std::string, int > m_words
Definition: searchindex.h:90
SrcLangExt_CSharp
@ SrcLangExt_CSharp
Definition: types.h:46
SearchIndex::addWord
void addWord(const QCString &word, bool hiPriority) override
Definition: searchindex.cpp:241
Definition::TypeClass
@ TypeClass
Definition: definition.h:87
Definition::definitionType
virtual DefType definitionType() const =0
SearchIndex::m_url2IdMap
std::unordered_map< std::string, int > m_url2IdMap
Definition: searchindex.h:92
getPrefixIndex
int getPrefixIndex(const QCString &name)
Definition: util.cpp:3357
Translator::trNamespace
virtual QCString trNamespace(bool first_capital, bool singular)=0
substitute
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition: qcstring.cpp:465
Translator::trPage
virtual QCString trPage(bool first_capital, bool singular)=0
Translator::trModule
virtual QCString trModule(bool first_capital, bool singular)=0
Config_getString
#define Config_getString(name)
Definition: config.h:32
writeString
static void writeString(std::ostream &f, const QCString &s)
Definition: searchindex.cpp:254
SearchIndexIntf::SearchIndexIntf
SearchIndexIntf(Kind k)
Definition: searchindex.h:71
QCString::data
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string
Definition: qcstring.h:153
PageDef::title
virtual QCString title() const =0
toFileDef
FileDef * toFileDef(Definition *d)
Definition: filedef.cpp:1778
Translator::trMember
virtual QCString trMember(bool first_capital, bool singular)=0
Translator::trGroup
virtual QCString trGroup(bool first_capital, bool singular)=0
FALSE
#define FALSE
Definition: qcstring.h:33
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108