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

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

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

866{
867 return g_searchIndexInfo;
868}

References g_searchIndexInfo.

◆ searchName()

QCString searchName ( const Definition * d)

◆ writeJavaScriptSearchIndex()

void writeJavaScriptSearchIndex ( )

Definition at line 794 of file searchindex_js.cpp.

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

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