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   23

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   23

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 335 of file searchindex_js.cpp.

336{
337 // index classes
338 for (const auto &cd : *Doxygen::classLinkedMap)
339 {
340 if (cd->isLinkable())
341 {
342 DString n = cd->localName();
344 if (Config_getBool(OPTIMIZE_OUTPUT_SLICE))
345 {
346 if (cd->compoundType()==ClassDef::Interface)
347 {
349 }
350 else if (cd->compoundType()==ClassDef::Struct)
351 {
353 }
354 else if (cd->compoundType()==ClassDef::Record)
355 {
357 }
358 else if (cd->compoundType()==ClassDef::Exception)
359 {
361 }
362 else // cd->compoundType()==ClassDef::Class
363 {
365 }
366 }
367 else // non slice optimization: group all types under classes
368 {
370 }
371 }
372 }
373
374 // index namespaces
375 for (const auto &nd : *Doxygen::namespaceLinkedMap)
376 {
377 if (nd->isLinkable())
378 {
379 DString n = nd->name();
382 }
383 }
384
385 // index concepts
386 for (const auto &cd : *Doxygen::conceptLinkedMap)
387 {
388 if (cd->isLinkable())
389 {
390 DString n = cd->localName();
393 }
394 }
395
396 // index modules
397 for (const auto &mod : ModuleManager::instance().modules())
398 {
399 if (mod->isLinkable() && mod->isPrimaryInterface())
400 {
401 DString n = mod->name();
404 }
405 }
406
407 // index files
408 for (const auto &fn : *Doxygen::inputNameLinkedMap)
409 {
410 for (const auto &fd : *fn)
411 {
412 DString n = fd->name();
413 if (fd->isLinkable())
414 {
417 }
418 }
419 }
420
421 // index class members
422 {
423 // for each member name
424 for (const auto &mn : *Doxygen::memberNameLinkedMap)
425 {
426 // for each member definition
427 for (const auto &md : *mn)
428 {
429 addMemberToSearchIndex(md.get());
430 }
431 }
432 }
433
434 // index file/namespace members
435 {
436 // for each member name
437 for (const auto &mn : *Doxygen::functionNameLinkedMap)
438 {
439 // for each member definition
440 for (const auto &md : *mn)
441 {
442 addMemberToSearchIndex(md.get());
443 }
444 }
445 }
446
447 // index groups
448 for (const auto &gd : *Doxygen::groupLinkedMap)
449 {
450 if (gd->isLinkable())
451 {
452 DString title(filterTitle(gd->groupTitle()).str());
453 SizeVector tokenIndices;
454 splitSearchTokens(title,tokenIndices);
455 for (size_t index : tokenIndices)
456 {
457 g_searchIndexInfo[SEARCH_INDEX_ALL].add(SearchTerm(title.mid(index),gd.get()));
458 g_searchIndexInfo[SEARCH_INDEX_GROUPS].add(SearchTerm(title.mid(index),gd.get()));
459 }
460 }
461 }
462
463 // index pages
464 for (const auto &pd : *Doxygen::pageLinkedMap)
465 {
466 if (pd->isLinkable())
467 {
468 DString title(filterTitle(pd->title()).str());
469 SizeVector tokenIndices;
470 splitSearchTokens(title,tokenIndices);
471 for (size_t index : tokenIndices)
472 {
473 g_searchIndexInfo[SEARCH_INDEX_ALL].add(SearchTerm(title.mid(index),pd.get()));
474 g_searchIndexInfo[SEARCH_INDEX_PAGES].add(SearchTerm(title.mid(index),pd.get()));
475 }
476 }
477 }
478
479 // main page
481 {
482 DString title(filterTitle(Doxygen::mainPage->title()).str());
483 SizeVector tokenIndices;
484 splitSearchTokens(title,tokenIndices);
485 for (size_t index : tokenIndices)
486 {
489 }
490 }
491
492 // sections
493 const auto &sm = SectionManager::instance();
494 for (const auto &sectionInfo : sm)
495 {
496 if (sectionInfo->level()>0) // level 0 is for page titles
497 {
498 DString title = filterTitle(sectionInfo->title());
499 SizeVector tokenIndices;
500 splitSearchTokens(title,tokenIndices);
501 //printf("split(%s)=(%s) %zu\n",qPrint(sectionInfo->title()),qPrint(title),tokenIndices.size());
502 for (size_t index : tokenIndices)
503 {
504 g_searchIndexInfo[SEARCH_INDEX_ALL].add(SearchTerm(title.mid(index),sectionInfo.get()));
505 g_searchIndexInfo[SEARCH_INDEX_PAGES].add(SearchTerm(title.mid(index),sectionInfo.get()));
506 }
507 }
508 }
509
510 // sort all lists
511 for (auto &sii : g_searchIndexInfo) // for each index
512 {
513 for (auto &[name,symList] : sii.symbolMap) // for each symbol in the index
514 {
515 // sort the symbols (first on search term, and then on full name)
516 //
517 // `std::stable_sort` is used here due to reproducibility issues
518 // on key collisions
519 // https://github.com/doxygen/doxygen/issues/10445
520 std::stable_sort(symList.begin(),
521 symList.end(),
522 [](const auto &t1,const auto &t2)
523 {
524 int eq = dstricmp_sort(t1.word,t2.word); // search term first
525 return eq==0 ? dstricmp_sort(t1.title,t2.title)<0 : eq<0; // then full title
526 });
527 }
528 }
529}
@ Interface
Definition classdef.h:109
@ Exception
Definition classdef.h:112
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_RECORDS
#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:4590

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, ClassDef::Record, 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_RECORDS, SEARCH_INDEX_STRUCTS, splitSearchTokens(), DString::str(), and ClassDef::Struct.

Referenced by generateOutput().

◆ getSearchIndices()

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

Definition at line 875 of file searchindex_js.cpp.

876{
877 return g_searchIndexInfo;
878}

References g_searchIndexInfo.

◆ searchName()

DString searchName ( const Definition * d)

◆ writeJavaScriptSearchIndex()

void writeJavaScriptSearchIndex ( )

Definition at line 804 of file searchindex_js.cpp.

805{
806 // write index files
807 DString searchDirName = Config_getString(HTML_OUTPUT)+"/search";
808
809 std::size_t numThreads = static_cast<std::size_t>(Config_getInt(NUM_PROC_THREADS));
810 if (numThreads>1) // multi threaded version
811 {
812 ThreadPool threadPool(numThreads);
813 std::vector< std::future<int> > results;
814 for (auto &sii : g_searchIndexInfo)
815 {
816 int p=0;
817 for (const auto &[letter,symList] : sii.symbolMap)
818 {
819 DString baseName;
820 baseName.sprintf("%s_%x",sii.name.data(),p);
821 DString dataFileName = searchDirName + "/"+baseName+".js";
822 auto &list = symList;
823 auto processFile = [p,baseName,dataFileName,&list]()
824 {
825 writeJavasScriptSearchDataPage(baseName,dataFileName,list);
826 return p;
827 };
828 results.emplace_back(threadPool.queue(processFile));
829 p++;
830 }
831 }
832 // wait for the results
833 for (auto &f : results) f.get();
834 }
835 else // single threaded version
836 {
837 for (auto &sii : g_searchIndexInfo)
838 {
839 int p=0;
840 for (const auto &[letter,symList] : sii.symbolMap)
841 {
842 DString baseName;
843 baseName.sprintf("%s_%x",sii.name.data(),p);
844 DString dataFileName = searchDirName + "/"+baseName+".js";
845 writeJavasScriptSearchDataPage(baseName,dataFileName,symList);
846 p++;
847 }
848 }
849 }
850
851 writeJavascriptSearchData(searchDirName);
852 auto &mgr = ResourceMgr::instance();
853 {
854 std::ofstream fn = Portable::openOutputStream(searchDirName+"/search.js");
855 if (fn.is_open())
856 {
857 TextStream t(&fn);
858 t << substitute(mgr.getAsString("search.js"),"$PROJECTID",getProjectId());
859 }
860 }
861
862 Doxygen::indexList->addStyleSheetFile("search/searchdata.js");
863 Doxygen::indexList->addStyleSheetFile("search/search.js");
864}
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:679
static void writeJavascriptSearchData(const DString &searchDirName)
static void writeJavasScriptSearchDataPage(const DString &baseName, const DString &dataFileName, const SearchIndexList &list)
DString getProjectId()
Definition util.cpp:5427

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().