Doxygen
Loading...
Searching...
No Matches
searchindex_js.h File Reference

Javascript based search engine. More...

#include <src/searchindex_js.h>

Include dependency graph for searchindex_js.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SearchTerm
 Searchable term. More...
struct  SearchIndexInfo
 Table entry to allow filtering the search results per category. More...

Macros

#define NUM_SEARCH_INDICES   22

Typedefs

using SearchIndexList = std::vector<SearchTerm>
 List of search terms.
using SearchIndexMap = std::map<std::string,SearchIndexList>
 Map of search terms for a given starting letter.

Functions

DString searchName (const Definition *d)
void createJavaScriptSearchIndex ()
void writeJavaScriptSearchIndex ()
const std::array< SearchIndexInfo, NUM_SEARCH_INDICES > & getSearchIndices ()

Detailed Description

Javascript based search engine.

Definition in file searchindex_js.h.

Macro Definition Documentation

◆ NUM_SEARCH_INDICES

#define NUM_SEARCH_INDICES   22

Definition at line 32 of file searchindex_js.h.

Typedef Documentation

◆ SearchIndexList

using SearchIndexList = std::vector<SearchTerm>

List of search terms.

Definition at line 55 of file searchindex_js.h.

◆ SearchIndexMap

using SearchIndexMap = std::map<std::string,SearchIndexList>

Map of search terms for a given starting letter.

Definition at line 58 of file searchindex_js.h.

Function Documentation

◆ createJavaScriptSearchIndex()

void createJavaScriptSearchIndex ( )

Definition at line 333 of file searchindex_js.cpp.

334{
335 // index classes
336 for (const auto &cd : *Doxygen::classLinkedMap)
337 {
338 if (cd->isLinkable())
339 {
340 DString n = cd->localName();
342 if (Config_getBool(OPTIMIZE_OUTPUT_SLICE))
343 {
344 if (cd->compoundType()==ClassDef::Interface)
345 {
347 }
348 else if (cd->compoundType()==ClassDef::Struct)
349 {
351 }
352 else if (cd->compoundType()==ClassDef::Exception)
353 {
355 }
356 else // cd->compoundType()==ClassDef::Class
357 {
359 }
360 }
361 else // non slice optimization: group all types under classes
362 {
364 }
365 }
366 }
367
368 // index namespaces
369 for (const auto &nd : *Doxygen::namespaceLinkedMap)
370 {
371 if (nd->isLinkable())
372 {
373 DString n = nd->name();
376 }
377 }
378
379 // index concepts
380 for (const auto &cd : *Doxygen::conceptLinkedMap)
381 {
382 if (cd->isLinkable())
383 {
384 DString n = cd->localName();
387 }
388 }
389
390 // index modules
391 for (const auto &mod : ModuleManager::instance().modules())
392 {
393 if (mod->isLinkable() && mod->isPrimaryInterface())
394 {
395 DString n = mod->name();
398 }
399 }
400
401 // index files
402 for (const auto &fn : *Doxygen::inputNameLinkedMap)
403 {
404 for (const auto &fd : *fn)
405 {
406 DString n = fd->name();
407 if (fd->isLinkable())
408 {
411 }
412 }
413 }
414
415 // index class members
416 {
417 // for each member name
418 for (const auto &mn : *Doxygen::memberNameLinkedMap)
419 {
420 // for each member definition
421 for (const auto &md : *mn)
422 {
423 addMemberToSearchIndex(md.get());
424 }
425 }
426 }
427
428 // index file/namespace members
429 {
430 // for each member name
431 for (const auto &mn : *Doxygen::functionNameLinkedMap)
432 {
433 // for each member definition
434 for (const auto &md : *mn)
435 {
436 addMemberToSearchIndex(md.get());
437 }
438 }
439 }
440
441 // index groups
442 for (const auto &gd : *Doxygen::groupLinkedMap)
443 {
444 if (gd->isLinkable())
445 {
446 DString title(filterTitle(gd->groupTitle()).str());
447 SizeVector tokenIndices;
448 splitSearchTokens(title,tokenIndices);
449 for (size_t index : tokenIndices)
450 {
451 g_searchIndexInfo[SEARCH_INDEX_ALL].add(SearchTerm(title.mid(index),gd.get()));
452 g_searchIndexInfo[SEARCH_INDEX_GROUPS].add(SearchTerm(title.mid(index),gd.get()));
453 }
454 }
455 }
456
457 // index pages
458 for (const auto &pd : *Doxygen::pageLinkedMap)
459 {
460 if (pd->isLinkable())
461 {
462 DString title(filterTitle(pd->title()).str());
463 SizeVector tokenIndices;
464 splitSearchTokens(title,tokenIndices);
465 for (size_t index : tokenIndices)
466 {
467 g_searchIndexInfo[SEARCH_INDEX_ALL].add(SearchTerm(title.mid(index),pd.get()));
468 g_searchIndexInfo[SEARCH_INDEX_PAGES].add(SearchTerm(title.mid(index),pd.get()));
469 }
470 }
471 }
472
473 // main page
475 {
476 DString title(filterTitle(Doxygen::mainPage->title()).str());
477 SizeVector tokenIndices;
478 splitSearchTokens(title,tokenIndices);
479 for (size_t index : tokenIndices)
480 {
483 }
484 }
485
486 // sections
487 const auto &sm = SectionManager::instance();
488 for (const auto &sectionInfo : sm)
489 {
490 if (sectionInfo->level()>0) // level 0 is for page titles
491 {
492 DString title = filterTitle(sectionInfo->title());
493 SizeVector tokenIndices;
494 splitSearchTokens(title,tokenIndices);
495 //printf("split(%s)=(%s) %zu\n",qPrint(sectionInfo->title()),qPrint(title),tokenIndices.size());
496 for (size_t index : tokenIndices)
497 {
498 g_searchIndexInfo[SEARCH_INDEX_ALL].add(SearchTerm(title.mid(index),sectionInfo.get()));
499 g_searchIndexInfo[SEARCH_INDEX_PAGES].add(SearchTerm(title.mid(index),sectionInfo.get()));
500 }
501 }
502 }
503
504 // sort all lists
505 for (auto &sii : g_searchIndexInfo) // for each index
506 {
507 for (auto &[name,symList] : sii.symbolMap) // for each symbol in the index
508 {
509 // sort the symbols (first on search term, and then on full name)
510 //
511 // `std::stable_sort` is used here due to reproducibility issues
512 // on key collisions
513 // https://github.com/doxygen/doxygen/issues/10445
514 std::stable_sort(symList.begin(),
515 symList.end(),
516 [](const auto &t1,const auto &t2)
517 {
518 int eq = dstricmp_sort(t1.word,t2.word); // search term first
519 return eq==0 ? dstricmp_sort(t1.title,t2.title)<0 : eq<0; // then full title
520 });
521 }
522 }
523}
@ Interface
Definition classdef.h:108
@ Exception
Definition classdef.h:111
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:318
const std::string & str() const
Definition dstring.h:645
static NamespaceLinkedMap * namespaceLinkedMap
Definition doxygen.h:108
static ConceptLinkedMap * conceptLinkedMap
Definition doxygen.h:90
static std::unique_ptr< PageDef > mainPage
Definition doxygen.h:93
static FileNameLinkedMap * inputNameLinkedMap
Definition doxygen.h:97
static ClassLinkedMap * classLinkedMap
Definition doxygen.h:88
static MemberNameLinkedMap * functionNameLinkedMap
Definition doxygen.h:105
static PageLinkedMap * pageLinkedMap
Definition doxygen.h:92
static MemberNameLinkedMap * memberNameLinkedMap
Definition doxygen.h:104
static GroupLinkedMap * groupLinkedMap
Definition doxygen.h:107
static ModuleManager & instance()
static SectionManager & instance()
returns a reference to the singleton
Definition section.h:179
#define Config_getBool(name)
Definition config.h:33
std::vector< size_t > SizeVector
Definition containers.h:39
static void addMemberToSearchIndex(const MemberDef *md)
#define SEARCH_INDEX_STRUCTS
#define SEARCH_INDEX_NAMESPACES
#define SEARCH_INDEX_CONCEPTS
static std::array< SearchIndexInfo, NUM_SEARCH_INDICES > g_searchIndexInfo
#define SEARCH_INDEX_FILES
#define SEARCH_INDEX_PAGES
#define SEARCH_INDEX_ALL
#define SEARCH_INDEX_GROUPS
#define SEARCH_INDEX_INTERFACES
static void splitSearchTokens(DString &title, SizeVector &indices)
#define SEARCH_INDEX_MODULES
#define SEARCH_INDEX_CLASSES
#define SEARCH_INDEX_EXCEPTIONS
Searchable term.
DString filterTitle(const DString &title)
Definition util.cpp:4454

References addMemberToSearchIndex(), Doxygen::classLinkedMap, Doxygen::conceptLinkedMap, Config_getBool, ClassDef::Exception, filterTitle(), Doxygen::functionNameLinkedMap, g_searchIndexInfo, Doxygen::groupLinkedMap, Doxygen::inputNameLinkedMap, ModuleManager::instance(), SectionManager::instance(), ClassDef::Interface, Doxygen::mainPage, Doxygen::memberNameLinkedMap, DString::mid(), Doxygen::namespaceLinkedMap, Doxygen::pageLinkedMap, SEARCH_INDEX_ALL, SEARCH_INDEX_CLASSES, SEARCH_INDEX_CONCEPTS, SEARCH_INDEX_EXCEPTIONS, SEARCH_INDEX_FILES, SEARCH_INDEX_GROUPS, SEARCH_INDEX_INTERFACES, SEARCH_INDEX_MODULES, SEARCH_INDEX_NAMESPACES, SEARCH_INDEX_PAGES, SEARCH_INDEX_STRUCTS, splitSearchTokens(), DString::str(), and ClassDef::Struct.

Referenced by generateOutput().

◆ getSearchIndices()

const std::array< SearchIndexInfo, NUM_SEARCH_INDICES > & getSearchIndices ( )

Definition at line 869 of file searchindex_js.cpp.

870{
871 return g_searchIndexInfo;
872}

References g_searchIndexInfo.

◆ searchName()

DString searchName ( const Definition * d)

◆ writeJavaScriptSearchIndex()

void writeJavaScriptSearchIndex ( )

Definition at line 798 of file searchindex_js.cpp.

799{
800 // write index files
801 DString searchDirName = Config_getString(HTML_OUTPUT)+"/search";
802
803 std::size_t numThreads = static_cast<std::size_t>(Config_getInt(NUM_PROC_THREADS));
804 if (numThreads>1) // multi threaded version
805 {
806 ThreadPool threadPool(numThreads);
807 std::vector< std::future<int> > results;
808 for (auto &sii : g_searchIndexInfo)
809 {
810 int p=0;
811 for (const auto &[letter,symList] : sii.symbolMap)
812 {
813 DString baseName;
814 baseName.sprintf("%s_%x",sii.name.data(),p);
815 DString dataFileName = searchDirName + "/"+baseName+".js";
816 auto &list = symList;
817 auto processFile = [p,baseName,dataFileName,&list]()
818 {
819 writeJavasScriptSearchDataPage(baseName,dataFileName,list);
820 return p;
821 };
822 results.emplace_back(threadPool.queue(processFile));
823 p++;
824 }
825 }
826 // wait for the results
827 for (auto &f : results) f.get();
828 }
829 else // single threaded version
830 {
831 for (auto &sii : g_searchIndexInfo)
832 {
833 int p=0;
834 for (const auto &[letter,symList] : sii.symbolMap)
835 {
836 DString baseName;
837 baseName.sprintf("%s_%x",sii.name.data(),p);
838 DString dataFileName = searchDirName + "/"+baseName+".js";
839 writeJavasScriptSearchDataPage(baseName,dataFileName,symList);
840 p++;
841 }
842 }
843 }
844
845 writeJavascriptSearchData(searchDirName);
846 auto &mgr = ResourceMgr::instance();
847 {
848 std::ofstream fn = Portable::openOutputStream(searchDirName+"/search.js");
849 if (fn.is_open())
850 {
851 TextStream t(&fn);
852 t << substitute(mgr.getAsString("search.js"),"$PROJECTID",getProjectId());
853 }
854 }
855
856 Doxygen::indexList->addStyleSheetFile("search/searchdata.js");
857 Doxygen::indexList->addStyleSheetFile("search/search.js");
858}
DString & sprintf(const char *format,...)
Definition dstring.cpp:34
static IndexList * indexList
Definition doxygen.h:125
void addStyleSheetFile(const DString &name)
Definition indexlist.h:127
static ResourceMgr & instance()
Returns the one and only instance of this class.
Text streaming class that buffers data.
Definition textstream.h:36
Class managing a pool of worker threads.
Definition threadpool.h:48
#define Config_getInt(name)
Definition config.h:34
#define Config_getString(name)
Definition config.h:32
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
Definition dstring.cpp:485
std::ofstream openOutputStream(const DString &name, bool append=false)
Definition portable.cpp:681
static void writeJavascriptSearchData(const DString &searchDirName)
static void writeJavasScriptSearchDataPage(const DString &baseName, const DString &dataFileName, const SearchIndexList &list)
DString getProjectId()
Definition util.cpp:5270

References IndexList::addStyleSheetFile(), Config_getInt, Config_getString, g_searchIndexInfo, getProjectId(), Doxygen::indexList, ResourceMgr::instance(), Portable::openOutputStream(), ThreadPool::queue(), DString::sprintf(), substitute(), writeJavascriptSearchData(), and writeJavasScriptSearchDataPage().

Referenced by generateOutput().