Public Member Functions | Private Member Functions | Private Attributes | List of all members
SearchIndex Class Reference

#include <searchindex.h>

Inheritance diagram for SearchIndex:
SearchIndexIntf

Public Member Functions

 SearchIndex ()
 
void setCurrentDoc (Definition *ctx, const char *anchor, bool isSourceFile)
 
void addWord (const char *word, bool hiPriority)
 
void write (const char *file)
 
- Public Member Functions inherited from SearchIndexIntf
 SearchIndexIntf (Kind k)
 
virtual ~SearchIndexIntf ()
 
Kind kind () const
 

Private Member Functions

void addWord (const char *word, bool hiPrio, bool recurse)
 

Private Attributes

QDict< IndexWordm_words
 
QVector< QList< IndexWord > > m_index
 
QDict< int > m_url2IdMap
 
QIntDict< URLm_urls
 
int m_urlIndex
 

Additional Inherited Members

- Public Types inherited from SearchIndexIntf
enum  Kind { Internal, External }
 

Detailed Description

Definition at line 83 of file searchindex.h.

Constructor & Destructor Documentation

SearchIndex::SearchIndex ( )

Definition at line 78 of file searchindex.cpp.

79  m_words(328829), m_index(numIndexEntries), m_url2IdMap(10007), m_urls(10007), m_urlIndex(-1)
80 {
81  int i;
82  m_words.setAutoDelete(TRUE);
83  m_url2IdMap.setAutoDelete(TRUE);
86  for (i=0;i<numIndexEntries;i++) m_index.insert(i,new QList<IndexWord>);
87 }
QDict< int > m_url2IdMap
Definition: searchindex.h:94
QVector< QList< IndexWord > > m_index
Definition: searchindex.h:93
QIntDict< URL > m_urls
Definition: searchindex.h:95
int m_urlIndex
Definition: searchindex.h:96
const int numIndexEntries
Definition: searchindex.cpp:52
SearchIndexIntf(Kind k)
Definition: searchindex.h:73
void setAutoDelete(bool enable)
Definition: qcollection.h:55
QDict< IndexWord > m_words
Definition: searchindex.h:92
const bool TRUE
Definition: qglobal.h:371
bool insert(uint i, const type *d)
Definition: qvector.h:61
Definition: qlist.h:54

Member Function Documentation

void SearchIndex::addWord ( const char *  word,
bool  hiPriority 
)
virtual

Implements SearchIndexIntf.

Definition at line 242 of file searchindex.cpp.

243 {
244  addWord(word,hiPriority,FALSE);
245 }
const bool FALSE
Definition: qglobal.h:370
void addWord(const char *word, bool hiPriority)
union ptb::content::word::word word
void SearchIndex::addWord ( const char *  word,
bool  hiPrio,
bool  recurse 
)
private

Definition at line 205 of file searchindex.cpp.

206 {
207  static QRegExp nextPart("[_a-z:][A-Z]");
208  if (word==0 || word[0]=='\0') return;
209  QCString wStr = QCString(word).lower();
210  //printf("SearchIndex::addWord(%s,%d) wStr=%s\n",word,hiPriority,wStr.data());
211  IndexWord *w = m_words[wStr];
212  if (w==0)
213  {
214  int idx=charsToIndex(wStr);
215  //fprintf(stderr,"addWord(%s) at index %d\n",word,idx);
216  if (idx<0) return;
217  w = new IndexWord(wStr);
218  m_index[idx]->append(w);
219  m_words.insert(wStr,w);
220  }
221  w->addUrlIndex(m_urlIndex,hiPriority);
222  int i;
223  bool found=FALSE;
224  if (!recurse) // the first time we check if we can strip the prefix
225  {
226  i=getPrefixIndex(word);
227  if (i>0)
228  {
229  addWord(word+i,hiPriority,TRUE);
230  found=TRUE;
231  }
232  }
233  if (!found) // no prefix stripped
234  {
235  if ((i=nextPart.match(word))>=1)
236  {
237  addWord(word+i+1,hiPriority,TRUE);
238  }
239  }
240 }
The QRegExp class provides pattern matching using regular expressions or wildcards.
Definition: qregexp.h:46
static int charsToIndex(const char *word)
QVector< QList< IndexWord > > m_index
Definition: searchindex.h:93
const bool FALSE
Definition: qglobal.h:370
int m_urlIndex
Definition: searchindex.h:96
int getPrefixIndex(const QCString &name)
Definition: util.cpp:5144
void addWord(const char *word, bool hiPriority)
QDict< IndexWord > m_words
Definition: searchindex.h:92
void addUrlIndex(int, bool)
Definition: searchindex.cpp:62
QCString lower() const
Definition: qcstring.cpp:263
union ptb::content::word::word word
const bool TRUE
Definition: qglobal.h:371
void SearchIndex::setCurrentDoc ( Definition ctx,
const char *  anchor,
bool  isSourceFile 
)
virtual

Implements SearchIndexIntf.

Definition at line 89 of file searchindex.cpp.

90 {
91  if (ctx==0) return;
92  assert(!isSourceFile || ctx->definitionType()==Definition::TypeFile);
93  //printf("SearchIndex::setCurrentDoc(%s,%s,%s)\n",name,baseName,anchor);
94  QCString url=isSourceFile ? ((FileDef*)ctx)->getSourceFileBase() : ctx->getOutputFileBase();
95  url+=Config_getString("HTML_FILE_EXTENSION");
96  QCString baseUrl = url;
97  if (anchor) url+=QCString("#")+anchor;
98  if (!isSourceFile) baseUrl=url;
101  {
102  MemberDef *md = (MemberDef *)ctx;
103  name.prepend((md->getLanguage()==SrcLangExt_Fortran ?
106  }
107  else // compound type
108  {
109  SrcLangExt lang = ctx->getLanguage();
111  if (sep!="::")
112  {
113  name = substitute(name,"::",sep);
114  }
115  switch (ctx->definitionType())
116  {
118  {
119  PageDef *pd = (PageDef *)ctx;
120  if (!pd->title().isEmpty())
121  {
122  name = theTranslator->trPage(TRUE,TRUE)+" "+pd->title();
123  }
124  else
125  {
126  name = theTranslator->trPage(TRUE,TRUE)+" "+pd->name();
127  }
128  }
129  break;
131  {
132  ClassDef *cd = (ClassDef *)ctx;
133  name.prepend(cd->compoundTypeString()+" ");
134  }
135  break;
137  {
138  if (lang==SrcLangExt_Java || lang==SrcLangExt_CSharp)
139  {
140  name = theTranslator->trPackage(name);
141  }
142  else if (lang==SrcLangExt_Fortran)
143  {
144  name.prepend(theTranslator->trModule(TRUE,TRUE)+" ");
145  }
146  else
147  {
149  }
150  }
151  break;
153  {
154  GroupDef *gd = (GroupDef *)ctx;
155  if (gd->groupTitle())
156  {
157  name = theTranslator->trGroup(TRUE,TRUE)+" "+gd->groupTitle();
158  }
159  else
160  {
161  name.prepend(theTranslator->trGroup(TRUE,TRUE)+" ");
162  }
163  }
164  break;
165  default:
166  break;
167  }
168  }
169 
170  int *pIndex = m_url2IdMap.find(baseUrl);
171  if (pIndex==0)
172  {
173  ++m_urlIndex;
174  m_url2IdMap.insert(baseUrl,new int(m_urlIndex));
175  m_urls.insert(m_urlIndex,new URL(name,url));
176  }
177  else
178  {
179  m_urls.insert(*pIndex,new URL(name,url));
180  }
181 }
static QCString name
Definition: declinfo.cpp:673
bool isEmpty() const
Definition: qcstring.h:189
QCString title() const
Definition: pagedef.h:54
QCString compoundTypeString() const
Definition: classdef.cpp:3499
QDict< int > m_url2IdMap
Definition: searchindex.h:94
virtual QCString getOutputFileBase() const =0
const char * groupTitle() const
Definition: groupdef.h:54
SrcLangExt
Definition: types.h:41
virtual QCString trModule(bool first_capital, bool singular)=0
virtual QCString trSubprogram(bool first_capital, bool singular)=0
virtual DefType definitionType() const =0
QCString getLanguageSpecificSeparator(SrcLangExt lang, bool classScope)
Definition: util.cpp:8065
void insert(long k, const type *d)
Definition: qintdict.h:57
QIntDict< URL > m_urls
Definition: searchindex.h:95
const QCString & name() const
Definition: definition.h:114
SrcLangExt getLanguage() const
int m_urlIndex
Definition: searchindex.h:96
QCString & prepend(const char *s)
Definition: qcstring.cpp:387
#define Config_getString(val)
Definition: config.cpp:660
virtual QCString trGroup(bool first_capital, bool singular)=0
virtual QCString qualifiedName() const
virtual QCString trPage(bool first_capital, bool singular)=0
virtual QCString trPackage(const char *name)=0
A model of a page symbol.
Definition: pagedef.h:29
virtual QCString trNamespace(bool first_capital, bool singular)=0
Translator * theTranslator
Definition: language.cpp:157
virtual QCString trMember(bool first_capital, bool singular)=0
const bool TRUE
Definition: qglobal.h:371
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition: util.cpp:5088
void SearchIndex::write ( const char *  file)
virtual

Implements SearchIndexIntf.

Definition at line 262 of file searchindex.cpp.

263 {
264  int i;
265  int size=4; // for the header
266  size+=4*numIndexEntries; // for the index
267  int wordsOffset = size;
268  // first pass: compute the size of the wordlist
269  for (i=0;i<numIndexEntries;i++)
270  {
271  QList<IndexWord> *wlist = m_index[i];
272  if (!wlist->isEmpty())
273  {
274  QListIterator<IndexWord> iwi(*wlist);
275  IndexWord *iw;
276  for (iwi.toFirst();(iw=iwi.current());++iwi)
277  {
278  int ws = iw->word().length()+1;
279  size+=ws+4; // word + url info list offset
280  }
281  size+=1; // zero list terminator
282  }
283  }
284 
285  // second pass: compute the offsets in the index
286  int indexOffsets[numIndexEntries];
287  int offset=wordsOffset;
288  for (i=0;i<numIndexEntries;i++)
289  {
290  QList<IndexWord> *wlist = m_index[i];
291  if (!wlist->isEmpty())
292  {
293  indexOffsets[i]=offset;
294  QListIterator<IndexWord> iwi(*wlist);
295  IndexWord *iw;
296  for (iwi.toFirst();(iw=iwi.current());++iwi)
297  {
298  offset+= iw->word().length()+1;
299  offset+=4; // word + offset to url info array
300  }
301  offset+=1; // zero list terminator
302  }
303  else
304  {
305  indexOffsets[i]=0;
306  }
307  }
308  int padding = size;
309  size = (size+3)&~3; // round up to 4 byte boundary
310  padding = size - padding;
311 
312  //int statsOffset = size;
313  //IndexWord *iw;
314  int *wordStatOffsets = new int[m_words.count()];
315 
316  int count=0;
317 
318  // third pass: compute offset to stats info for each word
319  for (i=0;i<numIndexEntries;i++)
320  {
321  QList<IndexWord> *wlist = m_index[i];
322  if (!wlist->isEmpty())
323  {
324  QListIterator<IndexWord> iwi(*wlist);
325  IndexWord *iw;
326  for (iwi.toFirst();(iw=iwi.current());++iwi)
327  {
328  //printf("wordStatOffsets[%d]=%d\n",count,size);
329  wordStatOffsets[count++] = size;
330  size+=4+iw->urls().count()*8; // count + (url_index,freq) per url
331  }
332  }
333  }
334  int *urlOffsets = new int[m_urls.count()];
335  //int urlsOffset = size;
337  URL *url;
338  for (udi.toFirst();(url=udi.current());++udi)
339  {
340  urlOffsets[udi.currentKey()]=size;
341  size+=url->name.length()+1+
342  url->url.length()+1;
343  }
344  //printf("Total size %x bytes (word=%x stats=%x urls=%x)\n",size,wordsOffset,statsOffset,urlsOffset);
345  QFile f(fileName);
346  if (f.open(IO_WriteOnly))
347  {
348  // write header
349  f.putch('D'); f.putch('O'); f.putch('X'); f.putch('S');
350  // write index
351  for (i=0;i<numIndexEntries;i++)
352  {
353  writeInt(f,indexOffsets[i]);
354  }
355  // write word lists
356  count=0;
357  for (i=0;i<numIndexEntries;i++)
358  {
359  QList<IndexWord> *wlist = m_index[i];
360  if (!wlist->isEmpty())
361  {
362  QListIterator<IndexWord> iwi(*wlist);
363  IndexWord *iw;
364  for (iwi.toFirst();(iw=iwi.current());++iwi)
365  {
366  writeString(f,iw->word());
367  writeInt(f,wordStatOffsets[count++]);
368  }
369  f.putch(0);
370  }
371  }
372  // write extra padding bytes
373  for (i=0;i<padding;i++) f.putch(0);
374  // write word statistics
375  for (i=0;i<numIndexEntries;i++)
376  {
377  QList<IndexWord> *wlist = m_index[i];
378  if (!wlist->isEmpty())
379  {
380  QListIterator<IndexWord> iwi(*wlist);
381  IndexWord *iw;
382  for (iwi.toFirst();(iw=iwi.current());++iwi)
383  {
384  int numUrls = iw->urls().count();
385  writeInt(f,numUrls);
386  QIntDictIterator<URLInfo> uli(iw->urls());
387  URLInfo *ui;
388  for (uli.toFirst();(ui=uli.current());++uli)
389  {
390  writeInt(f,urlOffsets[ui->urlIdx]);
391  writeInt(f,ui->freq);
392  }
393  }
394  }
395  }
396  // write urls
398  URL *url;
399  for (udi.toFirst();(url=udi.current());++udi)
400  {
401  writeString(f,url->name);
402  writeString(f,url->url);
403  }
404  }
405 
406  delete[] urlOffsets;
407  delete[] wordStatOffsets;
408 }
uint count() const
Definition: qintdict.h:54
QCString word() const
Definition: searchindex.h:62
uint length() const
Definition: qcstring.h:195
#define IO_WriteOnly
Definition: qiodevice.h:62
QVector< QList< IndexWord > > m_index
Definition: searchindex.h:93
static void writeString(QFile &f, const char *s)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
QIntDict< URL > m_urls
Definition: searchindex.h:95
fileName
Definition: dumpTree.py:9
bool isEmpty() const
Definition: qlist.h:67
const int numIndexEntries
Definition: searchindex.cpp:52
The QFile class is an I/O device that operates on files.
Definition: qfile.h:50
const QIntDict< URLInfo > & urls() const
Definition: searchindex.h:61
static void writeInt(QFile &f, int index)
type * current() const
Definition: qintdict.h:94
QCString name
Definition: searchindex.h:44
QDict< IndexWord > m_words
Definition: searchindex.h:92
QCString url
Definition: searchindex.h:45
Definition: qlist.h:54

Member Data Documentation

QVector< QList<IndexWord> > SearchIndex::m_index
private

Definition at line 93 of file searchindex.h.

QDict<int> SearchIndex::m_url2IdMap
private

Definition at line 94 of file searchindex.h.

int SearchIndex::m_urlIndex
private

Definition at line 96 of file searchindex.h.

QIntDict<URL> SearchIndex::m_urls
private

Definition at line 95 of file searchindex.h.

QDict<IndexWord> SearchIndex::m_words
private

Definition at line 92 of file searchindex.h.


The documentation for this class was generated from the following files: