Skip to main content

The searchindex_js.h File Reference

Javascript based search engine. More...

Included Headers

#include <array> #include <vector> #include <map> #include <string> #include <functional> #include <variant> #include "qcstring.h" #include "utf8.h"

Classes Index

structSearchTerm

Searchable term. More...

structSearchIndexInfo

Table entry to allow filtering the search results per category. More...

Typedefs Index

usingSearchIndexList = std::vector< SearchTerm >

List of search terms. More...

usingSearchIndexMap = std::map< std::string, SearchIndexList >

Map of search terms for a given starting letter. More...

Functions Index

QCStringsearchName (const Definition *d)
voidcreateJavaScriptSearchIndex ()
voidwriteJavaScriptSearchIndex ()
const std::array< SearchIndexInfo, NUM_SEARCH_INDICES > &getSearchIndices ()

Macro Definitions Index

#defineNUM_SEARCH_INDICES   22

Description

Javascript based search engine.

Typedefs

SearchIndexList

using SearchIndexList = std::vector<SearchTerm>

List of search terms.

Definition at line 56 of file searchindex_js.h.

56using SearchIndexList = std::vector<SearchTerm>;

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.

59using SearchIndexMap = std::map<std::string,SearchIndexList>; // key is starting letter of a term (UTF-8).

Functions

createJavaScriptSearchIndex()

void createJavaScriptSearchIndex ()

Declaration at line 70 of file searchindex_js.h, 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}

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

Declaration at line 72 of file searchindex_js.h, definition at line 864 of file searchindex_js.cpp.

864const std::array<SearchIndexInfo,NUM_SEARCH_INDICES> &getSearchIndices()
865{
866 return g_searchIndexInfo;
867}

Reference g_searchIndexInfo.

searchName()

QCString searchName (const Definition * d)

Definition at line 39 of file searchindex_js.h.

writeJavaScriptSearchIndex()

void writeJavaScriptSearchIndex ()

Declaration at line 71 of file searchindex_js.h, definition at line 793 of file searchindex_js.cpp.

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

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.

Macro Definitions

NUM_SEARCH_INDICES

#define NUM_SEARCH_INDICES   22

Definition at line 33 of file searchindex_js.h.

33#define NUM_SEARCH_INDICES 22

Generated via doxygen2docusaurus by Doxygen 1.14.0.