Imported Upstream version 1.8.15
[platform/upstream/doxygen.git] / doc / extsearch.doc
1 /******************************************************************************
2  *
3  * Copyright (C) 1997-2015 by Dimitri van Heesch.
4  *
5  * Permission to use, copy, modify, and distribute this software and its
6  * documentation under the terms of the GNU General Public License is hereby 
7  * granted. No representations are made about the suitability of this software 
8  * for any purpose. It is provided "as is" without express or implied warranty.
9  * See the GNU General Public License for more details.
10  *
11  * Documents produced by Doxygen are derivative works derived from the
12  * input used in their production; they are not affected by this license.
13  *
14  */
15 /*! \page extsearch External Indexing and Searching
16
17 [TOC]
18
19 \section extsearch_intro Introduction
20
21 With release 1.8.3, doxygen provides the ability to search through HTML using
22 an external indexing tool and search engine.
23 This has several advantages:
24 - For large projects it can have significant performance advantages over
25   doxygen's built-in search engine, as doxygen uses a rather simple indexing
26   algorithm.
27 - It allows combining the search data of multiple projects into one index,
28   allowing a global search across multiple doxygen projects.
29 - It allows adding additional data to the search index, i.e. other web pages
30   not produced by doxygen.
31 - The search engine needs to run on a web server, but clients can still browse
32   the web pages locally.
33
34 To avoid that everyone has to start writing their own indexer and search 
35 engine, doxygen provides an example tool for each action: `doxyindexer` 
36 for indexing the data and `doxysearch.cgi` for searching through the index.
37
38 The data flow is shown in the following diagram:
39
40 \image html extsearch_flow.png "External Search Data Flow"
41 \image latex extsearch_flow.eps "External Search Data Flow" height=10cm
42
43 - `doxygen` produces the raw search data
44 - `doxyindexer` indexes the data into a search database `doxysearch.db`
45 - when a user performs a search from a doxygen generated HTML page, 
46   the CGI binary `doxysearch.cgi` will be invoked.
47 - the `doxysearch.cgi` tool will perform a query on the database and return
48   the results. 
49 - The browser will show the search results.
50
51 \section extsearch_config Configuring
52
53 The first step is to make the search engine available via a web server.
54 If you use `doxysearch.cgi` this means making the
55 <a href="https://en.wikipedia.org/wiki/Common_Gateway_Interface">CGI</a> binary
56 available from the web server (i.e. be able to run it from a 
57 browser via an URL starting with http:)
58
59 How to setup a web server is outside the scope of this document,
60 but if you for instance have Apache installed, you could simply copy the 
61 `doxysearch.cgi` file from doxygen's `bin` directory to the `cgi-bin` directory of the
62 Apache web server. Read the <a href="http://httpd.apache.org/docs/2.2/howto/cgi.html">apache documentation</a> for details.
63
64 To test if `doxysearch.cgi` is accessible start your web browser and
65 point to URL to the binary and add `?test` at the end
66
67     http://yoursite.com/path/to/cgi/doxysearch.cgi?test
68
69 You should get the following message:
70
71     Test failed: cannot find search index doxysearch.db
72
73 If you use Internet Explorer you may be prompted to download a file,
74 which will then contain this message. 
75
76 Since we didn't create or install a doxysearch.db it is OK for the test to
77 fail for this reason. How to correct this is discussed in the next section.
78
79 Before continuing with the next section add the above 
80 URL (without the `?test` part) to the `SEARCHENGINE_URL` tag in
81 doxygen's configuration file:
82
83     SEARCHENGINE_URL = http://yoursite.com/path/to/cgi/doxysearch.cgi
84
85 \subsection extsearch_single Single project index
86
87 To use the external search option, make sure the following options are enabled
88 in doxygen's configuration file:
89
90     SEARCHENGINE           = YES
91     SERVER_BASED_SEARCH    = YES
92     EXTERNAL_SEARCH        = YES
93
94 This will make doxygen generate a file called `searchdata.xml` in the output 
95 directory (configured with \ref cfg_output_directory "OUTPUT_DIRECTORY").
96 You can change the file name (and location) with the 
97 \ref cfg_searchdata_file "SEARCHDATA_FILE" option.
98
99 The next step is to put the raw search data into an index for efficient 
100 searching. You can use `doxyindexer` for this. Simply run it from the command 
101 line:
102
103     doxyindexer searchdata.xml
104
105 This will create a directory called `doxysearch.db` with some files in it.
106 By default the directory will be created at the location from which doxyindexer
107 was started, but you can change the directory using the `-o` option.
108
109 Copy the `doxysearch.db` directory to the same directory as where 
110 the `doxysearch.cgi` is located and rerun the browser test by pointing 
111 the browser to
112
113     http://yoursite.com/path/to/cgi/doxysearch.cgi?test
114
115 You should now get the following message:
116
117     Test successful.
118
119 Now you should be able to search for words and symbols from the HTML output.
120
121 \subsection extsearch_multi Multi project index
122
123 In case you have more than one doxygen project and these projects are related, 
124 it may be desirable to allow searching for words in all projects from within 
125 the documentation of any of the projects.
126
127 To make this possible all that is needed is to combine the search data
128 for all projects into a single index, e.g. for two projects A and B for which the
129 searchdata.xml is generated in directories project_A and project_B run:
130
131     doxyindexer project_A/searchdata.xml project_B/searchdata.xml
132
133 and then copy the resulting `doxysearch.db` to the directory where also
134 `doxysearch.cgi` is located.
135
136 The `searchdata.xml` file doesn't contain any absolute paths or links, 
137 so how can the search results from multiple projects be linked back to the right documentation set?
138 This is where the `EXTERNAL_SEARCH_ID` and `EXTRA_SEARCH_MAPPINGS` options come into play.
139
140 To be able to identify the different projects, one needs to
141 set a unique ID using \ref cfg_external_search_id "EXTERNAL_SEARCH_ID"
142 for each project.
143
144 To link the search results to the right project, you need to define a
145 mapping per project using the \ref cfg_extra_search_mappings "EXTRA_SEARCH_MAPPINGS" tag.
146 With this option to can define the mapping from IDs of other projects to the
147 (relative) location of documentation of those projects.
148
149 So for projects A and B the relevant part of the configuration file 
150 could look as follows:
151
152     project_A/Doxyfile
153     ------------------
154     EXTERNAL_SEARCH_ID    = A
155     EXTRA_SEARCH_MAPPINGS = B=../../project_B/html
156
157 for project A and for project B
158
159     project_B/Doxyfile
160     ------------------
161     EXTERNAL_SEARCH_ID    = B
162     EXTRA_SEARCH_MAPPINGS = A=../../project_A/html
163     
164 with these settings, projects A and B can share the same search database,
165 and the search results will link to the right documentation set.
166
167 \section extsearch_update Updating the index
168
169 When you modify the source code, you should re-run doxygen to get up to date
170 documentation again. When using external searching you also need to update the
171 search index by re-running `doxyindexer`. You could wrap the call to doxygen
172 and doxyindexer together in a script to make this process easier.
173
174 \section extsearch_api Programming interface
175
176 Previous sections have assumed you use the tools `doxyindexer` 
177 and `doxysearch.cgi` to do the indexing and searching, but you could also 
178 write your own index and search tools if you like.
179
180 For this 3 interfaces are important
181 - The format of the input for the index tool.
182 - The format of the input for the search engine.
183 - The format of the output of search engine.
184
185 The next subsections describe these interfaces in more detail.
186
187 \subsection extsearch_api_index Indexer input format
188
189 The search data produced by doxygen follows the 
190 <a href="https://wiki.apache.org/solr/UpdateXmlMessages">Solr XML index message</a>
191 format.
192
193 The input for the indexer is an XML file, which consists of one `<add>` tag containing 
194 multiple `<doc>` tags, which in turn contain multiple `<field>` tags. 
195
196 Here is an example of one doc node, which contains the search data and meta data for 
197 one method:
198
199     <add>
200       ...
201       <doc>
202         <field name="type">function</field>
203         <field name="name">QXmlReader::setDTDHandler</field>
204         <field name="args">(QXmlDTDHandler *handler)=0</field>
205         <field name="tag">qtools.tag</field>
206         <field name="url">de/df6/class_q_xml_reader.html#a0b24b1fe26a4c32a8032d68ee14d5dba</field>
207         <field name="keywords">setDTDHandler QXmlReader::setDTDHandler QXmlReader</field>
208         <field name="text">Sets the DTD handler to handler DTDHandler()</field>
209       </doc>
210       ...
211     </add>
212
213 Each field has a name. The following field names are supported:
214 - *type*: the type of the search entry; can be one of: source, function, slot, 
215           signal, variable, typedef, enum, enumvalue, property, event, related, 
216           friend, define, file, namespace, group, package, page, dir
217 - *name*: the name of the search entry; for a method this is the qualified name of the method,
218           for a class it is the name of the class, etc.
219 - *args*: the parameter list (in case of functions or methods)
220 - *tag*:  the name of the tag file used for this project.
221 - *url*:  the (relative) URL to the HTML documentation for this entry.
222 - *keywords*: important words that are representative for the entry. When searching for such
223           keyword, this entry should get a higher rank in the search results.
224 - *text*: the documentation associated with the item. Note that only words are present, no markup.
225
226 @note Due to the potentially large size of the XML file, it is recommended to use a 
227 <a href="https://en.wikipedia.org/wiki/Simple_API_for_XML">SAX based parser</a> to process it.
228
229 \subsection extsearch_api_search_in Search URL format
230
231 When the search engine is invoked from a doxygen generated HTML page, a number of parameters are
232 passed to via the <a href="https://en.wikipedia.org/wiki/Query_string">query string</a>.
233
234 The following fields are passed:
235 - *q*:  the query text as entered by the user
236 - *n*:  the number of search results requested.
237 - *p*:  the number of search page for which to return the results. Each page has *n* values.
238 - *cb*: the name of the callback function, used for JSON with padding, see the next section.
239        
240 From the complete list of search results, the range `[n*p - n*(p+1)-1]` should be returned.
241
242 Here is an example of how a query looks like.
243
244     http://yoursite.com/path/to/cgi/doxysearch.cgi?q=list&n=20&p=1&cb=dummy
245
246 It represents a query for the word 'list' (`q=list`) requesting 20 search results (`n=20`), 
247 starting with the result number 20 (`p=1`) and using callback 'dummy' (`cb=dummy`):
248
249
250 @note The values are <a href="https://en.wikipedia.org/wiki/Percent-encoding">URL encoded</a> so they
251 have to be decoded before they can be used.
252
253 \subsection extsearch_api_search_out Search results format
254
255 When invoking the search engine as shown in the previous subsection, it should reply with
256 the results. The format of the reply is
257 <a href="https://en.wikipedia.org/wiki/JSONP">JSON with padding</a>, which is basically
258 a javascript struct wrapped in a function call. The name of function should be the name of
259 the callback (as passed with the *cb* field in the query).
260
261 With the example query as shown the previous subsection the main structure of the reply should
262 look as follows:
263
264     dummy({
265       "hits":179,
266       "first":20,
267       "count":20,
268       "page":1,
269       "pages":9,
270       "query": "list",
271       "items":[
272       ...
273      ]})
274
275 The fields have the following meaning:
276 - *hits*:  the total number of search results (could be more than was requested).
277 - *first*: the index of first result returned: \f$\min(n*p,\mbox{\em hits})\f$.
278 - *count*: the actual number of results returned: \f$\min(n,\mbox{\em hits}-\mbox{\em first})\f$
279 - *page*:  the page number of the result: \f$p\f$
280 - *pages*: the total number of pages: \f$\lceil\frac{\mbox{\em hits}}{n}\rceil\f$.
281 - *items*: an array containing the search data per result.
282
283 Here is an example of how the element of the *items* array should look like:
284
285     {"type": "function",
286      "name": "QDir::entryInfoList(const QString &nameFilter, int filterSpec=DefaultFilter, int sortSpec=DefaultSort) const",
287      "tag": "qtools.tag",
288      "url": "d5/d8d/class_q_dir.html#a9439ea6b331957f38dbad981c4d050ef",
289      "fragments":[
290        "Returns a <span class=\"hl\">list</span> of QFileInfo objects for all files and directories...",
291        "... pointer to a QFileInfoList The <span class=\"hl\">list</span> is owned by the QDir object...",
292        "... to keep the entries of the <span class=\"hl\">list</span> after a subsequent call to this..."
293      ]
294     },
295
296 The fields for such an item have the following meaning:
297 - *type*: the type of the item, as found in the field with name "type" in the raw search data.
298 - *name*: the name of the item, including the parameter list, as found in the fields with
299           name "name" and "args" in the raw search data.
300 - *tag*:  the name of the tag file, as found in the field with name "tag" in the raw search data.
301 - *url*:  the name of the (relative) URL to the documentation, as found in the field with name "url"
302           in the raw search data.
303 - "fragments": an array with 0 or more fragments of text containing words that have been search for.
304           These words should be wrapped in `<span class="hl">` and `</span>` tags to highlight them
305           in the output.
306 */