Skip to main content

The SearchIndexExternal Class Reference

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

Declaration

class SearchIndexExternal { ... }

Included Headers

#include <src/searchindex.h>

Public Constructors Index

SearchIndexExternal ()

Public Member Functions Index

voidsetCurrentDoc (const Definition *ctx, const QCString &anchor, bool isSourceFile)
voidaddWord (const QCString &word, bool hiPriority)
voidwrite (const QCString &file)

Private Member Attributes Index

std::map< std::string, SearchDocEntry >m_docEntries
SearchDocEntry *m_current = nullptr

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.

Public Constructors

SearchIndexExternal()

SearchIndexExternal::SearchIndexExternal ()

Declaration at line 127 of file searchindex.h, definition at line 387 of file searchindex.cpp.

Public Member Functions

addWord()

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

Declaration at line 129 of file searchindex.h, definition at line 493 of file searchindex.cpp.

493void SearchIndexExternal::addWord(const QCString &word,bool hiPriority)
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}

References GrowBuf::addChar, GrowBuf::addStr, g_searchIndexMutex, GrowBuf::getPos, QCString::isEmpty, isId and m_current.

setCurrentDoc()

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

Declaration at line 128 of file searchindex.h, definition at line 450 of file searchindex.cpp.

450void SearchIndexExternal::setCurrentDoc(const Definition *ctx,const QCString &anchor,bool isSourceFile)
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}

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)

Declaration at line 130 of file searchindex.h, 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 {} for writing!\n",fileName);
535 }
536}

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

Private Member Attributes

m_current

SearchDocEntry* SearchIndexExternal::m_current = nullptr

Definition at line 133 of file searchindex.h.

Referenced by addWord and setCurrentDoc.

m_docEntries

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

Definition at line 132 of file searchindex.h.

132 std::map<std::string,SearchDocEntry> m_docEntries;

Referenced by setCurrentDoc and write.


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


Generated via doxygen2docusaurus by Doxygen 1.14.0.