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

Javascript based search engine. More...

#include <array>
#include <vector>
#include <map>
#include <string>
#include <functional>
#include <variant>
#include "qcstring.h"
#include "utf8.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

QCString 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 33 of file searchindex_js.h.

Typedef Documentation

◆ SearchIndexList

using SearchIndexList = std::vector<SearchTerm>

List of search terms.

Definition at line 56 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 59 of file searchindex_js.h.

Function Documentation

◆ createJavaScriptSearchIndex()

void createJavaScriptSearchIndex ( )

Definition at line 331 of file searchindex_js.cpp.

332{
333 // index classes
334 for (const auto &cd : *Doxygen::classLinkedMap)
335 {
336 if (cd->isLinkable())
337 {
338 QCString n = cd->localName();
340 if (Config_getBool(OPTIMIZE_OUTPUT_SLICE))
341 {
342 if (cd->compoundType()==ClassDef::Interface)
343 {
345 }
346 else if (cd->compoundType()==ClassDef::Struct)
347 {
349 }
350 else if (cd->compoundType()==ClassDef::Exception)
351 {
353 }
354 else // cd->compoundType()==ClassDef::Class
355 {
357 }
358 }
359 else // non slice optimization: group all types under classes
360 {
362 }
363 }
364 }
365
366 // index namespaces
367 for (const auto &nd : *Doxygen::namespaceLinkedMap)
368 {
369 if (nd->isLinkable())
370 {
371 QCString n = nd->name();
374 }
375 }
376
377 // index concepts
378 for (const auto &cd : *Doxygen::conceptLinkedMap)
379 {
380 if (cd->isLinkable())
381 {
382 QCString n = cd->localName();
385 }
386 }
387
388 // index modules
389 for (const auto &mod : ModuleManager::instance().modules())
390 {
391 if (mod->isLinkable() && mod->isPrimaryInterface())
392 {
393 QCString n = mod->name();
396 }
397 }
398
399 // index files
400 for (const auto &fn : *Doxygen::inputNameLinkedMap)
401 {
402 for (const auto &fd : *fn)
403 {
404 QCString n = fd->name();
405 if (fd->isLinkable())
406 {
409 }
410 }
411 }
412
413 // index class members
414 {
415 // for each member name
416 for (const auto &mn : *Doxygen::memberNameLinkedMap)
417 {
418 // for each member definition
419 for (const auto &md : *mn)
420 {
421 addMemberToSearchIndex(md.get());
422 }
423 }
424 }
425
426 // index file/namespace members
427 {
428 // for each member name
429 for (const auto &mn : *Doxygen::functionNameLinkedMap)
430 {
431 // for each member definition
432 for (const auto &md : *mn)
433 {
434 addMemberToSearchIndex(md.get());
435 }
436 }
437 }
438
439 // index groups
440 for (const auto &gd : *Doxygen::groupLinkedMap)
441 {
442 if (gd->isLinkable())
443 {
444 QCString title(filterTitle(gd->groupTitle()).str());
445 IntVector tokenIndices;
446 splitSearchTokens(title,tokenIndices);
447 for (int index : tokenIndices)
448 {
449 g_searchIndexInfo[SEARCH_INDEX_ALL].add(SearchTerm(title.mid(index),gd.get()));
450 g_searchIndexInfo[SEARCH_INDEX_GROUPS].add(SearchTerm(title.mid(index),gd.get()));
451 }
452 }
453 }
454
455 // index pages
456 for (const auto &pd : *Doxygen::pageLinkedMap)
457 {
458 if (pd->isLinkable())
459 {
460 QCString title(filterTitle(pd->title()).str());
461 IntVector tokenIndices;
462 splitSearchTokens(title,tokenIndices);
463 for (int index : tokenIndices)
464 {
465 g_searchIndexInfo[SEARCH_INDEX_ALL].add(SearchTerm(title.mid(index),pd.get()));
466 g_searchIndexInfo[SEARCH_INDEX_PAGES].add(SearchTerm(title.mid(index),pd.get()));
467 }
468 }
469 }
470
471 // main page
473 {
474 QCString title(filterTitle(Doxygen::mainPage->title()).str());
475 IntVector tokenIndices;
476 splitSearchTokens(title,tokenIndices);
477 for (int index : tokenIndices)
478 {
481 }
482 }
483
484 // sections
485 const auto &sm = SectionManager::instance();
486 for (const auto &sectionInfo : sm)
487 {
488 if (sectionInfo->level()>0) // level 0 is for page titles
489 {
490 QCString title = filterTitle(sectionInfo->title());
491 IntVector tokenIndices;
492 splitSearchTokens(title,tokenIndices);
493 //printf("split(%s)=(%s) %zu\n",qPrint(sectionInfo->title()),qPrint(title),tokenIndices.size());
494 for (int index : tokenIndices)
495 {
496 g_searchIndexInfo[SEARCH_INDEX_ALL].add(SearchTerm(title.mid(index),sectionInfo.get()));
497 g_searchIndexInfo[SEARCH_INDEX_PAGES].add(SearchTerm(title.mid(index),sectionInfo.get()));
498 }
499 }
500 }
501
502 // sort all lists
503 for (auto &sii : g_searchIndexInfo) // for each index
504 {
505 for (auto &[name,symList] : sii.symbolMap) // for each symbol in the index
506 {
507 // sort the symbols (first on search term, and then on full name)
508 //
509 // `std::stable_sort` is used here due to reproducibility issues
510 // on key collisions
511 // https://github.com/doxygen/doxygen/issues/10445
512 std::stable_sort(symList.begin(),
513 symList.end(),
514 [](const auto &t1,const auto &t2)
515 {
516 int eq = qstricmp_sort(t1.word,t2.word); // search term first
517 return eq==0 ? qstricmp_sort(t1.title,t2.title)<0 : eq<0; // then full title
518 });
519 }
520 }
521}
@ Interface
Definition classdef.h:112
@ Exception
Definition classdef.h:115
static NamespaceLinkedMap * namespaceLinkedMap
Definition doxygen.h:115
static ConceptLinkedMap * conceptLinkedMap
Definition doxygen.h:97
static std::unique_ptr< PageDef > mainPage
Definition doxygen.h:100
static FileNameLinkedMap * inputNameLinkedMap
Definition doxygen.h:104
static ClassLinkedMap * classLinkedMap
Definition doxygen.h:95
static MemberNameLinkedMap * functionNameLinkedMap
Definition doxygen.h:112
static PageLinkedMap * pageLinkedMap
Definition doxygen.h:99
static MemberNameLinkedMap * memberNameLinkedMap
Definition doxygen.h:111
static GroupLinkedMap * groupLinkedMap
Definition doxygen.h:114
static ModuleManager & instance()
This is an alternative implementation of QCString.
Definition qcstring.h:101
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:241
const std::string & str() const
Definition qcstring.h:552
static SectionManager & instance()
returns a reference to the singleton
Definition section.h:179
#define Config_getBool(name)
Definition config.h:33
std::vector< int > IntVector
Definition containers.h:38
static void addMemberToSearchIndex(const MemberDef *md)
#define SEARCH_INDEX_STRUCTS
static void splitSearchTokens(QCString &title, IntVector &indices)
#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
#define SEARCH_INDEX_MODULES
#define SEARCH_INDEX_CLASSES
#define SEARCH_INDEX_EXCEPTIONS
Searchable term.
QCString filterTitle(const QCString &title)
Definition util.cpp:5650

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, QCString::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(), QCString::str(), and ClassDef::Struct.

Referenced by generateOutput().

◆ getSearchIndices()

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

Definition at line 867 of file searchindex_js.cpp.

868{
869 return g_searchIndexInfo;
870}

References g_searchIndexInfo.

◆ searchName()

QCString searchName ( const Definition * d)

◆ writeJavaScriptSearchIndex()

void writeJavaScriptSearchIndex ( )

Definition at line 796 of file searchindex_js.cpp.

797{
798 // write index files
799 QCString searchDirName = Config_getString(HTML_OUTPUT)+"/search";
800
801 std::size_t numThreads = static_cast<std::size_t>(Config_getInt(NUM_PROC_THREADS));
802 if (numThreads>1) // multi threaded version
803 {
804 ThreadPool threadPool(numThreads);
805 std::vector< std::future<int> > results;
806 for (auto &sii : g_searchIndexInfo)
807 {
808 int p=0;
809 for (const auto &[letter,symList] : sii.symbolMap)
810 {
811 QCString baseName;
812 baseName.sprintf("%s_%x",sii.name.data(),p);
813 QCString dataFileName = searchDirName + "/"+baseName+".js";
814 auto &list = symList;
815 auto processFile = [p,baseName,dataFileName,&list]()
816 {
817 writeJavasScriptSearchDataPage(baseName,dataFileName,list);
818 return p;
819 };
820 results.emplace_back(threadPool.queue(processFile));
821 p++;
822 }
823 }
824 // wait for the results
825 for (auto &f : results) f.get();
826 }
827 else // single threaded version
828 {
829 for (auto &sii : g_searchIndexInfo)
830 {
831 int p=0;
832 for (const auto &[letter,symList] : sii.symbolMap)
833 {
834 QCString baseName;
835 baseName.sprintf("%s_%x",sii.name.data(),p);
836 QCString dataFileName = searchDirName + "/"+baseName+".js";
837 writeJavasScriptSearchDataPage(baseName,dataFileName,symList);
838 p++;
839 }
840 }
841 }
842
843 writeJavascriptSearchData(searchDirName);
844 auto &mgr = ResourceMgr::instance();
845 {
846 std::ofstream fn = Portable::openOutputStream(searchDirName+"/search.js");
847 if (fn.is_open())
848 {
849 TextStream t(&fn);
850 t << substitute(mgr.getAsString("search.js"),"$PROJECTID",getProjectId());
851 }
852 }
853
854 Doxygen::indexList->addStyleSheetFile("search/searchdata.js");
855 Doxygen::indexList->addStyleSheetFile("search/search.js");
856}
static IndexList * indexList
Definition doxygen.h:132
QCString & sprintf(const char *format,...)
Definition qcstring.cpp:29
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
std::ofstream openOutputStream(const QCString &name, bool append=false)
Definition portable.cpp:648
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition qcstring.cpp:571
static void writeJavasScriptSearchDataPage(const QCString &baseName, const QCString &dataFileName, const SearchIndexList &list)
static void writeJavascriptSearchData(const QCString &searchDirName)
QCString getProjectId()
Definition util.cpp:6829

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

Referenced by generateOutput().