summaryrefslogtreecommitdiff
path: root/src/searchindex_js.h
blob: b46f0ba738ebaa2b02e6214742362cde4028152a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/******************************************************************************
 *
 * Copyright (C) 1997-2022 by Dimitri van Heesch.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby
 * granted. No representations are made about the suitability of this software
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
 * Documents produced by Doxygen are derivative works derived from the
 * input used in their production; they are not affected by this license.
 *
 */

/** @file
 *  @brief Javascript based search engine.
 */

#ifndef SEARCHINDEX_JS_H
#define SEARCHINDEX_JS_H

#include <array>
#include <vector>
#include <map>
#include <string>
#include <functional>
#include <variant>

#include "qcstring.h"
#include "utf8.h"

#define NUM_SEARCH_INDICES 22

class SectionInfo;
class Definition;

//QCString searchId(const Definition *d);
QCString searchName(const Definition *d);

//! Searchable term
struct SearchTerm
{
  using LinkInfo = std::variant<std::monostate,const Definition *,const SectionInfo *>;
  SearchTerm(const QCString &w,const Definition *d)  : word(convertUTF8ToLower(w.str())), info(d)  { makeTitle(); }
  SearchTerm(const QCString &w,const SectionInfo *s) : word(convertUTF8ToLower(w.str())), info(s)  { makeTitle(); }
  QCString word;                 //!< lower case word that is indexed (e.g. name of a symbol, or word from a title)
  QCString title;                //!< title to show in the output for this search result
  LinkInfo info;                 //!< definition to link to
  QCString termEncoded() const;  //!< encoded version of the search term
private:
  void makeTitle();
};

//! List of search terms
using SearchIndexList = std::vector<SearchTerm>;

//! Map of search terms for a given starting letter
using SearchIndexMap  = std::map<std::string,SearchIndexList>; // key is starting letter of a term (UTF-8).

//! Table entry to allow filtering the search results per category
struct SearchIndexInfo
{
  void add(const SearchTerm &term);
  QCString name;
  std::function<QCString()> getText;
  SearchIndexMap symbolMap;
};

void createJavaScriptSearchIndex();
void writeJavaScriptSearchIndex();
const std::array<SearchIndexInfo,NUM_SEARCH_INDICES> &getSearchIndices();

#endif