/[hyperestraier]/upstream/0.5.3/doc/pguide-en.html
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /upstream/0.5.3/doc/pguide-en.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (show annotations)
Wed Aug 3 15:25:48 2005 UTC (18 years, 9 months ago) by dpavlin
File MIME type: text/html
File size: 36766 byte(s)
import of upstream 0.5.3

1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
5 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
6
7 <head>
8 <meta http-equiv="Content-Language" content="en" />
9 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
10 <meta http-equiv="Content-Style-Type" content="text/css" />
11 <meta name="author" content="Mikio Hirabayashi" />
12 <meta name="keywords" content="Hyper Estraier, Estraier, full-text search, API" />
13 <meta name="description" content="API specifications of Hyper Estraier" />
14 <link rel="contents" href="./" />
15 <link rel="alternate" href="pguide-ja.html" hreflang="ja" title="the Japanese version" />
16 <link rel="stylesheet" href="common.css" />
17 <link rel="icon" href="icon16.png" />
18 <link rev="made" href="mailto:mikio@users.sourceforge.net" />
19 <title>Programming Guide of Hyper Estraier Version 1</title>
20 </head>
21
22 <body>
23
24 <h1>Programming Guide</h1>
25
26 <div class="note">Copyright (C) 2004-2005 Mikio Hirabayashi</div>
27 <div class="note">Last Update: Mon, 01 Aug 2005 00:50:38 +0900</div>
28 <div class="navi">[<a href="pguide-ja.html" hreflang="ja">Japanese</a>] [<a href="index.html">HOME</a>]</div>
29
30 <hr />
31
32 <h2 id="tableofcontents">Table of Contents</h2>
33
34 <ol>
35 <li><a href="#introduction">Introduction</a></li>
36 <li><a href="#architecture">Architecture</a></li>
37 <li><a href="#building">Building</a></li>
38 <li><a href="#estdoc">API for Documents</a></li>
39 <li><a href="#estcond">API for Search Conditions</a></li>
40 <li><a href="#estdb">API for Database</a></li>
41 <li><a href="#gatherer">Example of Gatherer</a></li>
42 <li><a href="#searcher">Example of Searcher</a></li>
43 <li><a href="#paralleling">Paralleling</a></li>
44 </ol>
45
46 <hr />
47
48 <h2 id="introduction">Introduction</h2>
49
50 <p>This document describes how to use the API of Hyper Estraier. If you have never read <a href="uguide-en.html">the user's guide</a> yet, please do it beforehand.</p>
51
52 <p>The API enables to realize many requirements which is impossible with `estcmd' and `estsearch.cgi' only. While `estcmd' can handle documents as files, it is possible to make an application to handle records in a relational database as a document by using the library. While `estseek.cgi' is accessed with a web browser, it is possible to make an application with a GUI based on the native OS.</p>
53
54 <p>The core API of Hyper Estraier provides some functions to manage the inverted index only. That is, processes of retrieving documents and calculating them are assigned to an application. Also, processes to display the search result is assigned to the application. Consequently, Hyper Estraier does not depend on any document repository, any file format, nor any user interface. They can be selected by the author of the application.</p>
55
56 <p>Hyper Estraier handles Unicode (UCS-2) and present it as UTF-8. That is, most languages in the current world is available. Moreover, because keys of search are extracted from the body text by N-gram method, Hyper Estraier does not depend on any vocabulary.</p>
57
58 <p>One of characteristics of Hyper Estraier is high scalability. So, the author of the application does not need to consider the scalability as long as using the API of Hyper Estraier.</p>
59
60 <p>As this document describes the core API, Hyper Estraier provides the node API based on P2P architecture. Refer to <a href="nguide-en.html">the P2P Guide</a> for the node API.</p>
61
62 <hr />
63
64 <h2 id="architecture">Architecture</h2>
65
66 <p>This section describes the architecture of the core API of Hyper Estraier.</p>
67
68 <h3>Gatherer and Filter</h3>
69
70 <p>The term `gatherer' means functions to register documents to the index. A gatherer is to be implemented in an application. For example, `estcmd' has functions to collect documents by scanning the file system. There are the following procedures.</p>
71
72 <ul>
73 <li>To specify the name of the index and the entry point of scanning, by parsing the command line arguments.</li>
74 <li>To open the index.</li>
75 <li>To scan the file system and specify the paths of the target files.</li>
76 <li>For each file of the list above --<ul>
77 <li>To discriminate the file format by suffix of the name.</li>
78 <li>To read the file if the format is supported.</li>
79 <li>To call the filter function corresponding to the format and create a document object.</li>
80 <li>To register the document object into the index.</li>
81 </ul></li>
82 <li>To close the index.</li>
83 </ul>
84
85 <p>The term `filter' means functions to extract attributes and body text from a file. A filter is implemented in the application. While it can be an own implementation of the application, it can be realized by using some existing library. Moreover, it can be realized by calling an outer command.</p>
86
87 <h3>Searcher</h3>
88
89 <p>The term `searcher' means functions to search the index for some documents corresponding to conditions specified by users. A searcher is implemented in the application. For example, `estseek.cgi' has functions to display the search result as HTML, called as a CGI script by the web server. There is the following procedures.</p>
90
91 <ul>
92 <li>To read such configurations as the name of the index from the configuration file.</li>
93 <li>To parse the parameters of CGI and get the search condition specified by the user.</li>
94 <li>To open the index.</li>
95 <li>To create a search condition object composed of a search phrase, some attribute expressions, an order expression.</li>
96 <li>To give the search condition object to the index and get a list of IDs of documents corresponding the conditions.</li>
97 <li>For each document of the list above --<ul>
98 <li>To retrieve the document object from the index.</li>
99 <li>To display attributes and the snippet.</li>
100 </ul></li>
101 <li>To close the index.</li>
102 </ul>
103
104 <p>Snippet of the body text is useful for the result to be straightforward. While a function is provided to create snippet by the API, the application can implement its own function.</p>
105
106 <h3>Typical Architecture</h3>
107
108 <p>The following is illustration of a typical architecture of the application of Hyper Estraier. As it is no more than a concept, you can design your own architecture.</p>
109
110 <div class="illust"><img src="coreframe.png" width="720" height="550" alt="[framework]" /></div>
111
112 <hr />
113
114 <h2 id="building">Building</h2>
115
116 <p>As Hyper Estraier provides the API for the C language, an application is implemented in C or C++. This section describes how to build the application with the library of Hyper Estraier.</p>
117
118 <h3>Including Headers</h3>
119
120 <p>In each source of applications of the core API, include `estraier.h', `cabin.h', and `stdlib.h'. `estraier.h' is a header file of Hyper Estraier. `cabin.h' is a header file of QDBM. See <a href="http://qdbm.sourceforge.net/spex.html#cabinapi">the document of QDBM</a> for the functions provided by `cabin.h'.</p>
121
122 <pre>#include &lt;estraier.h&gt;
123 #include &lt;cabin.h&gt;
124 #include &lt;stdlib.h&gt;
125 </pre>
126
127 <h3>Compilation and Linking</h3>
128
129 <p>By default, headers of Hyper Estraier are installed in `/usr/local/include', and libraries are installed in `/usr/local/lib'. Other underlying libraries except for `-lestraier' are `-lqdbm', `-lz' `-liconv', `-lm', and `-lc'. That is, perform the following command to build an application.</p>
130
131 <pre>gcc -I/usr/local/include -o foobar foobar.c \
132 -L/usr/local/lib -lestraier -lqdbm -lz -liconv -lm -lc
133 </pre>
134
135 <p>However, the above does not works if the destination of installation is different. It is suggested to use `estconfig' in order to improve maintainability, as the following.</p>
136
137 <pre>gcc `estconfig --cflags` -o foobar foobar.c `estconfig --ldflags` `estconfig --libs`
138 </pre>
139
140 <h3>Command for Integration</h3>
141
142 <p>`estconfig' is useful for integration of an application or a system using Hyper Estraier. It outputs setting and configurations of Hyper Estraier.</p>
143
144 <dl>
145 <dt><kbd>estconfig --version</kbd></dt>
146 <dd>to output version information.</dd>
147 <dt><kbd>estconfig --prefix</kbd></dt>
148 <dd>to output the prefix of the destination of installation.</dd>
149 <dt><kbd>estconfig --execprefix</kbd></dt>
150 <dd>to output the prefix of the files depending on the platform.</dd>
151 <dt><kbd>estconfig --headdir</kbd></dt>
152 <dd>to output the prefix of the headers.</dd>
153 <dt><kbd>estconfig --libdir</kbd></dt>
154 <dd>to output the prefix of the libraries.</dd>
155 <dt><kbd>estconfig --bindir</kbd></dt>
156 <dd>to output the prefix of the commands.</dd>
157 <dt><kbd>estconfig --libexecdir</kbd></dt>
158 <dd>to output the prefix of the CGI script.</dd>
159 <dt><kbd>estconfig --datadir</kbd></dt>
160 <dd>to output the prefix of the configuration files.</dd>
161 <dt><kbd>estconfig --cflags</kbd></dt>
162 <dd>to output the compiler options to be specified when building.</dd>
163 <dt><kbd>estconfig --ldflags</kbd></dt>
164 <dd>to output the linker options to be specified when building.</dd>
165 <dt><kbd>estconfig --libs</kbd></dt>
166 <dd>to output the libraries to be specified when building.</dd>
167 <dt><kbd>estconfig --mtlibs</kbd></dt>
168 <dd>to output the libraries for applications with multi thread.</dd>
169 <dt><kbd>estconfig --sklibs</kbd></dt>
170 <dd>to output the libraries for applications with socket.</dd>
171 </dl>
172
173 <p>`estconfig' always returns 0 as the exit status.</p>
174
175 <hr />
176
177 <h2 id="estdoc">API for Documents</h2>
178
179 <p>The API for documents aims to handle documents which were registered into the index.</p>
180
181 <h3>Description</h3>
182
183 <p>The type of the structure `ESTDOC' is for abstraction of a document. A document is composed of some attributes and some text sentences. No entitiy of `ESTDOC' is accessed directly, but it is accessed by the pointer. The term of "document object" means the pointer and its referent. A document object is created by the function `est_doc_new' and destroyed by `est_doc_delete'. Every created document object should be destroyed.</p>
184
185 <p>Target documents of search are to be registered in the database beforehand. The ID is assigned to each registered document. When search, they can be retrieved from the database by their ID. The encoding of attributes and text sentences should be UTF-8.</p>
186
187 <p>The following is a typical use case of document object.</p>
188
189 <pre>ESTDOC *doc;
190
191 /* create a document object */
192 doc = est_doc_new();
193
194 /* add the URI and the title as attributes */
195 est_doc_add_attr(doc, "@uri", "http://foo.bar/baz.txt");
196 est_doc_add_attr(doc, "@title", "Now Scream");
197
198 /* add text sentences */
199 est_doc_add_text(doc, "Give it up, Yo! Give it up, Yo!");
200 est_doc_add_text(doc, "Check it out, come on!");
201
202 /* register the object or display it here */
203
204 /* destroy the object */
205 est_doc_delete(doc);
206 </pre>
207
208 <h3>API</h3>
209
210 <p>The function `est_doc_new' is used in order to create a document object.</p>
211
212 <dl>
213 <dt><kbd>ESTDOC *est_doc_new(void);</kbd></dt>
214 <dd>The return value is an object of a document.</dd>
215 </dl>
216
217 <p>The function `est_doc_new_from_draft' is used in order to create a document object made from draft data.</p>
218
219 <dl>
220 <dt><kbd>ESTDOC *est_doc_new_from_draft(const char *<var>draft</var>);</kbd></dt>
221 <dd>`draft' specifies a string of draft data. The return value is an object of a document.</dd>
222 </dl>
223
224 <p>The function `est_doc_delete' is used in order to destroy a document object.</p>
225
226 <dl>
227 <dt><kbd>void est_doc_delete(ESTDOC *<var>doc</var>);</kbd></dt>
228 <dd>`doc' specifies a document object.</dd>
229 </dl>
230
231 <p>The function `est_doc_add_attr' is used in order to add an attribute to a document object.</p>
232
233 <dl>
234 <dt><kbd>void est_doc_add_attr(ESTDOC *<var>doc</var>, const char *<var>name</var>, const char *<var>value</var>);</kbd></dt>
235 <dd>`doc' specifies a document object. `name' specifies the name of an attribute. `value' specifies the value of the attribute. If it is `NULL', the attribute is removed.</dd>
236 </dl>
237
238 <p>The function `est_doc_add_text' is used in order to add a sentence of text to a document object.</p>
239
240 <dl>
241 <dt><kbd>void est_doc_add_text(ESTDOC *<var>doc</var>, const char *<var>text</var>);</kbd></dt>
242 <dd>`doc' specifies a document object. `text' specifies a sentence of text.</dd>
243 </dl>
244
245 <p>The function `est_doc_add_hidden_text' is used in order to add a hidden sentence to a document object.</p>
246
247 <dl>
248 <dt><kbd>void est_doc_add_hidden_text(ESTDOC *<var>doc</var>, const char *<var>text</var>);</kbd></dt>
249 <dd>`doc' specifies a document object. `text' specifies a hidden sentence.</dd>
250 </dl>
251
252 <p>The function `est_doc_id' is used in order to get the ID number of a document object.</p>
253
254 <dl>
255 <dt><kbd>int est_doc_id(ESTDOC *<var>doc</var>);</kbd></dt>
256 <dd>`doc' specifies a document object. The return value is the ID number of the document object. If the object has not been registered, -1 is returned.</dd>
257 </dl>
258
259 <p>The function `est_doc_attr_names' is used in order to get a list of attribute names of a document object.</p>
260
261 <dl>
262 <dt><kbd>CBLIST *est_doc_attr_names(ESTDOC *<var>doc</var>);</kbd></dt>
263 <dd>`doc' specifies a document object. The return value is a new list object of attribute names of the document object. Because the object of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use.</dd>
264 </dl>
265
266 <p>The function `est_doc_attr' is used in order to get the value of an attribute of a document object.</p>
267
268 <dl>
269 <dt><kbd>const char *est_doc_attr(ESTDOC *<var>doc</var>, const char *<var>name</var>);</kbd></dt>
270 <dd>`doc' specifies a document object. `name' specifies the name of an attribute. The return value is the value of the attribute or `NULL' if it does not exist. The life duration of the returned string is synchronous with the one of the document object.</dd>
271 </dl>
272
273 <p>The function `est_doc_texts' is used in order to get a list of sentences of the text of a document object.</p>
274
275 <dl>
276 <dt><kbd>const CBLIST *est_doc_texts(ESTDOC *<var>doc</var>);</kbd></dt>
277 <dd>`doc' specifies a document object. The return value is a list object of sentences of the text of the document object. The life duration of the returned object is synchronous with the one of the document object.</dd>
278 </dl>
279
280 <p>The function `est_doc_cat_texts' is used in order to concatenate sentences of the text of a document object.</p>
281
282 <dl>
283 <dt><kbd>char *est_doc_cat_texts(ESTDOC *<var>doc</var>);</kbd></dt>
284 <dd>`doc' specifies a document object. The return value is concatenated sentences of the document object. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
285 </dl>
286
287 <p>The function `est_doc_dump_draft' is used in order to dump draft data of a document object.</p>
288
289 <dl>
290 <dt><kbd>char *est_doc_dump_draft(ESTDOC *<var>doc</var>);</kbd></dt>
291 <dd>`doc' specifies a document object. The return value is draft data of the document object. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
292 </dl>
293
294 <p>The function `est_doc_make_snippet' is used in order to make a snippet of the body text of a document object.</p>
295
296 <dl>
297 <dt><kbd>char *est_doc_make_snippet(ESTDOC *<var>doc</var>, const CBLIST *<var>words</var>, int <var>wwidth</var>, int <var>hwidth</var>, int <var>awidth</var>);</kbd></dt>
298 <dd>`doc' specifies a document object. `word' specifies a list object of words to be highlight. `wwitdh' specifies whole width of the result. `hwitdh' specifies width of strings picked up from the beginning of the text. `awitdh' specifies width of strings picked up around each highlighted word. The return value is a snippet string of the body text of the document object. There are tab separated values. Each line is a string to be shown. Though most lines have only one field, some lines have two fields. If the second field exists, the first field is to be shown with highlighted, and the second field means its normalized form. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
299 </dl>
300
301 <p>The function `est_doc_scan_words' is used in order to check whether the text of a document object includes every specified words.</p>
302
303 <dl>
304 <dt><kbd>int est_doc_scan_words(ESTDOC *<var>doc</var>, const CBLIST *<var>words</var>);</kbd></dt>
305 <dd>`doc' specifies a document object. `word' specifies a list object of words to be checked. The return value is true if every specified words is found, else it is false.</dd>
306 </dl>
307
308 <hr />
309
310 <h2 id="estcond">API for Search Conditions</h2>
311
312 <p>The API for search conditions aims to specify search conditions given to the index.</p>
313
314 <h3>Description</h3>
315
316 <p>The type of the structure `ESTCOND' is for abstraction of search conditions. A unit of search conditions is composed of one search phrase, some attribute expressions, and one order expression. No entitiy of `ESTCOND' is accessed directly, but it is accessed by the pointer. The term of "condition object" means the pointer and its referent. A condition object is created by the function `est_cond_new' and destroyed by `est_cond_delete'. Every created condition object should be destroyed.</p>
317
318 <p>Condition objects are used as a parameter to search for documents registered in the database so that a list of IDs of corresponding documents are returned. See <a href="manual-en.html#searchcond">the manual</a> for the formats of expressions. The encoding of conditional expressions should be UTF-8.</p>
319
320 <p>The following is a typical use case of condition object.</p>
321
322 <pre>ESTCOND *cond;
323
324 /* create a condition object */
325 cond = est_cond_new();
326
327 /* set the search phrase */
328 est_cond_set_phrase(cond, "check AND out");
329
330 /* set the attribute expression */
331 est_cond_add_attr(cond, "@uri ISTREW .txt");
332
333 /* search the database here */
334
335 /* destroy the object */
336 est_cond_delete(cond);
337 </pre>
338
339 <h3>API</h3>
340
341 <p>The function `est_cond_new' is used in order to create a condition object.</p>
342
343 <dl>
344 <dt><kbd>ESTCOND *est_cond_new(void);</kbd></dt>
345 <dd>The return value is an object of search conditions.</dd>
346 </dl>
347
348 <p>The function `est_cond_delete' is used in order to destroy a condition object.</p>
349
350 <dl>
351 <dt><kbd>void est_cond_delete(ESTCOND *<var>cond</var>);</kbd></dt>
352 <dd>`cond' specifies a condition object.</dd>
353 </dl>
354
355 <p>The function `est_cond_set_phrase' is used in order to set the search phrase to a condition object.</p>
356
357 <dl>
358 <dt><kbd>void est_cond_set_phrase(ESTCOND *<var>cond</var>, const char *<var>phrase</var>);</kbd></dt>
359 <dd>`cond' specifies a condition object. `phrase' specifies a search phrase.</dd>
360 </dl>
361
362 <p>The function `est_cond_add_attr' is used in order to add an expression for an attribute to a condition object.</p>
363
364 <dl>
365 <dt><kbd>void est_cond_add_attr(ESTCOND *<var>cond</var>, const char *<var>expr</var>);</kbd></dt>
366 <dd>`cond' specifies a condition object. `expr' specifies an expression for an attribute.</dd>
367 </dl>
368
369 <p>The function `est_cond_set_order' is used in order to set the order of a condition object.</p>
370
371 <dl>
372 <dt><kbd>void est_cond_set_order(ESTCOND *<var>cond</var>, const char *<var>expr</var>);</kbd></dt>
373 <dd>`cond' specifies a condition object. `expr' specifies an expression for the order. By default, the order is by score descending.</dd>
374 </dl>
375
376 <p>The function `est_cond_set_max' is used in order to set the maximum number of retrieval of a condition object.</p>
377
378 <dl>
379 <dt><kbd>void est_cond_set_max(ESTCOND *<var>cond</var>, int <var>max</var>);</kbd></dt>
380 <dd>`cond' specifies a condition object. `max' specifies the maximum number of retrieval. By default, the number of retrieval is not limited.</dd>
381 </dl>
382
383 <p>The function `est_cond_set_options' is used in order to set options of retrieval of a condition object.</p>
384
385 <dl>
386 <dt><kbd>void est_cond_set_options(ESTCOND *<var>cond</var>, int <var>options</var>);</kbd></dt>
387 <dd>`cond' specifies a condition object. `options' specifies options: `ESTCONDSURE' specifies that it checks every N-gram key, `ESTCONDUSU', which is the default, specifies that it checks N-gram keys with skipping one key, `ESTCONDFAST' skips two keys, `ESTCONDAGIT' skips three keys, `ESTCONDNOIDF' specifies not to perform TF-IDF tuning, `ESTCONDSIMPLE' specifies to use simplified phrase. Each option can be specified at the same time by bitwise or. If keys are skipped, though search speed is improved, the relevance ratio grows less.</dd>
388 </dl>
389
390 <hr />
391
392 <h2 id="estdb">API for Database</h2>
393
394 <p>The API for database aims to handle the database of the index.</p>
395
396 <h3>Description</h3>
397
398 <p>The type of the structure `ESTDB' is for abstraction of access methods to database. A database has inverted index, document data, and meta data. One of writer or reader is selected when the connection is established. No entitiy of `ESTDB' is accessed directly, but it is accessed by the pointer. The term of "database object" means the pointer and its referent. A database object is created by the function `est_db_open' and destroyed by `est_db_close'. Every created database object should be destroyed.</p>
399
400 <p>Errors with some operations are informed to by the function `est_db_error'. The meaning of each error code can be gotten as a string by the function `est_err_msg'.</p>
401
402 <p>The following is a typical use case of database object.</p>
403
404 <pre>
405 ESTDB *db
406 int ecode;
407
408 /* create a database object as a write */
409 if(!(db = est_db_open("casket", ESTDBWRITER | ESTDBCREAT, &amp;ecode))){
410 /* if failure, return after displaying the error message */
411 fprintf(stderr, "error: %s\n", est_err_msg(ecode));
412 return -1;
413 }
414
415 /* register documents or search for documents here */
416
417 /* destroy the object */
418 if(!est_db_close(db, &amp;ecode)){
419 /* if failure, return after displaying the error message */
420 fprintf(stderr, "error: %s\n", est_err_msg(ecode));
421 return -1;
422 }
423 </pre>
424
425 <h3>API</h3>
426
427 <p>The following constant are defined for error codes.</p>
428
429 <ul>
430 <li><kbd>ESTENOERR</kbd> : no error.</li>
431 <li><kbd>ESTEINVAL</kbd> : invalid argument.</li>
432 <li><kbd>ESTEACCES</kbd> : access forbidden.</li>
433 <li><kbd>ESTELOCK</kbd> : lock failure.</li>
434 <li><kbd>ESTEDB</kbd> : database problem.</li>
435 <li><kbd>ESTEIO</kbd> : I/O problem.</li>
436 <li><kbd>ESTENOITEM</kbd> : no item.</li>
437 <li><kbd>ESTEMISC</kbd> : miscellaneous.</li>
438 </ul>
439
440 <p>The function `est_err_msg' is used in order to get the string of an error code.</p>
441
442 <dl>
443 <dt><kbd>const char *est_err_msg(int <var>ecode</var>);</kbd></dt>
444 <dd>`ecode' specifies an error code. The return value is the string of the error code.</dd>
445 </dl>
446
447 <p>The function `est_db_open' is used in order to open a database.</p>
448
449 <dl>
450 <dt><kbd>ESTDB *est_db_open(const char *<var>name</var>, int <var>omode</var>, int *<var>ecp</var>);</kbd></dt>
451 <dd>`name' specifies the name of a database directory. `mode' specifies open modes: `ESTDBWRITER' as a writer, `ESTDBREADER' as a reader. If the mode is `ESTDBWRITER', the following may be added by bitwise or: `ESTDBCREAT', which means it creates a new database if not exist, `ESTDBTRUNC', which means it creates a new database regardless if one exists. Both of `ESTDBREADER' and `ESTDBWRITER' can be added to by bitwise or: `ESTDBNOLCK', which means it opens a database file without file locking, or `ESTDBLCKNB', which means locking is performed without blocking. If `ESTDBNOLCK' is used, the application is responsible for exclusion control. `ESTDBCREAT' can be added to by bitwise or: `ESTDBPERFNG', which means N-gram analysis is performed against European text also. `ecp' specifies the pointer to a variable to which the error code is assigned. The return value is a database object of the database or `NULL' if failure.</dd>
452 </dl>
453
454 <p>The function `est_db_close' is used in order to close a database.</p>
455
456 <dl>
457 <dt><kbd>int est_db_close(ESTDB *<var>db</var>, int *<var>ecp</var>);</kbd></dt>
458 <dd>`db' specifies a database object. `ecp' specifies the pointer to a variable to which the error code is assigned. The return value is true if success, else it is false.</dd>
459 </dl>
460
461 <p>The function `est_db_error' is used in order to get the last happened error code of a database.</p>
462
463 <dl>
464 <dt><kbd>int est_db_error(ESTDB *<var>db</var>);</kbd></dt>
465 <dd>`db' specifies a database object. The return value is the last happened error code of the database.</dd>
466 </dl>
467
468 <p>The function `est_db_fatal' is used in order to check whether a database has a fatal error.</p>
469
470 <dl>
471 <dt><kbd>int est_db_fatal(ESTDB *<var>db</var>);</kbd></dt>
472 <dd>`db' specifies a database object. The return value is true if the database has fatal error, else it is false.</dd>
473 </dl>
474
475 <p>The function `est_db_flush' is used in order to flush index words in the cache of a database.</p>
476
477 <dl>
478 <dt><kbd>int est_db_flush(ESTDB *<var>db</var>, int <var>max</var>);</kbd></dt>
479 <dd>`db' specifies a database object connected as a writer. `max' specifies the maximum number of words to be flushed. If it not more than zero, all words are flushed. The return value is true if success, else it is false.</dd>
480 </dl>
481
482 <p>The function `est_db_sync' is used in order to synchronize updating contents of a database.</p>
483
484 <dl>
485 <dt><kbd>int est_db_sync(ESTDB *<var>db</var>);</kbd></dt>
486 <dd>`db' specifies a database object connected as a writer. The return value is true if success, else it is false.</dd>
487 </dl>
488
489 <p>The function `est_db_optimize' is used in order to optimize a database.</p>
490
491 <dl>
492 <dt><kbd>int est_db_optimize(ESTDB *<var>db</var>, int <var>options</var>);</kbd></dt>
493 <dd>`db' specifies a database object connected as a writer. `options' specifies options: `ESTOPTNOPURGE' to omit purging dispensable region of deleted documents, `ESTOPTNODBOPT' to omit optimization of the database files. The two can be specified at the same time by bitwise or. The return value is true if success, else it is false.</dd>
494 </dl>
495
496 <p>The function `est_db_put_doc' is used in order to add a document to a database.</p>
497
498 <dl>
499 <dt><kbd>int est_db_put_doc(ESTDB *<var>db</var>, ESTDOC *<var>doc</var>, int <var>options</var>);</kbd></dt>
500 <dd>`db' specifies a database object connected as a writer. `doc' specifies a document object. The document object should have the URI attribute. `options' specifies options: `ESTPDCLEAN' to clean up dispensable regions of the overwritten document. The return value is true if success, else it is false. If the URI attribute is same with an existing document in the database, the existing one is deleted.</dd>
501 </dl>
502
503 <p>The function `est_db_out_doc' is used in order to remove a document from a database.</p>
504
505 <dl>
506 <dt><kbd>int est_db_out_doc(ESTDB *<var>db</var>, int <var>id</var>, int <var>options</var>);</kbd></dt>
507 <dd>`db' specifies a database object connected as a writer. `id' specifies the ID number of a registered document. `options' specifies options: `ESTODCLEAN' to clean up dispensable regions of the deleted document. The return value is true if success, else it is false.</dd>
508 </dl>
509
510 <p>The function `est_db_get_doc' is used in order to retrieve a document in a database.</p>
511
512 <dl>
513 <dt><kbd>ESTDOC *est_db_get_doc(ESTDB *<var>db</var>, int <var>id</var>, int <var>options</var>);</kbd></dt>
514 <dd>`db' specifies a database object. `id' specifies the ID number of a registered document. `options' specifies options: `ESTGDNOATTR' to ignore attributes, `ESTGDNOTEXT' to ignore the body text. The two can be specified at the same time by bitwise or. The return value is a document object. On error, `NULL' is returned.</dd>
515 </dl>
516
517 <p>The function `est_db_get_doc_attr' is used in order to retrieve the value of an attribute of a document in a database.</p>
518
519 <dl>
520 <dt><kbd>char *est_db_get_doc_attr(ESTDB *<var>db</var>, int <var>id</var>, const char *<var>name</var>);</kbd></dt>
521 <dd>`db' specifies a database object. `id' specifies the ID number of a registered document. `name' specifies the name of an attribute. The return value is the value of the attribute or `NULL' if it does not exist. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
522 </dl>
523
524 <p>The function `est_db_uri_to_id' is used in order to get the ID of a document spacified by URI.</p>
525
526 <dl>
527 <dt><kbd>int est_db_uri_to_id(ESTDB *<var>db</var>, const char *<var>uri</var>);</kbd></dt>
528 <dd>`db' specifies a database object. `uri' specifies the URI of a registered document. The return value is the ID of the document. On error, -1 is returned.</dd>
529 </dl>
530
531 <p>The function `est_db_etch_doc' to extract keywords of a document object.</p>
532
533 <dl>
534 <dt><kbd>CBMAP *est_db_etch_doc(ESTDB *<var>db</var>, ESTDOC *<var>doc</var>, int <var>max</var>);</kbd></dt>
535 <dd>`db' specifies a database object for TF-IDF tuning. If it is `NULL', it is not used. `doc' specifies a document object. `max' specifies the maximum number of keywords to be extracted. The return value is a new map object of keywords and their scores in decimal string. Because the object of the return value is opened with the function `cbmapopen', it should be closed with the function `cbmapclose' if it is no longer in use.</dd>
536 </dl>
537
538 <p>The function `est_db_iter_init' is used in order to initialize the iterator of a database.</p>
539
540 <dl>
541 <dt><kbd>int est_db_iter_init(ESTDB *<var>db</var>);</kbd></dt>
542 <dd>`db' specifies a database object. The return value is true if success, else it is false.</dd>
543 </dl>
544
545 <p>The function `est_db_iter_next' is used in order to get the next ID of the iterator of a database.</p>
546
547 <dl>
548 <dt><kbd>int est_db_iter_next(ESTDB *<var>db</var>);</kbd></dt>
549 <dd>`db' specifies a database object. The return value is the next ID. If there is no more document, 0 is returned. On error, -1 is returned.</dd>
550 </dl>
551
552 <p>The function `est_db_name' is used in order to get the name of a database.</p>
553
554 <dl>
555 <dt><kbd>const char *est_db_name(ESTDB *<var>db</var>);</kbd></dt>
556 <dd>`db' specifies a database object. The return value is the name of the database. The life duration of the returned string is synchronous with the one of the database object.</dd>
557 </dl>
558
559 <p>The function `est_db_doc_num' is used in order to get the number of documents in a database.</p>
560
561 <dl>
562 <dt><kbd>int est_db_doc_num(ESTDB *<var>db</var>);</kbd></dt>
563 <dd>`db' specifies a database object. The return value is the number of documents in the database.</dd>
564 </dl>
565
566 <p>The function `est_db_word_num' is used in order to get the number of unique words in a database.</p>
567
568 <dl>
569 <dt><kbd>int est_db_word_num(ESTDB *<var>db</var>);</kbd></dt>
570 <dd>`db' specifies a database object. The return value is the number of unique words in the database.</dd>
571 </dl>
572
573 <p>The function `est_db_size' is used in order to get the size of a database.</p>
574
575 <dl>
576 <dt><kbd>double est_db_size(ESTDB *<var>db</var>);</kbd></dt>
577 <dd>`db' specifies a database object. The return value is the size of the database.</dd>
578 </dl>
579
580 <p>The function `est_db_search' is used in order to search documents corresponding a condition for a database.</p>
581
582 <dl>
583 <dt><kbd>int *est_db_search(ESTDB *<var>db</var>, ESTCOND *<var>cond</var>, int *<var>nump</var>, CBMAP *<var>hints</var>);</kbd></dt>
584 <dd>`db' specifies a database object. `cond' specifies a condition object. `nump' specifies the pointer to a variable to which the number of elements in the result is assigned. `hints' specifies a map object into which the number of documents corresponding to each word is stored. If a word is in a negative condition, the number is negative. The element whose key is an empty string specifies the number of whole result. If it is `NULL', it is not used. The return value is an array whose elements are ID numbers of corresponding documents. This function does never fail. Even if no document corresponds or an error occurs, an empty array is returned. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
585 </dl>
586
587 <p>The function `est_db_set_cache_size' is used in order to set the maximum size of the cache memory of a database.</p>
588
589 <dl>
590 <dt><kbd>void est_db_set_cache_size(ESTDB *<var>db</var>, size_t <var>size</var>, int <var>anum</var>, int <var>tnum</var>);</kbd></dt>
591 <dd>`db' specifies a database object. `size' specifies the maximum size of the index cache. By default, it is 64MB. If it is not more than 0, the current size is not changed. `anum' specifies the maximum number of cached records for document attributes. By default, it is 8192. If it is not more than 0, the current size is not changed. `tnum' specifies the maximum number of cached records for document texts. By default, it is 1024. If it is not more than 0, the current size is not changed.</dd>
592 </dl>
593
594 <hr />
595
596 <h2 id="gatherer">Example of Gatherer</h2>
597
598 <p>The following is the simplest implementation of a gatherer.</p>
599
600 <pre>#include &lt;estraier.h&gt;
601 #include &lt;cabin.h&gt;
602 #include &lt;stdlib.h&gt;
603 #include &lt;stdio.h&gt;
604
605 int main(int argc, char **argv){
606 ESTDB *db;
607 ESTDOC *doc;
608 int ecode;
609
610 /* open the database */
611 if(!(db = est_db_open("casket", ESTDBWRITER | ESTDBCREAT, &amp;ecode))){
612 fprintf(stderr, "error: %s\n", est_err_msg(ecode));
613 return 1;
614 }
615
616 /* create a document object */
617 doc = est_doc_new();
618
619 /* add attributes to the document object */
620 est_doc_add_attr(doc, "@uri", "http://estraier.gov/example.txt");
621 est_doc_add_attr(doc, "@title", "Over the Rainbow");
622
623 /* add the body text to the document object */
624 est_doc_add_text(doc, "Somewhere over the rainbow. Way up high.");
625 est_doc_add_text(doc, "There's a land that I heard of once in a lullaby.");
626
627 /* register the document object to the database */
628 if(!est_db_put_doc(db, doc, ESTPDCLEAN))
629 fprintf(stderr, "error: %s\n", est_err_msg(est_db_error(db)));
630
631 /* destroy the document object */
632 est_doc_delete(doc);
633
634 /* close the database */
635 if(!est_db_close(db, &amp;ecode)){
636 fprintf(stderr, "error: %s\n", est_err_msg(ecode));
637 return 1;
638 }
639
640 return 0;
641 }
642 </pre>
643
644 <hr />
645
646 <h2 id="searcher">Example of Searcher</h2>
647
648 <p>The following is the simplest implementation of a searcher.</p>
649
650 <pre>#include &lt;estraier.h&gt;
651 #include &lt;cabin.h&gt;
652 #include &lt;stdlib.h&gt;
653 #include &lt;stdio.h&gt;
654
655 int main(int argc, char **argv){
656 ESTDB *db;
657 ESTCOND *cond;
658 ESTDOC *doc;
659 const CBLIST *texts;
660 int ecode, *result, resnum, i, j;
661 const char *value;
662
663 /* open the database */
664 if(!(db = est_db_open("casket", ESTDBREADER, &amp;ecode))){
665 fprintf(stderr, "error: %s\n", est_err_msg(ecode));
666 return 1;
667 }
668
669 /* create a search condition object */
670 cond = est_cond_new();
671
672 /* set the search phrase to the search condition object */
673 est_cond_set_phrase(cond, "rainbow AND lullaby");
674
675 /* get the result of search */
676 result = est_db_search(db, cond, &amp;resnum, NULL);
677
678 /* for each document in the result */
679 for(i = 0; i &lt; resnum; i++){
680
681 /* retrieve the document object */
682 if(!(doc = est_db_get_doc(db, result[i], 0))) continue;
683
684 /* display attributes */
685 if((value = est_doc_attr(doc, "@uri")) != NULL)
686 printf("URI: %s\n", value);
687 if((value = est_doc_attr(doc, "@title")) != NULL)
688 printf("Title: %s\n", value);
689
690 /* display the body text */
691 texts = est_doc_texts(doc);
692 for(j = 0; j &lt; cblistnum(texts); j++){
693 value = cblistval(texts, j, NULL);
694 printf("%s\n", value);
695 }
696
697 /* destroy the document object */
698 est_doc_delete(doc);
699
700 }
701
702 /* free the result of search */
703 free(result);
704
705 /* destroy the search condition object */
706 est_cond_delete(cond);
707
708 /* close the database */
709 if(!est_db_close(db, &amp;ecode)){
710 fprintf(stderr, "error: %s\n", est_err_msg(ecode));
711 return 1;
712 }
713
714 return 0;
715 }
716 </pre>
717
718 <hr />
719
720 <h2 id="paralleling">Paralleling</h2>
721
722 <p>Databases of Hyper Estraier are protected by file locking. While a writer is connected to a database, neither readers nor writers can be connected. While a reader is connected to a database, other readers can be connect, but writers can not.</p>
723
724 <p>If you use multi thread, it is suggested to use the MT-safe API of Hyper Estraier. It is a wrapper to make the core API thread-safe. As the MT-safe API provides the same functions as with the core API, the following is different.</p>
725
726 <ul>
727 <li>Include not only `estraier.h' but also `estmtdb.h'.</li>
728 <li>Use pointers to `ESTMTDB' instead of `ESTDB' as database objects.</li>
729 <li>The names of functions begin with "est_mtdb_" instead of "est_db_".</li>
730 </ul>
731
732 <p>If QDBM was built with `--enable-pthread', mutex protection is performed for each connection, not in global. So, it is recommended when you use the MT-safe API.</p>
733
734 <hr />
735
736 </body>
737
738 </html>
739
740 <!-- END OF FILE -->

  ViewVC Help
Powered by ViewVC 1.1.26