Doxygen
Loading...
Searching...
No Matches
SearchIndexExternal Class Reference

Writes search index that should be used with an externally provided search engine, e.g. More...

#include <src/searchindex.h>

+ Collaboration diagram for SearchIndexExternal:

Classes

struct  SearchDocEntry
 

Public Member Functions

 SearchIndexExternal ()
 
void setCurrentDoc (const Definition *ctx, const QCString &anchor, bool isSourceFile)
 
void addWord (const QCString &word, bool hiPriority)
 
void write (const QCString &file)
 

Private Attributes

std::map< std::string, SearchDocEntrym_docEntries
 
SearchDocEntrym_current = nullptr
 

Detailed Description

Writes search index that should be used with an externally provided search engine, e.g.

doxyindexer and doxysearch.cgi.

Definition at line 113 of file searchindex.h.

Constructor & Destructor Documentation

◆ SearchIndexExternal()

SearchIndexExternal::SearchIndexExternal ( )

Definition at line 387 of file searchindex.cpp.

388{
389}

Member Function Documentation

◆ addWord()

void SearchIndexExternal::addWord ( const QCString & word,
bool hiPriority )

Definition at line 493 of file searchindex.cpp.

494{
495 std::lock_guard<std::mutex> lock(g_searchIndexMutex);
496 if (word.isEmpty() || !isId(word[0]) || m_current==nullptr) return;
497 GrowBuf *pText = hiPriority ? &m_current->importantText : &m_current->normalText;
498 if (pText->getPos()>0) pText->addChar(' ');
499 pText->addStr(word);
500 //printf("addWord %s\n",word);
501}
size_t getPos() const
Definition growbuf.h:116
void addChar(char c)
Definition growbuf.h:69
void addStr(const QCString &s)
Definition growbuf.h:72
SearchDocEntry * m_current
static std::mutex g_searchIndexMutex
std::string_view word
Definition util.cpp:980
bool isId(int c)
Definition util.h:202

References GrowBuf::addChar(), GrowBuf::addStr(), g_searchIndexMutex, GrowBuf::getPos(), isId(), m_current, and word.

◆ setCurrentDoc()

void SearchIndexExternal::setCurrentDoc ( const Definition * ctx,
const QCString & anchor,
bool isSourceFile )

Definition at line 450 of file searchindex.cpp.

451{
452 std::lock_guard<std::mutex> lock(g_searchIndexMutex);
453 QCString extId = stripPath(Config_getString(EXTERNAL_SEARCH_ID));
454 QCString url = isSourceFile ? (toFileDef(ctx))->getSourceFileBase() : ctx->getOutputFileBase();
456 if (!anchor.isEmpty()) url+=QCString("#")+anchor;
457 QCString key = extId+";"+url;
458
459 auto it = m_docEntries.find(key.str());
460 if (it == m_docEntries.end())
461 {
463 e.type = isSourceFile ? QCString("source") : definitionToName(ctx);
464 e.name = ctx->qualifiedName();
466 {
467 e.args = (toMemberDef(ctx))->argsString();
468 }
470 {
471 const GroupDef *gd = toGroupDef(ctx);
472 if (!gd->groupTitle().isEmpty())
473 {
474 e.name = filterTitle(gd->groupTitle());
475 }
476 }
477 else if (ctx->definitionType()==Definition::TypePage)
478 {
479 const PageDef *pd = toPageDef(ctx);
480 if (pd->hasTitle())
481 {
482 e.name = filterTitle(pd->title());
483 }
484 }
485 e.extId = extId;
486 e.url = url;
487 it = m_docEntries.emplace(key.str(),e).first;
488 //printf("searchIndexExt %s : %s\n",qPrint(e->name),qPrint(e->url));
489 }
490 m_current = &it->second;
491}
virtual DefType definitionType() const =0
virtual QCString qualifiedName() const =0
virtual bool hasTitle() const =0
virtual QCString title() const =0
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
const std::string & str() const
Definition qcstring.h:537
std::map< std::string, SearchDocEntry > m_docEntries
#define Config_getString(name)
Definition config.h:32
FileDef * toFileDef(Definition *d)
Definition filedef.cpp:1894
PageDef * toPageDef(Definition *d)
Definition pagedef.cpp:467
static QCString definitionToName(const Definition *ctx)
QCString type
QCString stripPath(const QCString &s)
Definition util.cpp:5292
QCString filterTitle(const QCString &title)
Definition util.cpp:5921
if(strLen >35 &&floatingIndex >30 &&autoBreak)
Definition util.cpp:949
void addHtmlExtensionIfMissing(QCString &fName)
Definition util.cpp:5243

References addHtmlExtensionIfMissing(), SearchIndexExternal::SearchDocEntry::args, Config_getString, definitionToName(), Definition::definitionType(), SearchIndexExternal::SearchDocEntry::extId, filterTitle(), g_searchIndexMutex, Definition::getOutputFileBase(), GroupDef::groupTitle(), PageDef::hasTitle(), QCString::isEmpty(), m_current, m_docEntries, SearchIndexExternal::SearchDocEntry::name, Definition::qualifiedName(), QCString::str(), stripPath(), PageDef::title(), toFileDef(), toGroupDef(), toMemberDef(), toPageDef(), SearchIndexExternal::SearchDocEntry::type, Definition::TypeGroup, Definition::TypeMember, Definition::TypePage, and SearchIndexExternal::SearchDocEntry::url.

◆ write()

void SearchIndexExternal::write ( const QCString & file)

Definition at line 503 of file searchindex.cpp.

504{
505 std::ofstream t = Portable::openOutputStream(fileName);
506 if (t.is_open())
507 {
508 t << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
509 t << "<add>\n";
510 for (auto &[name,doc] : m_docEntries)
511 {
512 doc.normalText.addChar(0); // make sure buffer ends with a 0 terminator
513 doc.importantText.addChar(0); // make sure buffer ends with a 0 terminator
514 t << " <doc>\n";
515 t << " <field name=\"type\">" << doc.type << "</field>\n";
516 t << " <field name=\"name\">" << convertToXML(doc.name) << "</field>\n";
517 if (!doc.args.isEmpty())
518 {
519 t << " <field name=\"args\">" << convertToXML(doc.args) << "</field>\n";
520 }
521 if (!doc.extId.isEmpty())
522 {
523 t << " <field name=\"tag\">" << convertToXML(doc.extId) << "</field>\n";
524 }
525 t << " <field name=\"url\">" << convertToXML(doc.url) << "</field>\n";
526 t << " <field name=\"keywords\">" << convertToXML(doc.importantText.get()) << "</field>\n";
527 t << " <field name=\"text\">" << convertToXML(doc.normalText.get()) << "</field>\n";
528 t << " </doc>\n";
529 }
530 t << "</add>\n";
531 }
532 else
533 {
534 err("Failed to open file %s for writing!\n",qPrint(fileName));
535 }
536}
#define err(fmt,...)
Definition message.h:84
std::ofstream openOutputStream(const QCString &name, bool append=false)
Definition portable.cpp:665
const char * qPrint(const char *s)
Definition qcstring.h:672
QCString convertToXML(const QCString &s, bool keepEntities)
Definition util.cpp:4266

References convertToXML(), err, m_docEntries, Portable::openOutputStream(), and qPrint().

Member Data Documentation

◆ m_current

SearchDocEntry* SearchIndexExternal::m_current = nullptr
private

Definition at line 133 of file searchindex.h.

Referenced by addWord(), and setCurrentDoc().

◆ m_docEntries

std::map<std::string,SearchDocEntry> SearchIndexExternal::m_docEntries
private

Definition at line 132 of file searchindex.h.

Referenced by setCurrentDoc(), and write().


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