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

Referenced by addMemberToSearchIndex(), and createJavaScriptSearchIndex().

◆ SEARCH_INDEX_CLASSES

#define SEARCH_INDEX_CLASSES   1

Definition at line 134 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_CONCEPTS

#define SEARCH_INDEX_CONCEPTS   20

Definition at line 153 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_DEFINES

#define SEARCH_INDEX_DEFINES   17

Definition at line 150 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_DICTIONARIES

#define SEARCH_INDEX_DICTIONARIES   11

Definition at line 144 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_ENUMS

#define SEARCH_INDEX_ENUMS   12

Definition at line 145 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_ENUMVALUES

#define SEARCH_INDEX_ENUMVALUES   13

Definition at line 146 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_EVENTS

#define SEARCH_INDEX_EVENTS   15

Definition at line 148 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_EXCEPTIONS

#define SEARCH_INDEX_EXCEPTIONS   4

Definition at line 137 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_FILES

#define SEARCH_INDEX_FILES   6

Definition at line 139 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_FUNCTIONS

#define SEARCH_INDEX_FUNCTIONS   7

Definition at line 140 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_GROUPS

#define SEARCH_INDEX_GROUPS   18

Definition at line 151 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_INTERFACES

#define SEARCH_INDEX_INTERFACES   2

Definition at line 135 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_MODULES

#define SEARCH_INDEX_MODULES   21

Definition at line 154 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_NAMESPACES

#define SEARCH_INDEX_NAMESPACES   5

Definition at line 138 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_PAGES

#define SEARCH_INDEX_PAGES   19

Definition at line 152 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_PROPERTIES

#define SEARCH_INDEX_PROPERTIES   14

Definition at line 147 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_RELATED

#define SEARCH_INDEX_RELATED   16

Definition at line 149 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_SEQUENCES

#define SEARCH_INDEX_SEQUENCES   10

Definition at line 143 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_STRUCTS

#define SEARCH_INDEX_STRUCTS   3

Definition at line 136 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_TYPEDEFS

#define SEARCH_INDEX_TYPEDEFS   9

Definition at line 142 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_VARIABLES

#define SEARCH_INDEX_VARIABLES   8

Definition at line 141 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

Function Documentation

◆ addMemberToSearchIndex()

static void addMemberToSearchIndex ( const MemberDef * md)
static

Definition at line 189 of file searchindex_js.cpp.

190{
191 bool hideFriendCompounds = Config_getBool(HIDE_FRIEND_COMPOUNDS);
192 bool isLinkable = md->isLinkable();
193 const ClassDef *cd=nullptr;
194 const NamespaceDef *nd=nullptr;
195 const FileDef *fd=nullptr;
196 const GroupDef *gd=nullptr;
197 if (isLinkable &&
198 (
199 ((cd=md->getClassDef()) && cd->isLinkable() && cd->templateMaster()==nullptr) ||
200 ((gd=md->getGroupDef()) && gd->isLinkable())
201 )
202 )
203 {
204 QCString n = md->name();
205 if (!n.isEmpty())
206 {
207 bool isFriendToHide = hideFriendCompounds &&
208 (QCString(md->typeString())=="friend class" ||
209 QCString(md->typeString())=="friend struct" ||
210 QCString(md->typeString())=="friend union");
211 if (!(md->isFriend() && isFriendToHide))
212 {
214 }
215 if (md->isFunction() || md->isSlot() || md->isSignal())
216 {
218 }
219 else if (md->isVariable())
220 {
222 }
223 else if (md->isSequence())
224 {
226 }
227 else if (md->isDictionary())
228 {
230 }
231 else if (md->isTypedef())
232 {
234 }
235 else if (md->isEnumerate())
236 {
238 }
239 else if (md->isEnumValue())
240 {
242 }
243 else if (md->isProperty())
244 {
246 }
247 else if (md->isEvent())
248 {
250 }
251 else if (md->isRelated() || md->isForeign() ||
252 (md->isFriend() && !isFriendToHide))
253 {
255 }
256 }
257 }
258 else if (isLinkable &&
259 (((nd=md->getNamespaceDef()) && nd->isLinkable()) ||
260 ((fd=md->getFileDef()) && fd->isLinkable())
261 )
262 )
263 {
264 QCString n = md->name();
265 if (!n.isEmpty())
266 {
268
269 if (md->isFunction())
270 {
272 }
273 else if (md->isVariable())
274 {
276 }
277 else if (md->isSequence())
278 {
280 }
281 else if (md->isDictionary())
282 {
284 }
285 else if (md->isTypedef())
286 {
288 }
289 else if (md->isEnumerate())
290 {
292 }
293 else if (md->isEnumValue())
294 {
296 }
297 else if (md->isDefine())
298 {
300 }
301 }
302 }
303}
A abstract class representing of a compound symbol.
Definition classdef.h:104
virtual const ClassDef * templateMaster() const =0
Returns the template master of which this class is an instance.
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(), 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, ClassDef::templateMaster(), and MemberDef::typeString().

Referenced by addToIndices(), and createJavaScriptSearchIndex().

◆ 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()
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:175
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
#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:5921

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.

◆ splitSearchTokens()

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

90{
91 if (title.isEmpty()) return;
92
93 // simplify title to contain only words with single space as separator
94 size_t di=0;
95 bool lastIsSpace=true;
96 for (size_t si=0; si<title.length(); si++)
97 {
98 char c = title.at(si);
99 if (isId(c) || c==':') // add "word" character
100 {
101 title.at(di)=c;
102 di++;
103 lastIsSpace=false;
104 }
105 else if (!lastIsSpace) // add one separator as space
106 {
107 title.at(di)=' ';
108 di++;
109 lastIsSpace=true;
110 }
111 }
112 if (di>0 && title.at(di-1)==' ') di--; // strip trailing whitespace
113 title.resize(di);
114
115 // create a list of start positions within title for
116 // each unique word in order of appearance
117 int p=0,i=0;
118 while ((i=title.find(' ',p))!=-1)
119 {
120 std::string word = title.mid(p,i-p).str();
121 indices.push_back(p);
122 p = i+1;
123 }
124 if (p<static_cast<int>(title.length()))
125 {
126 std::string word = title.mid(p).str();
127 indices.push_back(p);
128 }
129}
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
std::string_view word
Definition util.cpp:980
bool isId(int c)
Definition util.h:202

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

Referenced by createJavaScriptSearchIndex().

◆ writeJavascriptSearchData()

static void writeJavascriptSearchData ( const QCString & searchDirName)
static

Definition at line 497 of file searchindex_js.cpp.

498{
499 std::ofstream t = Portable::openOutputStream(searchDirName+"/searchdata.js");
500 if (t.is_open())
501 {
502 t << "var indexSectionsWithContent =\n";
503 t << "{\n";
504 int j=0;
505 for (const auto &sii : g_searchIndexInfo)
506 {
507 if (!sii.symbolMap.empty())
508 {
509 if (j>0) t << ",\n";
510 t << " " << j << ": \"";
511
512 std::string previous_letter; // start with value that does not exist in the map
513 for (const auto &[letter,list] : sii.symbolMap)
514 {
515 if (letter != previous_letter)
516 {
517 if ( letter == "\"" ) t << "\\"; // add escape for backslash
518 t << letter;
519 previous_letter = letter;
520 }
521 }
522 t << "\"";
523 j++;
524 }
525 }
526 if (j>0) t << "\n";
527 t << "};\n\n";
528 t << "var indexSectionNames =\n";
529 t << "{\n";
530 j=0;
531 for (const auto &sii : g_searchIndexInfo)
532 {
533 if (!sii.symbolMap.empty())
534 {
535 if (j>0) t << ",\n";
536 t << " " << j << ": \"" << sii.name << "\"";
537 j++;
538 }
539 }
540 if (j>0) t << "\n";
541 t << "};\n\n";
542 t << "var indexSectionLabels =\n";
543 t << "{\n";
544 j=0;
545 for (const auto &sii : g_searchIndexInfo)
546 {
547 if (!sii.symbolMap.empty())
548 {
549 if (j>0) t << ",\n";
550 t << " " << j << ": \"" << convertToXML(sii.getText()) << "\"";
551 j++;
552 }
553 }
554 if (j>0) t << "\n";
555 t << "};\n\n";
556 }
557}
std::ofstream openOutputStream(const QCString &name, bool append=false)
Definition portable.cpp:665
QCString convertToXML(const QCString &s, bool keepEntities)
Definition util.cpp:4266

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

Referenced by writeJavaScriptSearchIndex().

◆ 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
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:7139

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

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

Definition at line 559 of file searchindex_js.cpp.

560{
561 auto isDef = [](const SearchTerm::LinkInfo &info)
562 {
563 return std::holds_alternative<const Definition *>(info);
564 };
565 auto getDef = [&isDef](const SearchTerm::LinkInfo &info)
566 {
567 return isDef(info) ? std::get<const Definition *>(info) : nullptr;
568 };
569 auto isSection = [](const SearchTerm::LinkInfo &info)
570 {
571 return std::holds_alternative<const SectionInfo *>(info);
572 };
573 auto getSection = [&isSection](const SearchTerm::LinkInfo &info)
574 {
575 return isSection(info) ? std::get<const SectionInfo *>(info) : nullptr;
576 };
577
578 int cnt = 0;
579 std::ofstream ti = Portable::openOutputStream(dataFileName);
580 if (!ti.is_open())
581 {
582 err("Failed to open file '%s' for writing...\n",qPrint(dataFileName));
583 return;
584 }
585
586 ti << "var searchData=\n";
587 // format
588 // searchData[] = array of items
589 // searchData[x][0] = id
590 // searchData[x][1] = [ name + child1 + child2 + .. ]
591 // searchData[x][1][0] = name as shown
592 // searchData[x][1][y+1] = info for child y
593 // searchData[x][1][y+1][0] = url
594 // searchData[x][1][y+1][1] = 1 => target="_parent"
595 // searchData[x][1][y+1][1] = 0 => target="_blank"
596 // searchData[x][1][y+1][2] = scope
597
598 ti << "[\n";
599 bool firstEntry=TRUE;
600
601 int childCount=0;
602 QCString lastWord;
603 const Definition *prevScope = nullptr;
604 for (auto it = list.begin(); it!=list.end();)
605 {
606 const SearchTerm &term = *it;
607 const SearchTerm::LinkInfo info = term.info;
608 const Definition *d = getDef(info);
609 const SectionInfo *si = getSection(info);
610 assert(d || si); // either d or si should be valid
611 QCString word = term.word;
612 QCString id = term.termEncoded();
613 ++it;
614 const Definition *scope = d ? d->getOuterScope() : nullptr;
615 const SearchTerm::LinkInfo next = it!=list.end() ? it->info : SearchTerm::LinkInfo();
616 const Definition *nextScope = isDef(next) ? getDef(next)->getOuterScope() : nullptr;
617 const MemberDef *md = toMemberDef(d);
618 QCString anchor = d ? d->anchor() : si ? si->label() : QCString();
619
620 if (word!=lastWord) // this item has a different search word
621 {
622 if (!firstEntry)
623 {
624 ti << "]]]";
625 ti << ",\n";
626 }
627 firstEntry=FALSE;
628 ti << " ['" << id << "_" << cnt++ << "',['";
629 if (next==SearchTerm::LinkInfo() || it->word!=word) // unique result, show title
630 {
631 ti << convertToXML(term.title);
632 }
633 else // multiple results, show matching word only, expanded list will show title
634 {
635 ti << convertToXML(term.word);
636 }
637 ti << "',[";
638 childCount=0;
639 prevScope=nullptr;
640 }
641
642 if (childCount>0)
643 {
644 ti << "],[";
645 }
646 QCString fn = d ? d->getOutputFileBase() : si ? si->fileName() : QCString();
647 QCString ref = d ? d->getReference() : si ? si->ref() : QCString();
649 ti << "'" << externalRef("../",ref,TRUE) << fn;
650 if (!anchor.isEmpty())
651 {
652 ti << "#" << anchor;
653 }
654 ti << "',";
655
656 bool extLinksInWindow = Config_getBool(EXT_LINKS_IN_WINDOW);
657 if (!extLinksInWindow || ref.isEmpty())
658 {
659 ti << "1,";
660 }
661 else
662 {
663 ti << "0,";
664 }
665
666 if (lastWord!=word && (next==SearchTerm::LinkInfo() || it->word!=word)) // unique search result
667 {
668 if (d && d->getOuterScope()!=Doxygen::globalScope)
669 {
670 ti << "'" << convertToXML(d->getOuterScope()->name()) << "'";
671 }
672 else if (md)
673 {
674 const FileDef *fd = md->getBodyDef();
675 if (fd==nullptr) fd = md->getFileDef();
676 if (fd)
677 {
678 ti << "'" << convertToXML(fd->localName()) << "'";
679 }
680 }
681 else
682 {
683 ti << "''";
684 }
685 }
686 else // multiple entries with the same name
687 {
688 bool found=FALSE;
689 bool overloadedFunction = ((prevScope!=nullptr && scope==prevScope) || (scope && scope==nextScope)) &&
690 md && md->isCallable();
692 if (md) prefix=convertToXML(md->localName());
693 if (overloadedFunction) // overloaded member function
694 {
696 // show argument list to disambiguate overloaded functions
697 }
698 else if (md && md->isCallable()) // unique member function
699 {
700 prefix+="()"; // only to show it is a callable symbol
701 }
702 QCString name;
703 if (d)
704 {
705 switch (d->definitionType())
706 {
707 case Definition::TypeClass: name = convertToXML((toClassDef(d))->displayName()); found=true; break;
708 case Definition::TypeNamespace: name = convertToXML((toNamespaceDef(d))->displayName()); found=true; break;
709 case Definition::TypeModule: name = convertToXML(d->name()+" "+theTranslator->trModule(false,true)); found=true; break;
710 case Definition::TypePage: name = convertToXML(filterTitle(toPageDef(d)->title())); found=true; break;
711 case Definition::TypeGroup: name = convertToXML(filterTitle(toGroupDef(d)->groupTitle())); found=true; break;
712 default:
713 if (scope==nullptr || scope==Doxygen::globalScope) // in global scope
714 {
715 if (md)
716 {
717 const FileDef *fd = md->getBodyDef();
718 if (fd==nullptr) fd = md->resolveAlias()->getFileDef();
719 if (fd)
720 {
721 if (!prefix.isEmpty()) prefix+=":&#160;";
722 name = prefix + convertToXML(fd->localName());
723 found = true;
724 }
725 }
726 }
727 else if (md && (md->resolveAlias()->getClassDef() || md->resolveAlias()->getNamespaceDef()))
728 // member in class or namespace scope
729 {
730 SrcLangExt lang = md->getLanguage();
732 found = true;
733 }
734 else if (scope) // some thing else? -> show scope
735 {
736 name = prefix + convertToXML(scope->name());
737 found = true;
738 }
739 break;
740 }
741 }
742 else if (si)
743 {
744 name = convertToXML(filterTitle(si->title()));
745 found = true;
746 }
747 if (!found) // fallback
748 {
749 name = prefix + "("+theTranslator->trGlobalNamespace()+")";
750 }
751
752 ti << "'" << name << "'";
753
754 prevScope = scope;
755 childCount++;
756 }
757 lastWord = word;
758 }
759 if (!firstEntry)
760 {
761 ti << "]]]\n";
762 }
763 ti << "];\n";
764 Doxygen::indexList->addStyleSheetFile(("search/"+baseName+".js").data());
765}
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
QCString ref() const
Definition section.h:71
QCString fileName() const
Definition section.h:73
QCString title() const
Definition section.h:69
ClassDef * toClassDef(Definition *d)
GroupDef * toGroupDef(Definition *d)
Translator * theTranslator
Definition language.cpp:71
MemberDef * toMemberDef(Definition *d)
#define err(fmt,...)
Definition message.h:84
#define term(fmt,...)
Definition message.h:94
NamespaceDef * toNamespaceDef(Definition *d)
PageDef * toPageDef(Definition *d)
Definition pagedef.cpp:467
const char * qPrint(const char *s)
Definition qcstring.h:672
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34
std::variant< std::monostate, const Definition *, const SectionInfo * > LinkInfo
SrcLangExt
Language as given by extension.
Definition types.h:42
QCString externalRef(const QCString &relPath, const QCString &ref, bool href)
Definition util.cpp:6066
bool found
Definition util.cpp:984
QCString getLanguageSpecificSeparator(SrcLangExt lang, bool classScope)
Returns the scope separator to use given the programming language lang.
Definition util.cpp:6230
void addHtmlExtensionIfMissing(QCString &fName)
Definition util.cpp:5243

References addHtmlExtensionIfMissing(), Definition::anchor(), MemberDef::argsString(), Config_getBool, convertToXML(), Definition::definitionType(), err, externalRef(), FALSE, SectionInfo::fileName(), filterTitle(), found, 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(), Definition::localName(), Definition::name(), Portable::openOutputStream(), prefix, qPrint(), Definition::qualifiedName(), SectionInfo::ref(), MemberDef::resolveAlias(), term, theTranslator, SectionInfo::title(), toClassDef(), toGroupDef(), toMemberDef(), toNamespaceDef(), toPageDef(), TRUE, Definition::TypeClass, Definition::TypeGroup, Definition::TypeModule, Definition::TypeNamespace, Definition::TypePage, and word.

Referenced by writeJavaScriptSearchIndex().

Variable Documentation

◆ g_searchIndexInfo

std::array<SearchIndexInfo,NUM_SEARCH_INDICES> g_searchIndexInfo
static

Definition at line 156 of file searchindex_js.cpp.

157{ {
158 // index name getText symbolList
159 { /* SEARCH_INDEX_ALL */ "all" , []() { return theTranslator->trAll(); }, {} },
160 { /* SEARCH_INDEX_CLASSES */ "classes" , []() { return theTranslator->trClasses(); }, {} },
161 { /* SEARCH_INDEX_INTERFACES */ "interfaces" , []() { return theTranslator->trSliceInterfaces(); }, {} },
162 { /* SEARCH_INDEX_STRUCTS */ "structs" , []() { return theTranslator->trStructs(); }, {} },
163 { /* SEARCH_INDEX_EXCEPTIONS */ "exceptions" , []() { return theTranslator->trExceptions(); }, {} },
164 { /* SEARCH_INDEX_NAMESPACES */ "namespaces" , []() { return Config_getBool(OPTIMIZE_OUTPUT_SLICE) ?
165 theTranslator->trModules() :
166 theTranslator->trNamespace(TRUE,FALSE); }, {} },
167 { /* SEARCH_INDEX_FILES */ "files" , []() { return theTranslator->trFile(TRUE,FALSE); }, {} },
168 { /* SEARCH_INDEX_FUNCTIONS */ "functions" , []() { return Config_getBool(OPTIMIZE_OUTPUT_SLICE) ?
169 theTranslator->trOperations() :
170 theTranslator->trFunctions(); }, {} },
171 { /* SEARCH_INDEX_VARIABLES */ "variables" , []() { return Config_getBool(OPTIMIZE_OUTPUT_SLICE) ?
172 theTranslator->trConstants() :
173 theTranslator->trVariables(); }, {} },
174 { /* SEARCH_INDEX_TYPEDEFS */ "typedefs" , []() { return theTranslator->trTypedefs(); }, {} },
175 { /* SEARCH_INDEX_SEQUENCES */ "sequences" , []() { return theTranslator->trSequences(); }, {} },
176 { /* SEARCH_INDEX_DICTIONARIES */ "dictionaries", []() { return theTranslator->trDictionaries(); }, {} },
177 { /* SEARCH_INDEX_ENUMS */ "enums" , []() { return theTranslator->trEnumerations(); }, {} },
178 { /* SEARCH_INDEX_ENUMVALUES */ "enumvalues" , []() { return theTranslator->trEnumerationValues(); }, {} },
179 { /* SEARCH_INDEX_PROPERTIES */ "properties" , []() { return theTranslator->trProperties(); }, {} },
180 { /* SEARCH_INDEX_EVENTS */ "events" , []() { return theTranslator->trEvents(); }, {} },
181 { /* SEARCH_INDEX_RELATED */ "related" , []() { return theTranslator->trFriends(); }, {} },
182 { /* SEARCH_INDEX_DEFINES */ "defines" , []() { return theTranslator->trDefines(); }, {} },
183 { /* SEARCH_INDEX_GROUPS */ "groups" , []() { return theTranslator->trGroup(TRUE,FALSE); }, {} },
184 { /* SEARCH_INDEX_PAGES */ "pages" , []() { return theTranslator->trPage(TRUE,FALSE); }, {} },
185 { /* SEARCH_INDEX_CONCEPTS */ "concepts" , []() { return theTranslator->trConcept(true,false); }, {} },
186 { /* SEARCH_INDEX_MODULES */ "modules" , []() { return theTranslator->trModule(true,false); }, {} }
187} };

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