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 112 of file searchindex.h.

Constructor & Destructor Documentation

◆ SearchIndexExternal()

SearchIndexExternal::SearchIndexExternal ( )

Definition at line 386 of file searchindex.cpp.

387{
388}

Member Function Documentation

◆ addWord()

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

Definition at line 492 of file searchindex.cpp.

493{
494 std::lock_guard<std::mutex> lock(g_searchIndexMutex);
495 if (word.isEmpty() || !isId(word[0]) || m_current==nullptr) return;
496 QCString &text = hiPriority ? m_current->importantText : m_current->normalText;
497 if (!text.isEmpty()) text+=' ';
498 text+=word;
499 //printf("addWord %s\n",word);
500}
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
SearchDocEntry * m_current
static std::mutex g_searchIndexMutex
bool isId(int c)
Definition util.h:207

References g_searchIndexMutex, QCString::isEmpty(), isId(), and m_current.

◆ setCurrentDoc()

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

Definition at line 449 of file searchindex.cpp.

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

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 502 of file searchindex.cpp.

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

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

Member Data Documentation

◆ m_current

SearchDocEntry* SearchIndexExternal::m_current = nullptr
private

Definition at line 132 of file searchindex.h.

Referenced by addWord(), and setCurrentDoc().

◆ m_docEntries

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

Definition at line 131 of file searchindex.h.

Referenced by setCurrentDoc(), and write().


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