My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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.

References m_index, m_url2IdMap, m_urls, m_words, and numIndexEntries.

{
int i;
m_words.setAutoDelete(TRUE);
m_url2IdMap.setAutoDelete(TRUE);
m_urls.setAutoDelete(TRUE);
m_index.setAutoDelete(TRUE);
for (i=0;i<numIndexEntries;i++) m_index.insert(i,new QList<IndexWord>);
}

Member Function Documentation

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

Implements SearchIndexIntf.

Definition at line 242 of file searchindex.cpp.

Referenced by addWord().

{
addWord(word,hiPriority,FALSE);
}
void SearchIndex::addWord ( const char *  word,
bool  hiPrio,
bool  recurse 
)
private

Definition at line 205 of file searchindex.cpp.

References IndexWord::addUrlIndex(), addWord(), charsToIndex(), getPrefixIndex(), m_index, m_urlIndex, and m_words.

{
static QRegExp nextPart("[_a-z:][A-Z]");
if (word==0 || word[0]=='\0') return;
QCString wStr = QCString(word).lower();
//printf("SearchIndex::addWord(%s,%d) wStr=%s\n",word,hiPriority,wStr.data());
IndexWord *w = m_words[wStr];
if (w==0)
{
int idx=charsToIndex(wStr);
//fprintf(stderr,"addWord(%s) at index %d\n",word,idx);
if (idx<0) return;
w = new IndexWord(wStr);
m_index[idx]->append(w);
m_words.insert(wStr,w);
}
w->addUrlIndex(m_urlIndex,hiPriority);
int i;
bool found=FALSE;
if (!recurse) // the first time we check if we can strip the prefix
{
i=getPrefixIndex(word);
if (i>0)
{
addWord(word+i,hiPriority,TRUE);
found=TRUE;
}
}
if (!found) // no prefix stripped
{
if ((i=nextPart.match(word))>=1)
{
addWord(word+i+1,hiPriority,TRUE);
}
}
}
void SearchIndex::setCurrentDoc ( Definition ctx,
const char *  anchor,
bool  isSourceFile 
)
virtual

Implements SearchIndexIntf.

Definition at line 89 of file searchindex.cpp.

References ClassDef::compoundTypeString(), Config_getString, DefinitionIntf::definitionType(), Definition::getLanguage(), getLanguageSpecificSeparator(), GroupDef::groupTitle(), m_url2IdMap, m_urlIndex, m_urls, Definition::name(), SrcLangExt_CSharp, SrcLangExt_Fortran, SrcLangExt_Java, substitute(), theTranslator, PageDef::title(), Translator::trGroup(), Translator::trMember(), Translator::trModule(), Translator::trNamespace(), Translator::trPackage(), Translator::trPage(), Translator::trSubprogram(), DefinitionIntf::TypeClass, DefinitionIntf::TypeFile, DefinitionIntf::TypeGroup, DefinitionIntf::TypeMember, DefinitionIntf::TypeNamespace, and DefinitionIntf::TypePage.

{
if (ctx==0) return;
assert(!isSourceFile || ctx->definitionType()==Definition::TypeFile);
//printf("SearchIndex::setCurrentDoc(%s,%s,%s)\n",name,baseName,anchor);
QCString url=isSourceFile ? ((FileDef*)ctx)->getSourceFileBase() : ctx->getOutputFileBase();
url+=Config_getString(HTML_FILE_EXTENSION);
QCString baseUrl = url;
if (anchor) url+=QCString("#")+anchor;
if (!isSourceFile) baseUrl=url;
QCString name=ctx->qualifiedName();
{
MemberDef *md = (MemberDef *)ctx;
name.prepend((md->getLanguage()==SrcLangExt_Fortran ?
theTranslator->trMember(TRUE,TRUE))+" ");
}
else // compound type
{
SrcLangExt lang = ctx->getLanguage();
QCString sep = getLanguageSpecificSeparator(lang);
if (sep!="::")
{
name = substitute(name,"::",sep);
}
switch (ctx->definitionType())
{
{
PageDef *pd = (PageDef *)ctx;
if (!pd->title().isEmpty())
{
name = theTranslator->trPage(TRUE,TRUE)+" "+pd->title();
}
else
{
name = theTranslator->trPage(TRUE,TRUE)+" "+pd->name();
}
}
break;
{
ClassDef *cd = (ClassDef *)ctx;
name.prepend(cd->compoundTypeString()+" ");
}
break;
{
if (lang==SrcLangExt_Java || lang==SrcLangExt_CSharp)
{
name = theTranslator->trPackage(name);
}
else if (lang==SrcLangExt_Fortran)
{
name.prepend(theTranslator->trModule(TRUE,TRUE)+" ");
}
else
{
name.prepend(theTranslator->trNamespace(TRUE,TRUE)+" ");
}
}
break;
{
GroupDef *gd = (GroupDef *)ctx;
if (gd->groupTitle())
{
name = theTranslator->trGroup(TRUE,TRUE)+" "+gd->groupTitle();
}
else
{
name.prepend(theTranslator->trGroup(TRUE,TRUE)+" ");
}
}
break;
default:
break;
}
}
int *pIndex = m_url2IdMap.find(baseUrl);
if (pIndex==0)
{
m_url2IdMap.insert(baseUrl,new int(m_urlIndex));
m_urls.insert(m_urlIndex,new URL(name,url));
}
else
{
m_urls.insert(*pIndex,new URL(name,url));
}
}
void SearchIndex::write ( const char *  file)
virtual

Implements SearchIndexIntf.

Definition at line 262 of file searchindex.cpp.

References m_index, m_urls, m_words, URL::name, numIndexEntries, URL::url, IndexWord::urls(), IndexWord::word(), writeInt(), and writeString().

{
int i;
int size=4; // for the header
size+=4*numIndexEntries; // for the index
int wordsOffset = size;
// first pass: compute the size of the wordlist
for (i=0;i<numIndexEntries;i++)
{
QList<IndexWord> *wlist = m_index[i];
if (!wlist->isEmpty())
{
QListIterator<IndexWord> iwi(*wlist);
IndexWord *iw;
for (iwi.toFirst();(iw=iwi.current());++iwi)
{
int ws = iw->word().length()+1;
size+=ws+4; // word + url info list offset
}
size+=1; // zero list terminator
}
}
// second pass: compute the offsets in the index
int indexOffsets[numIndexEntries];
int offset=wordsOffset;
for (i=0;i<numIndexEntries;i++)
{
QList<IndexWord> *wlist = m_index[i];
if (!wlist->isEmpty())
{
indexOffsets[i]=offset;
QListIterator<IndexWord> iwi(*wlist);
IndexWord *iw;
for (iwi.toFirst();(iw=iwi.current());++iwi)
{
offset+= iw->word().length()+1;
offset+=4; // word + offset to url info array
}
offset+=1; // zero list terminator
}
else
{
indexOffsets[i]=0;
}
}
int padding = size;
size = (size+3)&~3; // round up to 4 byte boundary
padding = size - padding;
//int statsOffset = size;
//IndexWord *iw;
int *wordStatOffsets = new int[m_words.count()];
int count=0;
// third pass: compute offset to stats info for each word
for (i=0;i<numIndexEntries;i++)
{
QList<IndexWord> *wlist = m_index[i];
if (!wlist->isEmpty())
{
QListIterator<IndexWord> iwi(*wlist);
IndexWord *iw;
for (iwi.toFirst();(iw=iwi.current());++iwi)
{
//printf("wordStatOffsets[%d]=%d\n",count,size);
wordStatOffsets[count++] = size;
size+=4+iw->urls().count()*8; // count + (url_index,freq) per url
}
}
}
int *urlOffsets = new int[m_urls.count()];
//int urlsOffset = size;
QIntDictIterator<URL> udi(m_urls);
URL *url;
for (udi.toFirst();(url=udi.current());++udi)
{
urlOffsets[udi.currentKey()]=size;
size+=url->name.length()+1+
url->url.length()+1;
}
//printf("Total size %x bytes (word=%x stats=%x urls=%x)\n",size,wordsOffset,statsOffset,urlsOffset);
QFile f(fileName);
if (f.open(IO_WriteOnly))
{
// write header
f.putch('D'); f.putch('O'); f.putch('X'); f.putch('S');
// write index
for (i=0;i<numIndexEntries;i++)
{
writeInt(f,indexOffsets[i]);
}
// write word lists
count=0;
for (i=0;i<numIndexEntries;i++)
{
QList<IndexWord> *wlist = m_index[i];
if (!wlist->isEmpty())
{
QListIterator<IndexWord> iwi(*wlist);
IndexWord *iw;
for (iwi.toFirst();(iw=iwi.current());++iwi)
{
writeString(f,iw->word());
writeInt(f,wordStatOffsets[count++]);
}
f.putch(0);
}
}
// write extra padding bytes
for (i=0;i<padding;i++) f.putch(0);
// write word statistics
for (i=0;i<numIndexEntries;i++)
{
QList<IndexWord> *wlist = m_index[i];
if (!wlist->isEmpty())
{
QListIterator<IndexWord> iwi(*wlist);
IndexWord *iw;
for (iwi.toFirst();(iw=iwi.current());++iwi)
{
int numUrls = iw->urls().count();
writeInt(f,numUrls);
QIntDictIterator<URLInfo> uli(iw->urls());
URLInfo *ui;
for (uli.toFirst();(ui=uli.current());++uli)
{
writeInt(f,urlOffsets[ui->urlIdx]);
writeInt(f,ui->freq);
}
}
}
}
// write urls
QIntDictIterator<URL> udi(m_urls);
URL *url;
for (udi.toFirst();(url=udi.current());++udi)
{
writeString(f,url->name);
writeString(f,url->url);
}
}
delete[] urlOffsets;
delete[] wordStatOffsets;
}

Member Data Documentation

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

Definition at line 93 of file searchindex.h.

Referenced by addWord(), SearchIndex(), and write().

QDict<int> SearchIndex::m_url2IdMap
private

Definition at line 94 of file searchindex.h.

Referenced by SearchIndex(), and setCurrentDoc().

int SearchIndex::m_urlIndex
private

Definition at line 96 of file searchindex.h.

Referenced by addWord(), and setCurrentDoc().

QIntDict<URL> SearchIndex::m_urls
private

Definition at line 95 of file searchindex.h.

Referenced by SearchIndex(), setCurrentDoc(), and write().

QDict<IndexWord> SearchIndex::m_words
private

Definition at line 92 of file searchindex.h.

Referenced by addWord(), SearchIndex(), and write().


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