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

308{
309 // index classes
310 for (const auto &cd : *Doxygen::classLinkedMap)
311 {
312 if (cd->isLinkable())
313 {
314 QCString n = cd->localName();
316 if (Config_getBool(OPTIMIZE_OUTPUT_SLICE))
317 {
318 if (cd->compoundType()==ClassDef::Interface)
319 {
321 }
322 else if (cd->compoundType()==ClassDef::Struct)
323 {
325 }
326 else if (cd->compoundType()==ClassDef::Exception)
327 {
329 }
330 else // cd->compoundType()==ClassDef::Class
331 {
333 }
334 }
335 else // non slice optimization: group all types under classes
336 {
338 }
339 }
340 }
341
342 // index namespaces
343 for (const auto &nd : *Doxygen::namespaceLinkedMap)
344 {
345 if (nd->isLinkable())
346 {
347 QCString n = nd->name();
350 }
351 }
352
353 // index concepts
354 for (const auto &cd : *Doxygen::conceptLinkedMap)
355 {
356 if (cd->isLinkable())
357 {
358 QCString n = cd->name();
361 }
362 }
363
364 // index modules
365 for (const auto &mod : ModuleManager::instance().modules())
366 {
367 if (mod->isLinkable() && mod->isPrimaryInterface())
368 {
369 QCString n = mod->name();
372 }
373 }
374
375 // index files
376 for (const auto &fn : *Doxygen::inputNameLinkedMap)
377 {
378 for (const auto &fd : *fn)
379 {
380 QCString n = fd->name();
381 if (fd->isLinkable())
382 {
385 }
386 }
387 }
388
389 // index class members
390 {
391 // for each member name
392 for (const auto &mn : *Doxygen::memberNameLinkedMap)
393 {
394 // for each member definition
395 for (const auto &md : *mn)
396 {
397 addMemberToSearchIndex(md.get());
398 }
399 }
400 }
401
402 // index file/namespace members
403 {
404 // for each member name
405 for (const auto &mn : *Doxygen::functionNameLinkedMap)
406 {
407 // for each member definition
408 for (const auto &md : *mn)
409 {
410 addMemberToSearchIndex(md.get());
411 }
412 }
413 }
414
415 // index groups
416 for (const auto &gd : *Doxygen::groupLinkedMap)
417 {
418 if (gd->isLinkable())
419 {
420 QCString title(filterTitle(gd->groupTitle()).str());
421 IntVector tokenIndices;
422 splitSearchTokens(title,tokenIndices);
423 for (int index : tokenIndices)
424 {
425 g_searchIndexInfo[SEARCH_INDEX_ALL].add(SearchTerm(title.mid(index),gd.get()));
426 g_searchIndexInfo[SEARCH_INDEX_GROUPS].add(SearchTerm(title.mid(index),gd.get()));
427 }
428 }
429 }
430
431 // index pages
432 for (const auto &pd : *Doxygen::pageLinkedMap)
433 {
434 if (pd->isLinkable())
435 {
436 QCString title(filterTitle(pd->title()).str());
437 IntVector tokenIndices;
438 splitSearchTokens(title,tokenIndices);
439 for (int index : tokenIndices)
440 {
441 g_searchIndexInfo[SEARCH_INDEX_ALL].add(SearchTerm(title.mid(index),pd.get()));
442 g_searchIndexInfo[SEARCH_INDEX_PAGES].add(SearchTerm(title.mid(index),pd.get()));
443 }
444 }
445 }
446
447 // main page
449 {
450 QCString title(filterTitle(Doxygen::mainPage->title()).str());
451 IntVector tokenIndices;
452 splitSearchTokens(title,tokenIndices);
453 for (int index : tokenIndices)
454 {
457 }
458 }
459
460 // sections
461 const auto &sm = SectionManager::instance();
462 for (const auto &sectionInfo : sm)
463 {
464 if (sectionInfo->level()>0) // level 0 is for page titles
465 {
466 QCString title = filterTitle(sectionInfo->title());
467 IntVector tokenIndices;
468 splitSearchTokens(title,tokenIndices);
469 for (int index : tokenIndices)
470 {
471 g_searchIndexInfo[SEARCH_INDEX_ALL].add(SearchTerm(title.mid(index),sectionInfo.get()));
472 }
473 }
474 }
475
476 // sort all lists
477 for (auto &sii : g_searchIndexInfo) // for each index
478 {
479 for (auto &[name,symList] : sii.symbolMap) // for each symbol in the index
480 {
481 // sort the symbols (first on search term, and then on full name)
482 //
483 // `std::stable_sort` is used here due to reproducibility issues
484 // on key collisions
485 // https://github.com/doxygen/doxygen/issues/10445
486 std::stable_sort(symList.begin(),
487 symList.end(),
488 [](const auto &t1,const auto &t2)
489 {
490 int eq = qstricmp_sort(t1.word,t2.word); // search term first
491 return eq==0 ? qstricmp_sort(t1.title,t2.title)<0 : eq<0; // then full title
492 });
493 }
494 }
495}
@ 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:526
static SectionManager & instance()
returns a reference to the singleton
Definition section.h:175
#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)
helper function to simplify the given title string, and fill a list of start positions for the start ...
#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:5920

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

840{
841 return g_searchIndexInfo;
842}

References g_searchIndexInfo.

◆ searchName()

QCString searchName ( const Definition * d)

◆ writeJavaScriptSearchIndex()

void writeJavaScriptSearchIndex ( )

Definition at line 768 of file searchindex_js.cpp.

769{
770 // write index files
771 QCString searchDirName = Config_getString(HTML_OUTPUT)+"/search";
772
773 std::size_t numThreads = static_cast<std::size_t>(Config_getInt(NUM_PROC_THREADS));
774 if (numThreads>1) // multi threaded version
775 {
776 ThreadPool threadPool(numThreads);
777 std::vector< std::future<int> > results;
778 for (auto &sii : g_searchIndexInfo)
779 {
780 int p=0;
781 for (const auto &[letter,symList] : sii.symbolMap)
782 {
783 QCString baseName;
784 baseName.sprintf("%s_%x",sii.name.data(),p);
785 QCString dataFileName = searchDirName + "/"+baseName+".js";
786 auto &list = symList;
787 auto processFile = [p,baseName,dataFileName,&list]()
788 {
789 writeJavasScriptSearchDataPage(baseName,dataFileName,list);
790 return p;
791 };
792 results.emplace_back(threadPool.queue(processFile));
793 p++;
794 }
795 }
796 // wait for the results
797 for (auto &f : results) f.get();
798 }
799 else // single threaded version
800 {
801 for (auto &sii : g_searchIndexInfo)
802 {
803 int p=0;
804 for (const auto &[letter,symList] : sii.symbolMap)
805 {
806 QCString baseName;
807 baseName.sprintf("%s_%x",sii.name.data(),p);
808 QCString dataFileName = searchDirName + "/"+baseName+".js";
809 writeJavasScriptSearchDataPage(baseName,dataFileName,symList);
810 p++;
811 }
812 }
813 }
814
815 writeJavascriptSearchData(searchDirName);
816 auto &mgr = ResourceMgr::instance();
817 {
818 std::ofstream fn = Portable::openOutputStream(searchDirName+"/search.js");
819 if (fn.is_open())
820 {
821 TextStream t(&fn);
822 t << substitute(mgr.getAsString("search.js"),"$PROJECTID",getProjectId());
823 }
824 }
825
826 Doxygen::indexList->addStyleSheetFile("search/searchdata.js");
827 Doxygen::indexList->addStyleSheetFile("search/search.js");
828}
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:7138

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