Doxygen
Loading...
Searching...
No Matches
searchindex_js.cpp File Reference
#include <utility>
#include <algorithm>
#include <cassert>
#include "searchindex_js.h"
#include "doxygen.h"
#include "groupdef.h"
#include "pagedef.h"
#include "namespacedef.h"
#include "classdef.h"
#include "classlist.h"
#include "membername.h"
#include "filename.h"
#include "language.h"
#include "textstream.h"
#include "util.h"
#include "version.h"
#include "message.h"
#include "resourcemgr.h"
#include "indexlist.h"
#include "portable.h"
#include "threadpool.h"
#include "moduledef.h"
#include "section.h"
Include dependency graph for searchindex_js.cpp:

Go to the source code of this file.

Macros

#define SEARCH_INDEX_ALL   0
#define SEARCH_INDEX_CLASSES   1
#define SEARCH_INDEX_INTERFACES   2
#define SEARCH_INDEX_STRUCTS   3
#define SEARCH_INDEX_EXCEPTIONS   4
#define SEARCH_INDEX_NAMESPACES   5
#define SEARCH_INDEX_FILES   6
#define SEARCH_INDEX_FUNCTIONS   7
#define SEARCH_INDEX_VARIABLES   8
#define SEARCH_INDEX_TYPEDEFS   9
#define SEARCH_INDEX_SEQUENCES   10
#define SEARCH_INDEX_DICTIONARIES   11
#define SEARCH_INDEX_ENUMS   12
#define SEARCH_INDEX_ENUMVALUES   13
#define SEARCH_INDEX_PROPERTIES   14
#define SEARCH_INDEX_EVENTS   15
#define SEARCH_INDEX_RELATED   16
#define SEARCH_INDEX_DEFINES   17
#define SEARCH_INDEX_GROUPS   18
#define SEARCH_INDEX_PAGES   19
#define SEARCH_INDEX_CONCEPTS   20
#define SEARCH_INDEX_MODULES   21

Functions

static void splitSearchTokens (QCString &title, IntVector &indices)
static void addMemberToSearchIndex (const MemberDef *md)
void createJavaScriptSearchIndex ()
static void writeJavascriptSearchData (const QCString &searchDirName)
static void writeJavasScriptSearchDataPage (const QCString &baseName, const QCString &dataFileName, const SearchIndexList &list)
void writeJavaScriptSearchIndex ()
const std::array< SearchIndexInfo, NUM_SEARCH_INDICES > & getSearchIndices ()

Variables

static std::array< SearchIndexInfo, NUM_SEARCH_INDICESg_searchIndexInfo

Macro Definition Documentation

◆ SEARCH_INDEX_ALL

#define SEARCH_INDEX_ALL   0

Definition at line 156 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex(), and createJavaScriptSearchIndex().

◆ SEARCH_INDEX_CLASSES

#define SEARCH_INDEX_CLASSES   1

Definition at line 157 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_CONCEPTS

#define SEARCH_INDEX_CONCEPTS   20

Definition at line 176 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_DEFINES

#define SEARCH_INDEX_DEFINES   17

Definition at line 173 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_DICTIONARIES

#define SEARCH_INDEX_DICTIONARIES   11

Definition at line 167 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_ENUMS

#define SEARCH_INDEX_ENUMS   12

Definition at line 168 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_ENUMVALUES

#define SEARCH_INDEX_ENUMVALUES   13

Definition at line 169 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_EVENTS

#define SEARCH_INDEX_EVENTS   15

Definition at line 171 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_EXCEPTIONS

#define SEARCH_INDEX_EXCEPTIONS   4

Definition at line 160 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_FILES

#define SEARCH_INDEX_FILES   6

Definition at line 162 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_FUNCTIONS

#define SEARCH_INDEX_FUNCTIONS   7

Definition at line 163 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_GROUPS

#define SEARCH_INDEX_GROUPS   18

Definition at line 174 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_INTERFACES

#define SEARCH_INDEX_INTERFACES   2

Definition at line 158 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_MODULES

#define SEARCH_INDEX_MODULES   21

Definition at line 177 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_NAMESPACES

#define SEARCH_INDEX_NAMESPACES   5

Definition at line 161 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_PAGES

#define SEARCH_INDEX_PAGES   19

Definition at line 175 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_PROPERTIES

#define SEARCH_INDEX_PROPERTIES   14

Definition at line 170 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_RELATED

#define SEARCH_INDEX_RELATED   16

Definition at line 172 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_SEQUENCES

#define SEARCH_INDEX_SEQUENCES   10

Definition at line 166 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_STRUCTS

#define SEARCH_INDEX_STRUCTS   3

Definition at line 159 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_TYPEDEFS

#define SEARCH_INDEX_TYPEDEFS   9

Definition at line 165 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_VARIABLES

#define SEARCH_INDEX_VARIABLES   8

Definition at line 164 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

Function Documentation

◆ addMemberToSearchIndex()

void addMemberToSearchIndex ( const MemberDef * md)
static

Definition at line 212 of file searchindex_js.cpp.

213{
214 bool hideFriendCompounds = Config_getBool(HIDE_FRIEND_COMPOUNDS);
215 bool isLinkable = md->isLinkable();
216 const ClassDef *cd=nullptr;
217 const NamespaceDef *nd=nullptr;
218 const FileDef *fd=nullptr;
219 const GroupDef *gd=nullptr;
220 if (isLinkable &&
221 (
222 ((cd=md->getClassDef()) && cd->isLinkable() && !cd->isImplicitTemplateInstance()) ||
223 ((gd=md->getGroupDef()) && gd->isLinkable())
224 )
225 )
226 {
227 QCString n = md->name();
228 if (!n.isEmpty())
229 {
230 bool isFriendToHide = hideFriendCompounds &&
231 (QCString(md->typeString())=="friend class" ||
232 QCString(md->typeString())=="friend struct" ||
233 QCString(md->typeString())=="friend union");
234 if (!(md->isFriend() && isFriendToHide))
235 {
237 }
238 if (md->isFunction() || md->isSlot() || md->isSignal())
239 {
241 }
242 else if (md->isVariable())
243 {
245 }
246 else if (md->isSequence())
247 {
249 }
250 else if (md->isDictionary())
251 {
253 }
254 else if (md->isTypedef())
255 {
257 }
258 else if (md->isEnumerate())
259 {
261 }
262 else if (md->isEnumValue())
263 {
265 }
266 else if (md->isProperty())
267 {
269 }
270 else if (md->isEvent())
271 {
273 }
274 else if (md->isRelated() || md->isForeign() ||
275 (md->isFriend() && !isFriendToHide))
276 {
278 }
279 }
280 }
281 else if (isLinkable &&
282 (((nd=md->getNamespaceDef()) && nd->isLinkable()) ||
283 ((fd=md->getFileDef()) && fd->isLinkable())
284 )
285 )
286 {
287 QCString n = md->name();
288 if (!n.isEmpty())
289 {
291
292 if (md->isFunction())
293 {
295 }
296 else if (md->isVariable())
297 {
299 }
300 else if (md->isSequence())
301 {
303 }
304 else if (md->isDictionary())
305 {
307 }
308 else if (md->isTypedef())
309 {
311 }
312 else if (md->isEnumerate())
313 {
315 }
316 else if (md->isEnumValue())
317 {
319 }
320 else if (md->isDefine())
321 {
323 }
324 }
325 }
326}
A abstract class representing of a compound symbol.
Definition classdef.h:104
virtual bool isImplicitTemplateInstance() const =0
virtual bool isLinkable() const =0
virtual const QCString & name() const =0
A model of a file symbol.
Definition filedef.h:99
A model of a group of symbols.
Definition groupdef.h:52
virtual QCString typeString() const =0
virtual bool isSignal() const =0
virtual bool isFriend() const =0
virtual bool isForeign() const =0
virtual bool isRelated() const =0
virtual bool isSequence() const =0
virtual const ClassDef * getClassDef() const =0
virtual GroupDef * getGroupDef()=0
virtual bool isTypedef() const =0
virtual bool isSlot() const =0
virtual const FileDef * getFileDef() const =0
virtual bool isEvent() const =0
virtual bool isFunction() const =0
virtual bool isDictionary() const =0
virtual bool isDefine() const =0
virtual const NamespaceDef * getNamespaceDef() const =0
virtual bool isEnumerate() const =0
virtual bool isVariable() const =0
virtual bool isEnumValue() const =0
virtual bool isProperty() const =0
An abstract interface of a namespace symbol.
This is an alternative implementation of QCString.
Definition qcstring.h:101
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
#define Config_getBool(name)
Definition config.h:33
#define SEARCH_INDEX_TYPEDEFS
#define SEARCH_INDEX_EVENTS
static std::array< SearchIndexInfo, NUM_SEARCH_INDICES > g_searchIndexInfo
#define SEARCH_INDEX_DEFINES
#define SEARCH_INDEX_ENUMS
#define SEARCH_INDEX_DICTIONARIES
#define SEARCH_INDEX_ALL
#define SEARCH_INDEX_SEQUENCES
#define SEARCH_INDEX_PROPERTIES
#define SEARCH_INDEX_ENUMVALUES
#define SEARCH_INDEX_FUNCTIONS
#define SEARCH_INDEX_VARIABLES
#define SEARCH_INDEX_RELATED
Searchable term.

References Config_getBool, g_searchIndexInfo, MemberDef::getClassDef(), MemberDef::getFileDef(), MemberDef::getGroupDef(), MemberDef::getNamespaceDef(), MemberDef::isDefine(), MemberDef::isDictionary(), QCString::isEmpty(), MemberDef::isEnumerate(), MemberDef::isEnumValue(), MemberDef::isEvent(), MemberDef::isForeign(), MemberDef::isFriend(), MemberDef::isFunction(), ClassDef::isImplicitTemplateInstance(), Definition::isLinkable(), MemberDef::isProperty(), MemberDef::isRelated(), MemberDef::isSequence(), MemberDef::isSignal(), MemberDef::isSlot(), MemberDef::isTypedef(), MemberDef::isVariable(), Definition::name(), SEARCH_INDEX_ALL, SEARCH_INDEX_DEFINES, SEARCH_INDEX_DICTIONARIES, SEARCH_INDEX_ENUMS, SEARCH_INDEX_ENUMVALUES, SEARCH_INDEX_EVENTS, SEARCH_INDEX_FUNCTIONS, SEARCH_INDEX_PROPERTIES, SEARCH_INDEX_RELATED, SEARCH_INDEX_SEQUENCES, SEARCH_INDEX_TYPEDEFS, SEARCH_INDEX_VARIABLES, and MemberDef::typeString().

Referenced by addToIndices(), and createJavaScriptSearchIndex().

◆ 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()
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
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
#define SEARCH_INDEX_FILES
#define SEARCH_INDEX_PAGES
#define SEARCH_INDEX_GROUPS
#define SEARCH_INDEX_INTERFACES
#define SEARCH_INDEX_MODULES
#define SEARCH_INDEX_CLASSES
#define SEARCH_INDEX_EXCEPTIONS
QCString filterTitle(const QCString &title)
Definition util.cpp:6131

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

867{
868 return g_searchIndexInfo;
869}

References g_searchIndexInfo.

◆ splitSearchTokens()

void splitSearchTokens ( QCString & title,
IntVector & indices )
static

helper function to simplify the given title string, and fill a list of start positions for the start of each word in the simplified title string.

Definition at line 88 of file searchindex_js.cpp.

89{
90 if (title.isEmpty()) return;
91
92 // simplify title to contain only words with single space as separator
93 size_t di=0;
94 bool lastIsSpace=true;
95 for (size_t si=0; si<title.length(); si++)
96 {
97 char c = title.at(si);
98 if (c=='@' || c=='\\') // skip over special commands
99 {
100 title.at(di)=' ';
101 if (si<title.length()-1)
102 {
103 c = title.at(++si);
104 while (si<title.length() && (isId(c) || c==':')) c = title.at(++si);
105 --si;
106 }
107 }
108 else if (c=='<') // skip over html tags
109 {
110 if (si<title.length()-1)
111 {
112 for (size_t tsi = si; tsi<title.length(); ++tsi)
113 {
114 if (title.at(tsi)=='>')
115 {
116 si=tsi;
117 break;
118 }
119 }
120 }
121 }
122 else if (isId(c) || c==':') // add "word" character
123 {
124 title.at(di)=c;
125 di++;
126 lastIsSpace=false;
127 }
128 else if (!lastIsSpace) // add one separator as space
129 {
130 title.at(di)=' ';
131 di++;
132 lastIsSpace=true;
133 }
134 }
135 if (di>0 && title.at(di-1)==' ') di--; // strip trailing whitespace
136 title.resize(di);
137
138 // create a list of start positions within title for
139 // each unique word in order of appearance
140 int p=0,i=0;
141 while ((i=title.find(' ',p))!=-1)
142 {
143 std::string word = title.mid(p,i-p).str();
144 indices.push_back(p);
145 p = i+1;
146 }
147 if (p<static_cast<int>(title.length()))
148 {
149 std::string word = title.mid(p).str();
150 indices.push_back(p);
151 }
152}
int find(char c, int index=0, bool cs=TRUE) const
Definition qcstring.cpp:43
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:153
char & at(size_t i)
Returns a reference to the character at index i.
Definition qcstring.h:578
void resize(size_t newlen)
Definition qcstring.h:167
size_t i
Definition htmlgen.cpp:161
bool isId(int c)
Definition util.h:208

References QCString::at(), QCString::find(), i, QCString::isEmpty(), isId(), QCString::length(), QCString::mid(), QCString::resize(), and QCString::str().

Referenced by createJavaScriptSearchIndex().

◆ writeJavascriptSearchData()

void writeJavascriptSearchData ( const QCString & searchDirName)
static

Definition at line 522 of file searchindex_js.cpp.

523{
524 std::ofstream t = Portable::openOutputStream(searchDirName+"/searchdata.js");
525 if (t.is_open())
526 {
527 t << "var indexSectionsWithContent =\n";
528 t << "{\n";
529 int j=0;
530 for (const auto &sii : g_searchIndexInfo)
531 {
532 if (!sii.symbolMap.empty())
533 {
534 if (j>0) t << ",\n";
535 t << " " << j << ": \"";
536
537 std::string previous_letter; // start with value that does not exist in the map
538 for (const auto &[letter,list] : sii.symbolMap)
539 {
540 if (letter != previous_letter)
541 {
542 if ( letter == "\"" ) t << "\\"; // add escape for backslash
543 t << letter;
544 previous_letter = letter;
545 }
546 }
547 t << "\"";
548 j++;
549 }
550 }
551 if (j>0) t << "\n";
552 t << "};\n\n";
553 t << "var indexSectionNames =\n";
554 t << "{\n";
555 j=0;
556 for (const auto &sii : g_searchIndexInfo)
557 {
558 if (!sii.symbolMap.empty())
559 {
560 if (j>0) t << ",\n";
561 t << " " << j << ": \"" << convertToJSString(sii.name,true,false) << "\"";
562 j++;
563 }
564 }
565 if (j>0) t << "\n";
566 t << "};\n\n";
567 t << "var indexSectionLabels =\n";
568 t << "{\n";
569 j=0;
570 for (const auto &sii : g_searchIndexInfo)
571 {
572 if (!sii.symbolMap.empty())
573 {
574 if (j>0) t << ",\n";
575 t << " " << j << ": \"" << convertToJSString(convertToXML(sii.getText()),true,false) << "\"";
576 j++;
577 }
578 }
579 if (j>0) t << "\n";
580 t << "};\n\n";
581 }
582}
std::ofstream openOutputStream(const QCString &name, bool append=false)
Definition portable.cpp:665
QCString convertToJSString(const QCString &s, bool keepEntities, bool singleQuotes)
Definition util.cpp:4537
QCString convertToXML(const QCString &s, bool keepEntities)
Definition util.cpp:4426

References convertToJSString(), convertToXML(), g_searchIndexInfo, and Portable::openOutputStream().

Referenced by writeJavaScriptSearchIndex().

◆ writeJavaScriptSearchIndex()

void writeJavaScriptSearchIndex ( )

Definition at line 795 of file searchindex_js.cpp.

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

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

◆ writeJavasScriptSearchDataPage()

void writeJavasScriptSearchDataPage ( const QCString & baseName,
const QCString & dataFileName,
const SearchIndexList & list )
static

Definition at line 584 of file searchindex_js.cpp.

585{
586 auto isDef = [](const SearchTerm::LinkInfo &info)
587 {
588 return std::holds_alternative<const Definition *>(info);
589 };
590 auto getDef = [&isDef](const SearchTerm::LinkInfo &info)
591 {
592 return isDef(info) ? std::get<const Definition *>(info) : nullptr;
593 };
594 auto isSection = [](const SearchTerm::LinkInfo &info)
595 {
596 return std::holds_alternative<const SectionInfo *>(info);
597 };
598 auto getSection = [&isSection](const SearchTerm::LinkInfo &info)
599 {
600 return isSection(info) ? std::get<const SectionInfo *>(info) : nullptr;
601 };
602
603 int cnt = 0;
604 std::ofstream ti = Portable::openOutputStream(dataFileName);
605 if (!ti.is_open())
606 {
607 err("Failed to open file '{}' for writing...\n",dataFileName);
608 return;
609 }
610
611 ti << "var searchData=\n";
612 // format
613 // searchData[] = array of items
614 // searchData[x][0] = id
615 // searchData[x][1] = [ name + child1 + child2 + .. ]
616 // searchData[x][1][0] = name as shown
617 // searchData[x][1][y+1] = info for child y
618 // searchData[x][1][y+1][0] = url
619 // searchData[x][1][y+1][1] = 1 => target="_parent"
620 // searchData[x][1][y+1][1] = 0 => target="_blank"
621 // searchData[x][1][y+1][2] = scope
622
623 ti << "[\n";
624 bool firstEntry=TRUE;
625
626 int childCount=0;
627 QCString lastWord;
628 const Definition *prevScope = nullptr;
629 for (auto it = list.begin(); it!=list.end();)
630 {
631 const SearchTerm &term = *it;
632 const SearchTerm::LinkInfo info = term.info;
633 const Definition *d = getDef(info);
634 const SectionInfo *si = getSection(info);
635 assert(d || si); // either d or si should be valid
636 QCString word = term.word;
637 QCString id = term.termEncoded();
638 ++it;
639 const Definition *scope = d ? d->getOuterScope() : nullptr;
640 const SearchTerm::LinkInfo next = it!=list.end() ? it->info : SearchTerm::LinkInfo();
641 const Definition *nextScope = isDef(next) ? getDef(next)->getOuterScope() : nullptr;
642 const MemberDef *md = toMemberDef(d);
643 QCString anchor = d ? d->anchor() : si ? si->label() : QCString();
644
645 if (word!=lastWord) // this item has a different search word
646 {
647 if (!firstEntry)
648 {
649 ti << "]]]";
650 ti << ",\n";
651 }
652 firstEntry=FALSE;
653 ti << " ['" << id << "_" << cnt++ << "',['";
654 if (next==SearchTerm::LinkInfo() || it->word!=word) // unique result, show title
655 {
656 ti << convertToJSString(convertToXML(term.title),true,true);
657 }
658 else // multiple results, show matching word only, expanded list will show title
659 {
660 ti << convertToJSString(convertToXML(term.word),true,true);
661 }
662 ti << "',[";
663 childCount=0;
664 prevScope=nullptr;
665 }
666
667 if (childCount>0)
668 {
669 ti << "],[";
670 }
671 QCString fn = d ? d->getOutputFileBase() : si ? si->fileName() : QCString();
672 QCString ref = d ? d->getReference() : si ? si->ref() : QCString();
674 QCString extRef = externalRef("../",ref,true)+fn;
675 if (!anchor.isEmpty())
676 {
677 extRef+="#"+anchor;
678 }
679 ti << "'" << convertToJSString(extRef,true,true) << "',";
680
681 bool extLinksInWindow = Config_getBool(EXT_LINKS_IN_WINDOW);
682 if (!extLinksInWindow || ref.isEmpty())
683 {
684 ti << "1,";
685 }
686 else
687 {
688 ti << "0,";
689 }
690
691 if (lastWord!=word && (next==SearchTerm::LinkInfo() || it->word!=word)) // unique search result
692 {
693 if (d && d->getOuterScope()!=Doxygen::globalScope)
694 {
695 ti << "'" << convertToJSString(convertToXML(d->getOuterScope()->name()),true,true) << "'";
696 }
697 else if (md)
698 {
699 const FileDef *fd = md->getBodyDef();
700 if (fd==nullptr) fd = md->getFileDef();
701 if (fd)
702 {
703 ti << "'" << convertToJSString(convertToXML(fd->localName()),true,true) << "'";
704 }
705 }
706 else
707 {
708 ti << "''";
709 }
710 }
711 else // multiple entries with the same name
712 {
713 bool found=FALSE;
714 bool overloadedFunction = ((prevScope!=nullptr && scope==prevScope) || (scope && scope==nextScope)) &&
715 md && md->isCallable();
717 if (md) prefix=convertToXML(md->localName());
718 if (overloadedFunction) // overloaded member function
719 {
721 // show argument list to disambiguate overloaded functions
722 }
723 else if (md && md->isCallable()) // unique member function
724 {
725 prefix+="()"; // only to show it is a callable symbol
726 }
727 QCString name;
728 if (d)
729 {
730 switch (d->definitionType())
731 {
732 case Definition::TypeClass: name = convertToXML((toClassDef(d))->displayName()); found=true; break;
733 case Definition::TypeNamespace: name = convertToXML((toNamespaceDef(d))->displayName()); found=true; break;
734 case Definition::TypeModule: name = convertToXML(d->name()+" "+theTranslator->trModule(false,true)); found=true; break;
735 case Definition::TypePage: name = convertToXML(filterTitle(toPageDef(d)->title())); found=true; break;
736 case Definition::TypeGroup: name = convertToXML(filterTitle(toGroupDef(d)->groupTitle())); found=true; break;
737 default:
738 if (scope==nullptr || scope==Doxygen::globalScope) // in global scope
739 {
740 if (md)
741 {
742 const FileDef *fd = md->getBodyDef();
743 if (fd==nullptr) fd = md->resolveAlias()->getFileDef();
744 if (fd)
745 {
746 if (!prefix.isEmpty()) prefix+=":&#160;";
747 name = prefix + convertToXML(fd->localName());
748 found = true;
749 }
750 }
751 }
752 else if (md && (md->resolveAlias()->getClassDef() || md->resolveAlias()->getNamespaceDef()))
753 // member in class or namespace scope
754 {
755 SrcLangExt lang = md->getLanguage();
757 name = convertToXML(d->getOuterScope()->qualifiedName()) + sep + prefix;
758 found = true;
759 }
760 else if (scope) // some thing else? -> show scope
761 {
762 name = prefix + convertToXML(scope->name());
763 found = true;
764 }
765 break;
766 }
767 }
768 else if (si)
769 {
770 name = parseCommentAsHtml(si->definition(),nullptr,si->title(),si->fileName(),si->lineNr());
771 name = convertToXML(name);
772 found = true;
773 }
774 if (!found) // fallback
775 {
776 name = prefix + "("+theTranslator->trGlobalNamespace()+")";
777 }
778
779 ti << "'" << convertToJSString(name,true,true) << "'";
780
781 prevScope = scope;
782 childCount++;
783 }
784 lastWord = word;
785 }
786 if (!firstEntry)
787 {
788 ti << "]]]\n";
789 }
790 ti << "];\n";
791 Doxygen::indexList->addStyleSheetFile(("search/"+baseName+".js").data());
792}
constexpr auto prefix
Definition anchor.cpp:44
The common base class of all entity definitions found in the sources.
Definition definition.h:76
virtual const QCString & localName() const =0
virtual SrcLangExt getLanguage() const =0
Returns the programming language this definition was written in.
virtual DefType definitionType() const =0
virtual QCString anchor() const =0
virtual const FileDef * getBodyDef() const =0
virtual QCString getReference() const =0
virtual QCString qualifiedName() const =0
virtual QCString getOutputFileBase() const =0
virtual Definition * getOuterScope() const =0
static NamespaceDefMutable * globalScope
Definition doxygen.h:121
A model of a class/file/namespace member symbol.
Definition memberdef.h:48
virtual MemberDef * resolveAlias()=0
virtual QCString argsString() const =0
virtual bool isCallable() const =0
class that provide information about a section.
Definition section.h:57
QCString label() const
Definition section.h:68
Definition * definition() const
Definition section.h:76
QCString ref() const
Definition section.h:71
QCString fileName() const
Definition section.h:73
int lineNr() const
Definition section.h:72
QCString title() const
Definition section.h:69
ClassDef * toClassDef(Definition *d)
GroupDef * toGroupDef(Definition *d)
const char * data
Definition htmlgen.cpp:158
int cnt
Definition htmlgen.cpp:160
Translator * theTranslator
Definition language.cpp:71
MemberDef * toMemberDef(Definition *d)
#define err(fmt,...)
Definition message.h:127
#define term(fmt,...)
Definition message.h:137
NamespaceDef * toNamespaceDef(Definition *d)
PageDef * toPageDef(Definition *d)
Definition pagedef.cpp:490
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34
std::variant< std::monostate, const Definition *, const SectionInfo * > LinkInfo
SrcLangExt
Definition types.h:207
QCString externalRef(const QCString &relPath, const QCString &ref, bool href)
Definition util.cpp:6270
QCString parseCommentAsHtml(const Definition *scope, const MemberDef *member, const QCString &doc, const QCString &fileName, int lineNr)
Definition util.cpp:5931
QCString getLanguageSpecificSeparator(SrcLangExt lang, bool classScope)
Returns the scope separator to use given the programming language lang.
Definition util.cpp:6414
void addHtmlExtensionIfMissing(QCString &fName)
Definition util.cpp:5416

References addHtmlExtensionIfMissing(), Definition::anchor(), MemberDef::argsString(), cnt, Config_getBool, convertToJSString(), convertToXML(), data, SectionInfo::definition(), Definition::definitionType(), err, externalRef(), FALSE, SectionInfo::fileName(), filterTitle(), Definition::getBodyDef(), MemberDef::getClassDef(), MemberDef::getFileDef(), Definition::getLanguage(), getLanguageSpecificSeparator(), MemberDef::getNamespaceDef(), Definition::getOuterScope(), Definition::getOutputFileBase(), Definition::getReference(), Doxygen::globalScope, Doxygen::indexList, MemberDef::isCallable(), QCString::isEmpty(), SectionInfo::label(), SectionInfo::lineNr(), Definition::localName(), Definition::name(), Portable::openOutputStream(), parseCommentAsHtml(), prefix, Definition::qualifiedName(), SectionInfo::ref(), MemberDef::resolveAlias(), term, theTranslator, SectionInfo::title(), toClassDef(), toGroupDef(), toMemberDef(), toNamespaceDef(), toPageDef(), TRUE, Definition::TypeClass, Definition::TypeGroup, Definition::TypeModule, Definition::TypeNamespace, and Definition::TypePage.

Referenced by writeJavaScriptSearchIndex().

Variable Documentation

◆ g_searchIndexInfo

std::array<SearchIndexInfo,NUM_SEARCH_INDICES> g_searchIndexInfo
static

Definition at line 179 of file searchindex_js.cpp.

180{ {
181 // index name getText symbolList
182 { /* SEARCH_INDEX_ALL */ "all" , []() { return theTranslator->trAll(); }, {} },
183 { /* SEARCH_INDEX_CLASSES */ "classes" , []() { return theTranslator->trClasses(); }, {} },
184 { /* SEARCH_INDEX_INTERFACES */ "interfaces" , []() { return theTranslator->trSliceInterfaces(); }, {} },
185 { /* SEARCH_INDEX_STRUCTS */ "structs" , []() { return theTranslator->trStructs(); }, {} },
186 { /* SEARCH_INDEX_EXCEPTIONS */ "exceptions" , []() { return theTranslator->trExceptions(); }, {} },
187 { /* SEARCH_INDEX_NAMESPACES */ "namespaces" , []() { return Config_getBool(OPTIMIZE_OUTPUT_SLICE) ?
188 theTranslator->trModules() :
189 theTranslator->trNamespace(TRUE,FALSE); }, {} },
190 { /* SEARCH_INDEX_FILES */ "files" , []() { return theTranslator->trFile(TRUE,FALSE); }, {} },
191 { /* SEARCH_INDEX_FUNCTIONS */ "functions" , []() { return Config_getBool(OPTIMIZE_OUTPUT_SLICE) ?
192 theTranslator->trOperations() :
193 theTranslator->trFunctions(); }, {} },
194 { /* SEARCH_INDEX_VARIABLES */ "variables" , []() { return Config_getBool(OPTIMIZE_OUTPUT_SLICE) ?
195 theTranslator->trConstants() :
196 theTranslator->trVariables(); }, {} },
197 { /* SEARCH_INDEX_TYPEDEFS */ "typedefs" , []() { return theTranslator->trTypedefs(); }, {} },
198 { /* SEARCH_INDEX_SEQUENCES */ "sequences" , []() { return theTranslator->trSequences(); }, {} },
199 { /* SEARCH_INDEX_DICTIONARIES */ "dictionaries", []() { return theTranslator->trDictionaries(); }, {} },
200 { /* SEARCH_INDEX_ENUMS */ "enums" , []() { return theTranslator->trEnumerations(); }, {} },
201 { /* SEARCH_INDEX_ENUMVALUES */ "enumvalues" , []() { return theTranslator->trEnumerationValues(); }, {} },
202 { /* SEARCH_INDEX_PROPERTIES */ "properties" , []() { return theTranslator->trProperties(); }, {} },
203 { /* SEARCH_INDEX_EVENTS */ "events" , []() { return theTranslator->trEvents(); }, {} },
204 { /* SEARCH_INDEX_RELATED */ "related" , []() { return theTranslator->trFriends(); }, {} },
205 { /* SEARCH_INDEX_DEFINES */ "defines" , []() { return theTranslator->trDefines(); }, {} },
206 { /* SEARCH_INDEX_GROUPS */ "groups" , []() { return theTranslator->trGroup(TRUE,FALSE); }, {} },
207 { /* SEARCH_INDEX_PAGES */ "pages" , []() { return theTranslator->trPage(TRUE,FALSE); }, {} },
208 { /* SEARCH_INDEX_CONCEPTS */ "concepts" , []() { return theTranslator->trConcept(true,false); }, {} },
209 { /* SEARCH_INDEX_MODULES */ "modules" , []() { return theTranslator->trModule(true,false); }, {} }
210} };

Referenced by addMemberToSearchIndex(), createJavaScriptSearchIndex(), getSearchIndices(), writeJavascriptSearchData(), and writeJavaScriptSearchIndex().