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

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

#include <src/searchindex.h>

Collaboration diagram for SearchIndexExternal:

Classes

struct  SearchDocEntry

Public Member Functions

 SearchIndexExternal ()
void setCurrentDoc (const Definition *ctx, const DString &anchor, bool isSourceFile)
void addWord (const DString &word, bool hiPriority)
void write (const DString &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 111 of file searchindex.h.

Constructor & Destructor Documentation

◆ SearchIndexExternal()

SearchIndexExternal::SearchIndexExternal ( )

Definition at line 385 of file searchindex.cpp.

386{
387}

Member Function Documentation

◆ addWord()

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

Definition at line 491 of file searchindex.cpp.

492{
493 std::lock_guard<std::mutex> lock(g_searchIndexMutex);
494 if (word.empty() || !isId(word[0]) || m_current==nullptr) return;
495 DString &text = hiPriority ? m_current->importantText : m_current->normalText;
496 if (!text.empty()) text+=' ';
497 text+=word;
498 //printf("addWord %s\n",word);
499}
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
SearchDocEntry * m_current
bool isId(int c)
Returns true if c is a valid character for an identifier.
Definition dstring.h:895
static std::mutex g_searchIndexMutex
DString normalText
DString importantText

References DString::empty(), g_searchIndexMutex, isId(), and m_current.

◆ setCurrentDoc()

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

Definition at line 448 of file searchindex.cpp.

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

References addHtmlExtensionIfMissing(), SearchIndexExternal::SearchDocEntry::args, Config_getString, definitionToName(), Definition::definitionType(), DString::empty(), SearchIndexExternal::SearchDocEntry::extId, filterTitle(), DString::find(), g_searchIndexMutex, Definition::getOutputFileBase(), GroupDef::groupTitle(), PageDef::hasTitle(), m_current, m_docEntries, SearchIndexExternal::SearchDocEntry::name, Definition::qualifiedName(), DString::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 DString & file)

Definition at line 501 of file searchindex.cpp.

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

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

Member Data Documentation

◆ m_current

SearchDocEntry* SearchIndexExternal::m_current = nullptr
private

Definition at line 131 of file searchindex.h.

Referenced by addWord(), and setCurrentDoc().

◆ m_docEntries

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

Definition at line 130 of file searchindex.h.

Referenced by setCurrentDoc(), and write().


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