/[hyperestraier]/upstream/0.5.3/doc/nguide-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/nguide-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: 59992 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, Node, P2P" />
13 <meta name="description" content="API specifications of Hyper Estraier" />
14 <link rel="contents" href="./" />
15 <link rel="alternate" href="nguide-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>P2P Guide of Hyper Estraier Version 1</title>
20 </head>
21
22 <body>
23
24 <h1>P2P 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="nguide-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="#tutorial">Tutorial</a></li>
38 <li><a href="#estmaster">Command of the Node Master</a></li>
39 <li><a href="#protocol">Protocol</a></li>
40 <li><a href="#nodeapi">Node API</a></li>
41 <li><a href="#estcall">Command of a Client</a></li>
42 </ol>
43
44 <hr />
45
46 <h2 id="introduction">Introduction</h2>
47
48 <p>This document describes how to use P2P mechanism of Hyper Estraier. If you have never read <a href="uguide-en.html">the user's guide</a>, please read it beforehand.</p>
49
50 <p>estseek.cgi is not efficient because it connects to the database per execution. And, it is impossible to perform search during database updating, because estcmd locks the database. To solve the problem, Hyper Estraier provides a server program of C/S (client/server) architecture. There are a resident process keeping connection to the database and it serves some operations via network. The C/S architecture has the following advantages.</p>
51
52 <ul>
53 <li>The server and its clients work on separate machines.</li>
54 <li>Plural clients of one server can work in parallel.</li>
55 <li>The database is not broken even when some clients crash.</li>
56 <li>Clients can be implemented without dependency of programming languages or APIs.</li>
57 </ul>
58
59 <p>Because the protocol between C/S is based on HTTP, some popular web browsers can be used as clients. Of course, clients can be implemented on your own way. It is also good idea to use such technologies around web browser as JavaScript, Flash, and so on.</p>
60
61 <p>Distributed processing based on P2P (Peer to Peer) architecture is supported. If you use 10 servers handling one million of documents, you can search 10 millions of documents. Because servers are equivalent, whole of the network service works successively even if a server crashes. Moreover, calculating reliability between servers is supported and it can improve search precision.</p>
62
63 <p>The node API is provided to hide the protocol between C/S. Using the node API, you can implement client applications without closeup know-hows about network. This document describes how to use the node API (C language). Interfaces of the node API for <a href="japidoc/">Java</a> and <a href="rbapidoc/">Ruby</a> are also provided.</p>
64
65 <hr />
66
67 <h2 id="architecture">Architecture</h2>
68
69 <p>This section describes the P2P architecture of Hyper Estraier.</p>
70
71 <h3>Node Master and Node Server</h3>
72
73 <p>If you uses many indexes, it is inefficient to run a server per index. So, a program called node master is provided. While it works as one process and uses one network port, it can handle several indexes. Because each index performs its own service, we can regard a "node master" as aggregation of several index servers. On the viewpoint, each virtual server handling an index is called "node server". Each node server has an own URL. A client application knows URL of a node server but does not know in which node master the node server works.</p>
74
75 <div class="illust"><img src="nodeframe.png" width="720" height="350" alt="[framework]" /></div>
76
77 <p>The term "node" is used as with the term "peer" in the P2P architecture. As a client connects to a node master itself and manage some nodes, another client connects to a node server and search/register documents.</p>
78
79 <h3>Meta Search and Credit</h3>
80
81 <p>A node server can link to another node server one-sidedly. When a client send a query to a node server, the node server relay the query to linked nodes. Responses of linked nodes and the first node are merged and sent back to the client. That is, so-called meta search is supported by every nodes and it realizes distributed processing in P2P architecture.</p>
82
83 <p>The meta search is performed hierarchically. Because loop of routing is detected and restrained automatically, the behavior is as with search of tree structured network. Due to this mechanism, it is possible to increase nodes of the network up to infinity.</p>
84
85 <div class="illust"><img src="metatree.png" width="720" height="400" alt="[tree of meta search]" /></div>
86
87 <p>Reliability called "credit" is set to each link between nodes. When a node merges responses collected by meta search, credit is used for weighting of scores. So, documents in response of nodes with high credit is apt to be shown in high ranks. As applications are responsible to set links and their credit, it is possible to improve search precision by increasing credit of frequently used nodes.</p>
88
89 <h3>Authentication</h3>
90
91 <p>When a client connects to the node master or a node server, authentication with a user name and a password is performed. Users are classified into super users and normal users. The former has permission to manage nodes and users. The latter does not have those permissions. Moreover, permission is granted for each node servers. Each node has lists of administrator who can update the index and normal users who can perform search only. Besides, super users of the node master can connect as administrators to node servers in the same node master.</p>
92
93 <hr />
94
95 <h2 id="tutorial">Tutorial</h2>
96
97 <p>As the concept of P2P seems difficult, let's try to use some commands and learn it by degrees.</p>
98
99 <h3>Start and Stop</h3>
100
101 <p>For preparation for the node master, create the server root directory which includes configuration files and indexes. Perform the following command and a directory "casket" will be created.</p>
102
103 <pre>estmaster init casket
104 </pre>
105
106 <p>Next, start the node master. Perform the following command.</p>
107
108 <pre>estmaster start casket
109 </pre>
110
111 <p>To stop the node master, input Ctrl-D on the terminal on which the node master is running or perform the following command on another terminal.</p>
112
113 <pre>estmaster stop casket
114 </pre>
115
116 <h3>Administration Interface</h3>
117
118 <p>While the node master is running, we can access "http://localhost:1978/masterui" with a web browser and use the administration interface. When access the URL, a dialog is shown and the user name and the password is required. Input "admin" and "admin". Then, the menu of administration commands is displayed.</p>
119
120 <p>If you step into "Manage Master" and select "SHUTDOWN", you can stop the node master. But, leave it for now.</p>
121
122 <p>Select "Manage Users". As you have logged in as a user whose name is "admin", create a new user account and switch to it. Input the user name, the password, the flags, the full name, and the the miscellaneous information into the forms at the bottom of the page. The name and the password can contain alphanumeric characters only. As for now, input "clint", "tnilc", "s", "Clint Eastwood", and "Dirty Harry". It is important to set "s" in the flags. It means that the user is a super user.</p>
123
124 <p>Now, the user "admin" is no longer in use. As it has some potential security problems, delete it. Select the "DELE" in the line of "admin" and push "delete" on the next confirmation step.</p>
125
126 <p>Step into "Manage Nodes". Because the user "admin" is deleted, you are asked the user name and the password again. Input the "clint" and "tnilc" so that you can continue. In turn, create new nodes. Input the node name and the label into the form at the bottom of the page. The name can contain alphanumeric characters only. As for now, create a node whose name is "test1" and whose label is "First Node". And create another node whose name is "test2" and whose label is "Second Node".</p>
127
128 <h3>Register Documents</h3>
129
130 <p>Back to the command line operations. As the terminal of the node master is busy to show log messages, open another terminal.</p>
131
132 <p>Let's register some documents into the indexes of nodes. It is needed to prepare document draft data of documents to register. Create the following file and save it as "data001.est".</p>
133
134 <pre>@uri=data001
135 @title=Material Girl
136
137 Living in a material world
138 And I am a material girl
139 You know that we are living in a material world
140 And I am a material girl
141 </pre>
142
143 <p>To register it into the node "test1", perform the following command. Because the permission as administrators is needed to update the index, you should specify the user name and the password with the -auth option. Process of registration finishes in a flash. It is success if no error message is shown.</p>
144
145 <pre>estcall put -auth clint tnilc http://localhost:1978/node/test1 data001.est
146 </pre>
147
148 <p>For explanation of meta search said later, register another document into the node "test2" also. Create the following file and save it as "data002.est".</p>
149
150 <pre>@uri=data002
151 @title=Liberian Girl
152
153 Liberian girl
154 You came and you changed My world
155 A love so brand new
156 </pre>
157
158 <p>Then, perform the following command.</p>
159
160 <pre>estcall put -auth clint tnilc http://localhost:1978/node/test2 data002.est
161 </pre>
162
163 <p>It is useful to register documents from remote machines, isn't it? As with the above steps, register some other documents.</p>
164
165 <h3>Search for Documents</h3>
166
167 <p>All right, let's search for some registered documents. Perform the following command, and information of the corresponding document is shown.</p>
168
169 <pre>estcall search http://localhost:1978/node/test1 "material world"
170 </pre>
171
172 <p>By setting a link between the two nodes, you can do meta search. Now, set the link from "test1" to "test2". Specify the URL of the source node, the URL of the destination node, the label to display, and the credit.</p>
173
174 <pre>estcall setlink -auth clint tnilc http://localhost:1978/node/test1 \
175 http://localhost:1978/node/test2 TEST02 8000
176 </pre>
177
178 <p>And, search again. This time, set depth of meta search with the option -dpt.</p>
179
180 <pre>estcall search -dpt 1 http://localhost:1978/node/test1 "girl"
181 </pre>
182
183 <p>Though you access the node "test1", the result of "test2" is merged and shown. It is the feature of meta search in P2P architecture. If "test1" and "test2" are on separate machines, distributed computing is realized.</p>
184
185 <p>By increasing the credit, ranking of documents in the result of the destination node is to be higher. Perform the following command and search again. Then, you will see the ranking is changed.</p>
186
187 <pre>estcall setlink -auth clint tnilc http://localhost:1978/node/test1 \
188 http://localhost:1978/node/test2 TEST02 12000
189 </pre>
190
191 <p>You can get result as XML data. Perform the following command. See estresult.dtd for detail of the XML format.</p>
192
193 <pre>estcall search -dpt 1 -vx http://localhost:1978/node/test1 "girl"
194 </pre>
195
196 <p>Each node server embeds search interface for web browsers. Access "http://localhost:1978/node/test1/searchui" to use it.</p>
197
198 <hr />
199
200 <h2 id="estmaster">Command of the Node Master</h2>
201
202 <p>`estmaster' is provided as a command to manage the node master. This section describes how to use estmaster.</p>
203
204 <h3>Synopsis and Description</h3>
205
206 <p>estmaster is an aggregation of sub commands. The name of a sub command is specified by the first argument. Other arguments are parsed according to each sub command. The argument <var>rootdir</var> specifies the server root directory which contains configuration file and so on.</p>
207
208 <dl>
209 <dt><kbd>estmaster init [-ex] <var>rootdir</var></kbd></dt>
210 <dd>Create the server root directory.</dd>
211 <dd>If -ex is specified, some users and some nodes are set for example. By default, only a super user whose name and password are both "admin" is set.</dd>
212 </dl>
213
214 <dl>
215 <dt><kbd>estmaster start [-bg] [-st] <var>rootdir</var></kbd></dt>
216 <dd>Start the node master.</dd>
217 <dd>If -bg is specified, the server runs in background as a daemon process.</dd>
218 <dd>If -st is specified, the server runs in single thread mode.</dd>
219 </dl>
220
221 <dl>
222 <dt><kbd>estmaster stop <var>rootdir</var></kbd></dt>
223 <dd>Stop the running node master.</dd>
224 </dl>
225
226 <dl>
227 <dt><kbd>estmaster unittest <var>rootdir</var></kbd></dt>
228 <dd>Perform unit tests.</dd>
229 </dl>
230
231 <dl>
232 <dt><kbd>estmaster crypt <var>key</var> [<var>hash</var>]</kbd></dt>
233 <dd>Output an encrypted string of a string.</dd>
234 <dd><var>key</var> specifies a target string.</dd>
235 <dd>If <var>hash</var> is specified, it checks whether the key and the hash matches.</dd>
236 </dl>
237
238 <p>All sub commands return 0 if the operation is success, else return 1. A running node master finishes with closing the database when it catches the signal 2 (SIGINT), 3 (SIGQUIT), or 15 (SIGTERM). Moreover, when a running node master catches the signal 1 (SIGHUP), the process is re-start and re-read the configuration files.</p>
239
240 <p>A running node server should be finished by valid means by command line or via network. Otherwise, the index may be broken.</p>
241
242 <h3>Constitution of the Server Root Directory</h3>
243
244 <p>The server root directory contains the following files and directories.</p>
245
246 <ul>
247 <li><kbd>_conf</kbd> : prime configuration file.</li>
248 <li><kbd>_user</kbd> : user account file.</li>
249 <li><kbd>_log</kbd> : log file.</li>
250 <li><kbd>_meta</kbd> : database file for meta data.</li>
251 <li><kbd>_pid</kbd> : file recording the process ID.</li>
252 <li><kbd>_stop</kbd> : file to stop the node master.</li>
253 <li><kbd>_node/</kbd> : node directory.</li>
254 <li><kbd>_sess/</kbd> : session directory.</li>
255 </ul>
256
257 <p>The prime configuration file can be edit with a text editor. However, the user account file should not be edit during the node master is running.</p>
258
259 <p>If you have an index created by estcmd, move it into the node directory and reboot the server. So, the index will work as a node.</p>
260
261 <h3>Prime Configuration File</h3>
262
263 <p>The prime configuration file is composed of lines and the name of an variable and the value separated by `:' are in each line. By default, the following configuration is there.</p>
264
265 <pre>hostname: localhost
266 portnum: 1978
267 runmode: 1
268 authmode: 2
269 maxconn: 30
270 sessiontimeout: 600
271 searchtimeout: 8
272 searchdepth: 5
273 proxyhost:
274 proxyport:
275 loglevel: 2
276 docroot:
277 indexfile:
278 trustednode:
279 denyuntrusted: 0
280 cachesize: 64
281 specialcache:
282 snipwwidth: 480
283 sniphwidth: 96
284 snipawidth: 96
285 uilprefix: file:///home/mikio/public_html/
286 uigprefix: http://localhost/
287 uigsuffix:
288 uidirindex: index.html
289 uireplace: //localhost/{{!}}//127.0.0.1/
290 uireplace: //127.0.0.1:80/{{!}}//127.0.0.1/
291 uiextattr: @author|Author
292 uiextattr: @mdate|Modification Date
293 uismplphrase: 1
294 </pre>
295
296 <p>Meaning of each variable is the following.</p>
297
298 <ul>
299 <li><kbd>hostname</kbd> : specifies the host name of the server.</li>
300 <li><kbd>portnum</kbd> : specifies the port number of the server.</li>
301 <li><kbd>runmode</kbd> : specifies running mode (1:normal, 2:readonly).</li>
302 <li><kbd>authmode</kbd> : specifies authorization mode (1:none, 2:admin, 3:all).</li>
303 <li><kbd>maxconn</kbd> : specifies maximum number of connections at the same time.</li>
304 <li><kbd>sessiontimeout</kbd> : specifies timeout of a session (in seconds).</li>
305 <li><kbd>searchtimeout</kbd> : specifies timeout of search (in seconds).</li>
306 <li><kbd>searchdepth</kbd> : specifies maximum depth of meta search.</li>
307 <li><kbd>proxyhost</kbd> : specifies the host name of the proxy server.</li>
308 <li><kbd>proxyport</kbd> : specifies the port number of the proxy server.</li>
309 <li><kbd>loglevel</kbd> : specifies logging level (1:debug, 2:information, 3:warning, 4:error, 5:none).</li>
310 <li><kbd>docroot</kbd> : specifies document root directory (full path of a directory to be public).</li>
311 <li><kbd>indexfile</kbd> : specifies index file (name of directory index files).</li>
312 <li><kbd>trustednode</kbd> : specifies decimal IP addresses of trusted nodes. This can be more than once.</li>
313 <li><kbd>denyuntrusted</kbd> : specifies whether to deny all nodes except for trusted nodes (0:no, 1:yes).</li>
314 <li><kbd>cachesize</kbd> : specifies maximum size of the index cache (in mega bytes).</li>
315 <li><kbd>specialcache</kbd> : specifies name of the attribute of the special cache.</li>
316 <li><kbd>snipwwidth</kbd> : specifies whole width of the snippet of each shown document.</li>
317 <li><kbd>sniphwidth</kbd> : specifies width of strings picked up from the beginning of the text.</li>
318 <li><kbd>snipawidth</kbd> : specifies width of strings picked up around each highlighted word.</li>
319 <li><kbd>uilprefix</kbd> : specifies the prefix of the local URI of each document.</li>
320 <li><kbd>uigprefix</kbd> : specifies the prefix of the global URI of each document.</li>
321 <li><kbd>uigsuffix</kbd> : specifies the suffix added to the global URI of each document.</li>
322 <li><kbd>uidirindex</kbd> : specifies the name of the directory index file.</li>
323 <li><kbd>uireplace</kbd> : specifies an expression to replace the URI of each document. Before string and after string are separated by "{{!}}". This can be more than once.</li>
324 <li><kbd>uiextattr</kbd> : specifies an attribute to be shown. The name and the label are separated by "|". This can be more than once.</li>
325 <li><kbd>uismplphrase</kbd> : specifies whether to use simplified search phrase (0:no, 1:yes).</li>
326 </ul>
327
328 <h3>User Account File</h3>
329
330 <p>The user account file is composed of lines and each includes the name, the encrypted password, the flags, the full name, and the miscellaneous information separated by tabs. The character encoding is UTF-8. By default, the following account is there.</p>
331
332 <pre>admin 21232f297a57a5a743894a0e4a801fc3 s Carolus Magnus Administrator
333 </pre>
334
335 <p>The password is expressed as MD5 hash value. In the flags, "s" is for super users, and "b" is for banned users. Flags, full name, and miscellaneous information can be omitted.</p>
336
337 <h3>Embedded User Interfaces</h3>
338
339 <p>By accessing the absolute URL "/masterui" of the node master with a web browser, you can use the administration interface. It requires authentication as a super user.</p>
340
341 <p>By accessing the URL which is the URL of a node server followed by "/searchui", you can use the search interface.</p>
342
343 <hr />
344
345 <h2 id="protocol">Protocol</h2>
346
347 <p>Communication between nodes and communication between clients and nodes are carried out by a protocol based on HTTP. This section describes the protocol.</p>
348
349 <h3>Introduction</h3>
350
351 <p>The node master and node servers implement HTTP/1.0. As for now, such particular features of HTTP/1.1 as keep-alive connection, chunked encoding, and content negotiation are not supported.</p>
352
353 <p>While both of GET and POST are allowed for the request method of HTTP, GET is preferred if the command retrieves information, POST is preferred if the command update the node master or a node server. As the character encoding of parameters is UTF-8, meta characters and multi-byte characters should be escaped by URL encoding (application/x-www-form-urlencoded). The maximum length of data sent with the GET method is 8000. Authentication information is passed in the basic authentication mechanism of HTTP.</p>
354
355 <p>If an operation is done successfully, the status code 200 or 202 is returned. On error, one of the following status code is returned.</p>
356
357 <ul>
358 <li>400 : parameters are invalid.</li>
359 <li>401 : authentication information lacks or is invalid.</li>
360 <li>403 : the account has not the permission.</li>
361 <li>404 : the node does not exist.</li>
362 <li>500 : some errors of due to the server occurred.</li>
363 </ul>
364
365 <p>The result of operation of search or retrieve is sent as message body of response. As the format of the data is plain text whose encoding is UTF-8, it can be structured with tabs and line feeds.</p>
366
367 <h3>Operation of Node Master</h3>
368
369 <p>To operate the node master, connect to the path "/master" of the server. For example, if the host name is "skyhigh.estraier.go.jp" and the port number is 8888, connect to "http://skyhigh.estraier.go.jp:8888/master". Only super users are granted to operate the node master. There are some sub commands for operations of the node master. The name of a sub command is specified by the parameter "action". Other parameters vary according to each sub command.</p>
370
371 <dl>
372 <dt><kbd>/master?action=shutdown</kbd></dt>
373 <dd>Shutdown the node master.</dd>
374 <dd>No parameter is used.</dd>
375 <dd>On success, the status code 202 is returned.</dd>
376 </dl>
377
378 <dl>
379 <dt><kbd>/master?action=userlist</kbd></dt>
380 <dd>Get the list of user accounts.</dd>
381 <dd>No parameter is used.</dd>
382 <dd>On success, the status code 200 is returned. The entity body of response expresses the list of user accounts whose format is TSV. Each line is information of each user. There is fields of the user name, the encrypted password, the flags, the full name, and the miscellaneous information.</dd>
383 </dl>
384
385 <dl>
386 <dt><kbd>/master?action=useradd&amp;name=<var>str</var>&amp;passwd=<var>str</var>&amp;flags=<var>str</var>&amp;fname=<var>str</var>&amp;misc=<var>str</var></kbd></dt>
387 <dd>Add a user account.</dd>
388 <dd><var>name</var> specifies the name of a new user. It is essential. Only alphanumeric characters are in the name. If the specified name overlaps the name of an existing user, it is treated as an error.</dd>
389 <dd><var>passwd</var> specifies the password. It is essential.</dd>
390 <dd><var>flags</var> specifies the flags. It is optional.</dd>
391 <dd><var>fname</var> specifies the full name. It is optional.</dd>
392 <dd><var>misc</var> specifies the miscellaneous information. It is optional.</dd>
393 <dd>On success, the status code 200 is returned.</dd>
394 <dd>Because the password is sent, POST method should be used.</dd>
395 </dl>
396
397 <dl>
398 <dt><kbd>/master?action=userdel&amp;name=<var>str</var></kbd></dt>
399 <dd>Delete a user account.</dd>
400 <dd><var>name</var> specifies the name of a user. It is essential.</dd>
401 <dd>On success, the status code 200 is returned.</dd>
402 </dl>
403
404 <dl>
405 <dt><kbd>/master?action=nodelist</kbd></dt>
406 <dd>Get the list of node servers.</dd>
407 <dd>No parameter is used.</dd>
408 <dd>On success, the status code 200 is returned. The entity body of response expresses the list of node servers whose format is TSV. Each line is information of each node. There is fields of the node name, the label, the number of documents, the number of unique words, and the size.</dd>
409 </dl>
410
411 <dl>
412 <dt><kbd>/master?action=nodeadd&amp;name=<var>str</var>&amp;label=<var>str</var></kbd></dt>
413 <dd>Add a node server.</dd>
414 <dd><var>name</var> specifies the name of a new node. It is essential. Only alphanumeric characters are in the name. If the specified name overlaps the name of an existing node, it is treated as an error.</dd>
415 <dd><var>label</var> specifies the label. It is optional. If it is omitted, the label is to be the same as the name.</dd>
416 <dd>On success, the status code 200 is returned.</dd>
417 </dl>
418
419 <dl>
420 <dt><kbd>/master?action=nodedel&amp;name=<var>str</var></kbd></dt>
421 <dd>Delete a node server.</dd>
422 <dd><var>name</var> specifies the name of a node. It is essential.</dd>
423 <dd>On success, the status code 200 is returned.</dd>
424 </dl>
425
426 <h3>Operation of Node Server</h3>
427
428 <p>To operate a node server, connect to a path which begins "/node/" and is followed by the name of the node. For example, if the host name is "skyhigh.estraier.go.jp" and the port number is 8888 and the name of the node is "foo", connect to "http://skyhigh.estraier.go.jp:8888/node/foo". There are some sub commands for operations of node servers. The name of a sub command is specified after the node name. Parameters vary according to each sub command.</p>
429
430 <dl>
431 <dt><kbd>/node/<var>name</var>/inform</kbd></dt>
432 <dd>Get information of a node.</dd>
433 <dd>No parameter is used.</dd>
434 <dd>On success, the status code 200 is returned. The entity body of response expresses node information whose format is TSV. The first line includes fields of the node name, the label, the number of documents, the number of unique words, and the size. The next line is empty. The succeeding lines to the next empty line are names of administrators. And, the succeeding lines to the next empty line are names of normal users. And, the succeeding lines to the end are link information. There are fields of the URL, the label, and the credit.</dd>
435 </dl>
436
437 <dl>
438 <dt><kbd>/node/<var>name</var>/search?phrase=<var>str</var>&amp;attr=<var>str</var>&amp;order=<var>str</var>&amp;max=<var>num</var>&amp;options=<var>num</var>&amp;depth=<var>num</var></kbd></dt>
439 <dd>Search for documents.</dd>
440 <dd><var>phrase</var> specifies the search phrase. It is optional. The format is as with the one of the core API.</dd>
441 <dd><var>attr</var> specifies an attribute search condition. It is optional. From <var>attr1</var> to <var>attr9</var> works as with it. The format is as with the one of the core API.</dd>
442 <dd><var>order</var> specifies the order expression. It is optional. The format is as with the one of the core API.</dd>
443 <dd><var>max</var> specifies the maximum number of shown documents. It is optional. By default, it is 10.</dd>
444 <dd><var>options</var> specifies options. It is optional. The value is as with the one of the core API.</dd>
445 <dd><var>depth</var> specifies depth of meta search. It is optional. By default, it is 0.</dd>
446 <dd>On success, the status code 200 is returned. The entity body of response expresses the search result. The format is explained later.</dd>
447 </dl>
448
449 <dl>
450 <dt><kbd>/node/<var>name</var>/get_doc?id=<var>num</var>&amp;uri=<var>str</var></kbd></dt>
451 <dd>Get information of a document.</dd>
452 <dd><var>id</var> specifies the ID number of a document. It is optional.</dd>
453 <dd><var>uri</var> specifies the URI of a document. It is optional.</dd>
454 <dd>On success, the status code 200 is returned. The entity body of response expresses the search result. The format is document draft.</dd>
455 </dl>
456
457 <dl>
458 <dt><kbd>/node/<var>name</var>/get_doc_attr?id=<var>num</var>&amp;uri=<var>str</var>&amp;attr=<var>str</var></kbd></dt>
459 <dd>Get the value of an attribute of a document.</dd>
460 <dd><var>id</var> specifies the ID number of a document. It is optional.</dd>
461 <dd><var>uri</var> specifies the URI of a document. It is optional.</dd>
462 <dd><var>attr</var> specifies the name of an attribute. It is essential.</dd>
463 <dd>On success, the status code 200 is returned. The entity body of response expresses the value of the attribute.</dd>
464 </dl>
465
466 <dl>
467 <dt><kbd>/node/<var>name</var>/uri_to_id?uri=<var>str</var></kbd></dt>
468 <dd>Get the ID number of a document specified by URI.</dd>
469 <dd><var>uri</var> specifies the URI of a document. It is essential.</dd>
470 <dd>On success, the status code 200 is returned. The entity body of response expresses the ID number of the document.</dd>
471 </dl>
472
473 <dl>
474 <dt><kbd>/node/<var>name</var>/put_doc?draft=<var>str</var></kbd></dt>
475 <dd>Register a document. It is available by administrators only.</dd>
476 <dd><var>draft</var> specifies content of a document in document draft format. It is essential.</dd>
477 <dd>On success, the status code 200 is returned.</dd>
478 </dl>
479
480 <dl>
481 <dt><kbd>/node/<var>name</var>/out_doc?id=<var>num</var>&amp;uri=<var>str</var></kbd></dt>
482 <dd>Remove a document. It is available by administrators only.</dd>
483 <dd><var>id</var> specifies the ID number of a document. It is optional.</dd>
484 <dd><var>uri</var> specifies the URI of a document. It is optional.</dd>
485 <dd>On success, the status code 200 is returned.</dd>
486 </dl>
487
488 <dl>
489 <dt><kbd>/node/<var>name</var>/_set_user?name=<var>str</var>&amp;mode=<var>num</var></kbd></dt>
490 <dd>Set permission of a user. It is available by administrators only.</dd>
491 <dd><var>name</var> specifies the name of a user. It is essential.</dd>
492 <dd><var>mode</var> specifies operation mode. It is essential. 1 means to set the user as an administrator, 2 means to set the user as a normal user, and 0 means to revoke the user account.</dd>
493 <dd>On success, the status code 200 is returned.</dd>
494 </dl>
495
496 <dl>
497 <dt><kbd>/node/<var>name</var>/_set_link?url=<var>str</var>&amp;label=<var>str</var>&amp;credit=<var>num</var></kbd></dt>
498 <dd>Set a link to another node. It is available by administrators only.</dd>
499 <dd><var>url</var> specifies the URL of a destination node. It is essential. If the specified URL overlaps the URL of an existing link, the label and the credit is overwritten.</dd>
500 <dd><var>label</var> specifies the label of the link. It is essential.</dd>
501 <dd><var>credit</var> specifies the credit of the link. It is optional. If it is omitted, the link is removed.</dd>
502 <dd>On success, the status code 200 is returned.</dd>
503 </dl>
504
505 <p>Note that while super users has permission to administrate all nodes, an administrator of a node may not be a super user. Moreover, setting of normal users of each node have meaning only when the authorization mode is 3 (all).</p>
506
507 <h3>Format of Search Result</h3>
508
509 <p>The format of the entity body of result of search command is alike to multipart of MIME. The following is an example.</p>
510
511 <pre>--------[2387AD2E34554FFF]--------
512 VERSION 0.9
513 NODE http://localhost:1978/node/sample1
514 HIT 2
515 HINT#1 give 2
516 DOCNUM 2
517 WORDNUM 31
518 TIME 0.001
519 LINK#0 http://localhost:1978/node/sample1 Sample1 10000 2 31 2731304 2
520 LINK#1 http://localhost:1978/node/sample2 Sample2 4000 3 125 8524522 1
521 VIEW SNIPPET
522
523 --------[2387AD2E34554FFF]--------
524 #nodelabel=Sample Node One
525 #nodeurl=http://localhost:1978/node/sample1
526 @id=1
527 @uri=http://localhost/foo.html
528
529 You may my glories and my state dispose, But not my griefs; still am I king of those. (
530 Give give
531 it u
532
533 p, Yo!
534 Give give
535 it up, Yo!)
536
537 --------[2387AD2E34554FFF]--------
538 #nodelabel=Sample Node One
539 #nodeurl=http://localhost:1978/node/sample1
540 @id=2
541 @uri=http://localhost/bar.html
542
543 The faster I go, the behinder I get. (
544 Give give
545 it up, Yo!
546 Give give
547 it up, Yo!)
548
549 --------[2387AD2E34554FFF]--------:END
550 </pre>
551
552 <p>Each line feed is a single LF. The first line is definition of the border string. Each parts are delimited by the border string. The last border string is followed by ":END". The first part is the meta section. The other parts are document sections.</p>
553
554 <p>The format of the meta section is TSV. Meaning of each string is picked out by the first field. There are the following kinds.</p>
555
556 <ul>
557 <li><kbd>VERSION</kbd> : specifies the version of the protocol.</li>
558 <li><kbd>NODE</kbd> : specifies the URL of the node.</li>
559 <li><kbd>HIT</kbd> : specifies the total number of the corresponding documents.</li>
560 <li><kbd>HINT#<var>n</var></kbd> : specifies the number of documents corresponding each word. The second field specifies the word. The third field specifies the number.</li>
561 <li><kbd>DOCNUM</kbd> : specifies the total number of documents in target nodes.</li>
562 <li><kbd>WORDNUM</kbd> : specifies the total number of words in target nodes.</li>
563 <li><kbd>TIME</kbd> : specifies elapsed time in milliseconds.</li>
564 <li><kbd>LINK#<var>n</var></kbd> : specifies information of each linked node. Fields express the URL, the label, the credit, the number of documents, the number of unique words, the size of the database, and the number of corresponding documents. LINK#0 means the node it self.</li>
565 <li><kbd>VIEW</kbd> : specifies the format of document parts. As for now, it is constantly "SNIPPET".</li>
566 </ul>
567
568 <p>Each document part expresses attributes and a snippet of a document. Top lines to the first empty line expresses attributes. Their format is as with the one of document draft. The format of the snippet is TSV. 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.</p>
569
570 <p>The following pseudo-attributes are added to each result documents of the search command or the get_doc command includes.</p>
571
572 <ul>
573 <li><kbd>#nodeurl</kbd> : specifies the URL of the node into which the document was registered.</li>
574 <li><kbd>#nodelabel</kbd> : specifies the label of the node into which the document was registered.</li>
575 </ul>
576
577 <h3>Special Format for Document Registration</h3>
578
579 <p>Because URL encoding is not efficient as for large data sent for the put_doc command, the raw mode is supported. If the value of "Content-Type" is "text/x-estraier-draft", the entity body is treated as a document draft itself. The following is an example.</p>
580
581 <pre>POST /node/foo/put_doc HTTP/1.0
582 Content-Type: text/x-estraier-draft
583 Content-Length: 138
584
585 @uri=http://gogo.estraier.go.jp/sample.html
586 @title=Twinkle Twinkle Little Star
587
588 Twinkle, twinkle, little star,
589 How I wonder what you are.
590 </pre>
591
592 <hr />
593
594 <h2 id="nodeapi">Node API</h2>
595
596 <p>As it is a bother to implement HTTP, the node API is useful. This section describes how to use the node API.</p>
597
598 <h3>Introduction</h3>
599
600 <p>Using the node API, you can implement clients communicating node severs without considering such low level processing as TCP/IP and HTTP. Though the node API has overhead comparing to the core API, it is important to be able to execute at remote host and to perform parallel processing without discrimination of readers and writers.</p>
601
602 <p>In each source of applications of the node API, include `estraier.h', `estnode.h', `cabin.h', and `stdlib.h'.</p>
603
604 <pre>#include &lt;estraier.h&gt;
605 #include &lt;estnode.h&gt;
606 #include &lt;cabin.h&gt;
607 #include &lt;stdlib.h&gt;
608 </pre>
609
610 <p>To build an application, perform the following command. It is same as with the core API.</p>
611
612 <pre>gcc `estconfig --cflags` -o foobar foobar.c `estconfig --ldflags` `estconfig --libs`
613 </pre>
614
615 <p>Because the node API uses features of the core API also, if you have never read <a href="pguide-en.html">the programming guide</a>, please read it beforehand.</p>
616
617 <h3>API for Initializing</h3>
618
619 <p>For preparation to use the node API, initialize the network environment at the beginning of a program. Moreover, the environment should be freed at the end of the program.</p>
620
621 <p>The function `est_init_net_env' is used in order to initialize the networking environment.</p>
622
623 <dl>
624 <dt><kbd>int est_init_net_env(void);</kbd></dt>
625 <dd>The return value is true if success, else it is false. As it is allowable to call this function multiple times, it is needed to call the function `est_free_net_env' at the same frequency.</dd>
626 </dl>
627
628 <p>The function `est_free_net_env' is used in order to free the networking environment.</p>
629
630 <dl>
631 <dt><kbd>void est_free_net_env(void);</kbd></dt>
632 <dd>There is no parameter and no return value.</dd>
633 </dl>
634
635 <h3>API for Nodes</h3>
636
637 <p>The type of the structure `ESTNODE' is for abstraction of connection to a node. A node has its own URL. No entity of `ESTNODE' is accessed directly, but it is accessed by the pointer. The term of "node connection object" means the pointer and its referent. A node connection object is created by the function `est_node_new' and destroyed by `est_node_delete'. Every created node connection object should be destroyed.</p>
638
639 <p>The following is a typical use case of node connection object.</p>
640
641 <pre>ESTNODE *node;
642
643 /* create a node connection object */
644 node = est_node_new("http://estraier.gov:1978/node/foo");
645
646 /* set the proxy, the timeout, and the authentication */
647 est_node_set_proxy(node, "proxy.qdbm.go.jp", 8080);
648 est_node_set_timeout(node, 5);
649 est_node_set_auth(node, "mikio", "oikim");
650
651 /* register documents or search for documents here */
652
653 /* destroy the object */
654 est_node_delete(node);
655 </pre>
656
657 <p>The function `est_node_new' is used in order to create a node connection object.</p>
658
659 <dl>
660 <dt><kbd>ESTNODE *est_node_new(const char *<var>url</var>);</kbd></dt>
661 <dd>`url' specifies the URL of a node. The return value is a node connection object.</dd>
662 </dl>
663
664 <p>The function `est_node_delete' is used in order to destroy a node connection object.</p>
665
666 <dl>
667 <dt><kbd>void est_node_delete(ESTNODE *<var>node</var>);</kbd></dt>
668 <dd>`node' specifies a node connection object.</dd>
669 </dl>
670
671 <p>The function `est_node_set_proxy' is used in order to set the proxy information of a node connection object.</p>
672
673 <dl>
674 <dt><kbd>void est_node_set_proxy(ESTNODE *<var>node</var>, const char *<var>host</var>, int <var>port</var>);</kbd></dt>
675 <dd>`node' specifies a node connection object. `host' specifies the host name of a proxy server. `port' specifies the port number of the proxy server.</dd>
676 </dl>
677
678 <p>The function `est_node_set_timeout' is used in order to set timeout of a connection.</p>
679
680 <dl>
681 <dt><kbd>void est_node_set_timeout(ESTNODE *<var>node</var>, int <var>sec</var>);</kbd></dt>
682 <dd>`node' specifies a node connection object. `sec' specifies timeout of the connection in seconds.</dd>
683 </dl>
684
685 <p>The function `est_node_set_auth' is used in order to set the authentication information of a node connection object.</p>
686
687 <dl>
688 <dt><kbd>void est_node_set_auth(ESTNODE *<var>node</var>, const char *<var>name</var>, const char *<var>passwd</var>);</kbd></dt>
689 <dd>`node' specifies a node connection object. `name' specifies the name of authentication. `passwd' specifies the password of the authentication.</dd>
690 </dl>
691
692 <p>The function `est_node_status' is used in order to get the status code of the last request of a node.</p>
693
694 <dl>
695 <dt><kbd>int est_node_status(ESTNODE *<var>node</var>);</kbd></dt>
696 <dd>`node' specifies a node connection object. The return value is the status code of the last request of the node. -1 means failure of connection.</dd>
697 </dl>
698
699 <p>The function `est_node_put_doc' is used in order to add a document to a node.</p>
700
701 <dl>
702 <dt><kbd>int est_node_put_doc(ESTNODE *<var>node</var>, ESTDOC *<var>doc</var>);</kbd></dt>
703 <dd>`node' specifies a node connection object. `doc' specifies a document object. The document object should have the URI attribute. The return value is true if success, else it is false. If the URI attribute is same with an existing document in the node, the existing one is deleted.</dd>
704 </dl>
705
706 <p>The function `est_node_out_doc' is used in order to remove a document from a node.</p>
707
708 <dl>
709 <dt><kbd>int est_node_out_doc(ESTNODE *<var>node</var>, int <var>id</var>);</kbd></dt>
710 <dd>`node' specifies a node connection object. `id' specifies the ID number of a registered document. The return value is true if success, else it is false.</dd>
711 </dl>
712
713 <p>The function `est_node_out_doc_by_uri' is used in order to remove a document specified by URI from a node.</p>
714
715 <dl>
716 <dt><kbd>int est_node_out_doc_by_uri(ESTNODE *<var>node</var>, const char *<var>uri</var>);</kbd></dt>
717 <dd>`node' specifies a node connection object. `uri' specifies the URI of a registered document. The return value is true if success, else it is false.</dd>
718 </dl>
719
720 <p>The function `est_node_get_doc' is used in order to retrieve a document in a node.</p>
721
722 <dl>
723 <dt><kbd>ESTDOC *est_node_get_doc(ESTNODE *<var>node</var>, int <var>id</var>);</kbd></dt>
724 <dd>`node' specifies a node connection object. `id' specifies the ID number of a registered document. The return value is a document object. It should be deleted with `est_doc_delete' if it is no longer in use. On error, `NULL' is returned.</dd>
725 </dl>
726
727 <p>The function `est_node_get_doc_by_uri' is used in order to retrieve a document specified by URI in a node.</p>
728
729 <dl>
730 <dt><kbd>ESTDOC *est_node_get_doc_by_uri(ESTNODE *<var>node</var>, const char *<var>uri</var>);</kbd></dt>
731 <dd>`node' specifies a node connection object. `uri' specifies the URI of a registered document. The return value is a document object. It should be deleted with `est_doc_delete' if it is no longer in use. On error, `NULL' is returned.</dd>
732 </dl>
733
734 <p>The function `est_node_get_doc_attr' is used in order to retrieve the value of an attribute of a document in a node.</p>
735
736 <dl>
737 <dt><kbd>char *est_node_get_doc_attr(ESTNODE *<var>node</var>, int <var>id</var>, const char *<var>name</var>);</kbd></dt>
738 <dd>`node' specifies a node connection 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>
739 </dl>
740
741 <p>The function `est_node_get_doc_attr_by_uri' is used in order to retrieve the value of an attribute of a document specified by URI in a node.</p>
742
743 <dl>
744 <dt><kbd>char *est_node_get_doc_attr_by_uri(ESTNODE *<var>node</var>, const char *<var>uri</var>, const char *<var>name</var>);</kbd></dt>
745 <dd>`node' specifies a node connection object. `uri' specifies the URI 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>
746 </dl>
747
748 <p>The function `est_node_uri_to_id' is used in order to get the ID of a document specified by URI.</p>
749
750 <dl>
751 <dt><kbd>int est_node_uri_to_id(ESTNODE *<var>node</var>, const char *<var>uri</var>);</kbd></dt>
752 <dd>`node' specifies a node connection object. `uri' specifies the URI of a registered document. The return value is the ID of the document. On error, -1 is returned.</dd>
753 </dl>
754
755 <p>The function `est_node_name' is used in order to get the name of a node.</p>
756
757 <dl>
758 <dt><kbd>const char *est_node_name(ESTNODE *<var>node</var>);</kbd></dt>
759 <dd>`node' specifies a node connection object. The return value is the name of the node. On error, `NULL' is returned. The life duration of the returned string is synchronous with the one of the node object.</dd>
760 </dl>
761
762 <p>The function `est_node_label' is used in order to get the label of a node.</p>
763
764 <dl>
765 <dt><kbd>const char *est_node_label(ESTNODE *<var>node</var>);</kbd></dt>
766 <dd>`node' specifies a node connection object. The return value is the label of the node. On error, `NULL' is returned. The life duration of the returned string is synchronous with the one of the node object.</dd>
767 </dl>
768
769 <p>The function `est_node_doc_num' is used in order to get the number of documents in a node.</p>
770
771 <dl>
772 <dt><kbd>int est_node_doc_num(ESTNODE *<var>node</var>);</kbd></dt>
773 <dd>`node' specifies a node connection object. The return value is the number of documents in the node. On error, -1 is returned.</dd>
774 </dl>
775
776 <p>The function `est_node_word_num' is used in order to get the number of unique words in a node.</p>
777
778 <dl>
779 <dt><kbd>int est_node_word_num(ESTNODE *<var>node</var>);</kbd></dt>
780 <dd>`node' specifies a node connection object. The return value is the number of unique words in the node. On error, -1 is returned.</dd>
781 </dl>
782
783 <p>The function `est_node_size' is used in order to get the size of the database of a node.</p>
784
785 <dl>
786 <dt><kbd>double est_node_size(ESTNODE *<var>node</var>);</kbd></dt>
787 <dd>`node' specifies a node connection object. The return value is the size of the database of the node. On error, -1.0 is returned.</dd>
788 </dl>
789
790 <p>The function `est_node_search' is used in order to search documents corresponding a condition for a node.</p>
791
792 <dl>
793 <dt><kbd>ESTNODERES *est_node_search(ESTNODE *<var>node</var>, ESTCOND *<var>cond</var>, int <var>depth</var>);</kbd></dt>
794 <dd>`node' specifies a node connection object. `cond' specifies a condition object. `depth' specifies the depth of meta search. The return value is a node result object. It should be deleted with `est_noderes_delete' if it is no longer in use. On error, `NULL' is returned.</dd>
795 </dl>
796
797 <p>The function `est_node_set_user' is used in order to manage a user account of a node.</p>
798
799 <dl>
800 <dt><kbd>int est_node_set_user(ESTNODE *<var>node</var>, const char *<var>name</var>, int <var>mode</var>);</kbd></dt>
801 <dd>`node' specifies a node connection object. `name' specifies the name of a user. `mode' specifies the operation mode. 0 means to delete the account. 1 means to set the account as an administrator. 2 means to set the account as a normal user. The return value is true if success, else it is false.</dd>
802 </dl>
803
804 <p>The function `est_node_set_link' is used in order to manage a link of a node.</p>
805
806 <dl>
807 <dt><kbd>int est_node_set_link(ESTNODE *<var>node</var>, const char *<var>url</var>, const char *<var>label</var>, int <var>credit</var>);</kbd></dt>
808 <dd>`node' specifies a node connection object. `url' specifies the URL of the target node of a link. `label' specifies the label of the link. `credit' specifies the credit of the link. If it is negative, the link is removed. The return value is true if success, else it is false.</dd>
809 </dl>
810
811 <h3>API for Search Results of Nodes</h3>
812
813 <p>The type of the structure `ESTNODERES' is for abstraction of search result from a node. A result is composed of a list of corresponding documents and information of hints. No entity of `ESTNODERES' is accessed directly, but it is accessed by the pointer. The term of "node result object" means the pointer and its referent. A node result object is created by the function `est_node_search' and destroyed by `est_noderes_delete'. Every created node connection object should be destroyed.</p>
814
815 <p>The type of the structure `ESTRESDOC' is for abstraction of a document in search result. A result document is composed of some attributes and a snippet. No entity of `ESTRESDOC' is accessed directly, but it is accessed by the pointer. The term of "result document object" means the pointer and its referent. A result document object is gotten by the function `est_noderes_get_doc' but it should not be destroyed because the entity is managed inside the node result object.</p>
816
817 <p>The following is a typical use case of node connection object and result document object.</p>
818
819 <pre>ESTNODERES *nres;
820 CBMAP *hints;
821 ESTRESDOC *rdoc;
822 int i;
823
824 /* create a node result object */
825 nres = est_node_search(node, cond, 1);
826
827 /* get hints */
828 hints = est_noderes_hints(nres);
829
830 /* show the hints here */
831
832 /* scan documents in the result */
833 for(i = 0; i &lt; est_noderes_doc_num(nres); i++){
834
835 /* get a result document object */
836 rdoc = est_noderes_get_doc(nres, i);
837
838 /* show the result document object here */
839
840 }
841
842 /* destroy the node result object */
843 est_noderes_delete(nres);
844 </pre>
845
846 <p>The function `est_noderes_delete' is used in order to delete a node result object.</p>
847
848 <dl>
849 <dt><kbd>void est_noderes_delete(ESTNODERES *<var>nres</var>);</kbd></dt>
850 <dd>`nres' specifies a node result object.</dd>
851 </dl>
852
853 <p>The function `est_noderes_hints' is used in order to get a map object for hints of a node result object.</p>
854
855 <dl>
856 <dt><kbd>CBMAP *est_noderes_hints(ESTNODERES *<var>nres</var>);</kbd></dt>
857 <dd>`nres' specifies a node result object. The return value is a map object for hints. Keys of the map are "VERSION", "NODE", "HIT", "HINT#n", "DOCNUM", "WORDNUM", "TIME", "LINK#n", and "VIEW". The life duration of the returned object is synchronous with the one of the node result object.</dd>
858 </dl>
859
860 <p>The function `est_noderes_doc_num' is used in order to get the number of documents in a node result object.</p>
861
862 <dl>
863 <dt><kbd>int est_noderes_doc_num(ESTNODERES *<var>nres</var>);</kbd></dt>
864 <dd>`nres' specifies a node result object. The return value is the number of documents in a node result object.</dd>
865 </dl>
866
867 <p>The function `est_noderes_get_doc' is used in order to refer a result document object in a node result object.</p>
868
869 <dl>
870 <dt><kbd>ESTRESDOC *est_noderes_get_doc(ESTNODERES *<var>nres</var>, int <var>index</var>);</kbd></dt>
871 <dd>`nres' specifies a node result object. `index' specifies the index of a document. The return value is a result document object or `NULL' if `index' is equal to or more than the number of documents. The life duration of the returned object is synchronous with the one of the node result object.</dd>
872 </dl>
873
874 <p>The function `est_resdoc_uri' is used in order to get the URI of a result document object.</p>
875
876 <dl>
877 <dt><kbd>const char *est_resdoc_uri(ESTRESDOC *<var>rdoc</var>);</kbd></dt>
878 <dd>`rdoc' specifies a result document object. The return value is the URI of the result document object. The life duration of the returned string is synchronous with the one of the result document object.</dd>
879 </dl>
880
881 <p>The function `est_resdoc_attr_names' is used in order to get a list of attribute names of a result document object.</p>
882
883 <dl>
884 <dt><kbd>CBLIST *est_resdoc_attr_names(ESTRESDOC *<var>rdoc</var>);</kbd></dt>
885 <dd>`rdoc' specifies a result document object. The return value is a new list object of attribute names of the result 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>
886 </dl>
887
888 <p>The function `est_resdoc_attr' is used in order to get the value of an attribute of a result document object.</p>
889
890 <dl>
891 <dt><kbd>const char *est_resdoc_attr(ESTRESDOC *<var>rdoc</var>, const char *<var>name</var>);</kbd></dt>
892 <dd>`rdoc' specifies a result 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 result document object.</dd>
893 </dl>
894
895 <p>The function `est_resdoc_snippet' is used in order to get the snippet of a result document object.</p>
896
897 <dl>
898 <dt><kbd>const char *est_resdoc_snippet(ESTRESDOC *<var>rdoc</var>);</kbd></dt>
899 <dd>`rdoc' specifies a result document object. The return value is the snippet of the result 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. The life duration of the returned string is synchronous with the one of the result document object.</dd>
900 </dl>
901
902 <h3>Paralleling</h3>
903
904 <p>Each of node connection objects, node result objects, and result document objects can not be shared by threads. If you use multi threads, make each thread have its own objects. If the precondition is kept, functions of the node API can be treated as thread-safe functions.</p>
905
906 <h3>Example of Gatherer</h3>
907
908 <p>The following is the simplest implementation of a gatherer.</p>
909
910 <pre>#include &lt;estraier.h&gt;
911 #include &lt;estnode.h&gt;
912 #include &lt;cabin.h&gt;
913 #include &lt;stdlib.h&gt;
914 #include &lt;stdio.h&gt;
915
916 int main(int argc, char **argv){
917 ESTNODE *node;
918 ESTDOC *doc;
919 /* initialize the network environment */
920 if(!est_init_net_env()){
921 fprintf(stderr, "error: network is unavailable\n");
922 return 1;
923 }
924 /* create and configure the node connection object */
925 node = est_node_new("http://localhost:1978/node/test1");
926 est_node_set_auth(node, "admin", "admin");
927 /* create a document object */
928 doc = est_doc_new();
929 /* add attributes to the document object */
930 est_doc_add_attr(doc, "@uri", "http://estraier.gov/example.txt");
931 est_doc_add_attr(doc, "@title", "Over the Rainbow");
932 /* add the body text to the document object */
933 est_doc_add_text(doc, "Somewhere over the rainbow. Way up high.");
934 est_doc_add_text(doc, "There's a land that I heard of once in a lullaby.");
935 /* register the document object to the node */
936 if(!est_node_put_doc(node, doc))
937 fprintf(stderr, "error: %d\n", est_node_status(node));
938 /* destroy the document object */
939 est_doc_delete(doc);
940 /* destroy the node object */
941 est_node_delete(node);
942 /* free the networking environment */
943 est_free_net_env();
944 return 0;
945 }
946 </pre>
947
948 <h3>Example of Searcher</h3>
949
950 <p>The following is the simplest implementation of a searcher.</p>
951
952 <pre>#include &lt;estraier.h&gt;
953 #include &lt;estnode.h&gt;
954 #include &lt;cabin.h&gt;
955 #include &lt;stdlib.h&gt;
956 #include &lt;stdio.h&gt;
957
958 int main(int argc, char **argv){
959 ESTNODE *node;
960 ESTCOND *cond;
961 ESTNODERES *nres;
962 ESTRESDOC *rdoc;
963 int i;
964 const char *value;
965 /* initialize the network environment */
966 if(!est_init_net_env()){
967 fprintf(stderr, "error: network is unavailable\n");
968 return 1;
969 }
970 /* create the node connection object */
971 node = est_node_new("http://localhost:1978/node/test1");
972 /* create a search condition object */
973 cond = est_cond_new();
974 /* set the search phrase to the search condition object */
975 est_cond_set_phrase(cond, "rainbow AND lullaby");
976 /* get the result of search */
977 nres = est_node_search(node, cond, 0);
978 if(nres){
979 /* for each document in the result */
980 for(i = 0; i &lt; est_noderes_doc_num(nres); i++){
981 /* get a result document object */
982 rdoc = est_noderes_get_doc(nres, i);
983 /* display attributes */
984 if((value = est_resdoc_attr(rdoc, "@uri")) != NULL)
985 printf("URI: %s\n", value);
986 if((value = est_resdoc_attr(rdoc, "@title")) != NULL)
987 printf("Title: %s\n", value);
988 /* display the snippet text */
989 printf("%s", est_resdoc_snippet(rdoc));
990 }
991 /* delete the node result object */
992 est_noderes_delete(nres);
993 } else {
994 fprintf(stderr, "error: %d\n", est_node_status(node));
995 }
996 /* destroy the search condition object */
997 est_cond_delete(cond);
998 /* destroy the node object */
999 est_node_delete(node);
1000 /* free the networking environment */
1001 est_free_net_env();
1002 return 0;
1003 }
1004 </pre>
1005
1006 <hr />
1007
1008 <h2 id="estcall">Command of a Client</h2>
1009
1010 <p>`estcall' is provided as a client command to manage the node server. This section describes how to use estcall.</p>
1011
1012 <h3>Synopsis and Description</h3>
1013
1014 <p>estcall is an aggregation of sub commands. The name of a sub command is specified by the first argument. Other arguments are parsed according to each sub command. The argument <var>nurl</var> specifies the URL of a node. The option -proxy specifies the host name and the port number of a proxy server. The option -tout specifies timeout in seconds. The option -auth specifies the user name and the password of authentication information.</p>
1015
1016 <dl>
1017 <dt><kbd>estcall put [-proxy <var>host</var> <var>port</var>] [-tout <var>num</var>] [-auth <var>user</var> <var>pass</var>] <var>nurl</var> [<var>file</var>]</kbd></dt>
1018 <dd>Register a document of document draft to a node.</dd>
1019 <dd><var>file</var> specifies a target file. If it is omitted, the standard input is read.</dd>
1020 </dl>
1021
1022 <dl>
1023 <dt><kbd>estcall out [-proxy <var>host</var> <var>port</var>] [-tout <var>num</var>] [-auth <var>user</var> <var>pass</var>] <var>nurl</var> <var>expr</var></kbd></dt>
1024 <dd>Remove information of a document from a node.</dd>
1025 <dd><var>expr</var> specifies the ID number or the URI of a document.</dd>
1026 </dl>
1027
1028 <dl>
1029 <dt><kbd>estcall get [-proxy <var>host</var> <var>port</var>] [-tout <var>num</var>] [-auth <var>user</var> <var>pass</var>] <var>nurl</var> <var>expr</var> [<var>attr</var>]</kbd></dt>
1030 <dd>Output document draft of a document in a node.</dd>
1031 <dd><var>expr</var> specifies the ID number or the URI of a document.</dd>
1032 <dd>If <var>attr</var> is specified, only the value of the attribute is output.</dd>
1033 </dl>
1034
1035 <dl>
1036 <dt><kbd>estcall uriid [-proxy <var>host</var> <var>port</var>] [-tout <var>num</var>] [-auth <var>user</var> <var>pass</var>] <var>nurl</var> <var>uri</var></kbd></dt>
1037 <dd>Output the ID number of a document specified by URI.</dd>
1038 <dd><var>uri</var> specifies the URI of a document.</dd>
1039 </dl>
1040
1041 <dl>
1042 <dt><kbd>estcall inform [-proxy <var>host</var> <var>port</var>] [-tout <var>num</var>] [-auth <var>user</var> <var>pass</var>] <var>nurl</var></kbd></dt>
1043 <dd>Output the name, the label, the number of documents, and the number of unique words of a node.</dd>
1044 </dl>
1045
1046 <dl>
1047 <dt><kbd>estcall search [-proxy <var>host</var> <var>port</var>] [-tout <var>num</var>] [-auth <var>user</var> <var>pass</var>] [-vx] [-sf] [-attr <var>expr</var>] [-ord <var>expr</var>] [-max <var>num</var>] [-dpt <var>num</var>] <var>nurl</var> [<var>phrase</var>]</kbd></dt>
1048 <dd>Search a node for documents.</dd>
1049 <dd><var>phrase</var> specifies the search phrase.</dd>
1050 <dd>If -vx is specified, XML including including attributes and snippets is output.</dd>
1051 <dd>If -sf is specified, the phrase is treated as a simplified form.</dd>
1052 <dd>-attr specifies an attribute search condition. This option can be specified multiple times.</dd>
1053 <dd>-ord specifies the order expression. By default, it is descending by score.</dd>
1054 <dd>-max specifies the maximum number of show documents. Negative means unlimited. By default, it is 10.</dd>
1055 <dd>-dpt specifies depth of meta search. by default it is 0.</dd>
1056 </dl>
1057
1058 <dl>
1059 <dt><kbd>estcall setuser [-proxy <var>host</var> <var>port</var>] [-tout <var>num</var>] [-auth <var>user</var> <var>pass</var>] <var>nurl</var> <var>name</var> <var>mode</var></kbd></dt>
1060 <dd>Set permission of a user.</dd>
1061 <dd><var>name</var> specifies the name of a user.</dd>
1062 <dd><var>mode</var> specifies operation mode. 1 means to set the user as an administrator, 2 means to set the user as a normal user, and 0 means to revoke the user account.</dd>
1063 </dl>
1064
1065 <dl>
1066 <dt><kbd>estcall setlink [-proxy <var>host</var> <var>port</var>] [-tout <var>num</var>] [-auth <var>user</var> <var>pass</var>] <var>nurl</var> <var>url</var> <var>label</var> <var>credit</var></kbd></dt>
1067 <dd>Set a link to another node.</dd>
1068 <dd><var>url</var> specifies the URL of a destination node.</dd>
1069 <dd><var>label</var> specifies the label of the link.</dd>
1070 <dd><var>credit</var> specifies the credit of the link. If the value is negative, the link is removed.</dd>
1071 </dl>
1072
1073 <dl>
1074 <dt><kbd>estcall raw [-proxy <var>host</var> <var>port</var>] [-tout <var>num</var>] [-auth <var>user</var> <var>pass</var>] [-np] [-eh <var>expr</var>] <var>url</var> [<var>file</var>]</kbd></dt>
1075 <dd>Output response of an HTTP request.</dd>
1076 <dd><var>url</var> specifies the URL of a target.</dd>
1077 <dd>If <var>file</var> is specified, the content is sent by POST method. If not, GET method is used. If "-" is specified, the standard input is read.</dd>
1078 <dd>If -np is specified, output response headers also.</dd>
1079 <dd>-eh specifies an additional HTTP header. By default, "Host", "Connection", "User-Agent", and "Content-Length" is added.</dd>
1080 </dl>
1081
1082 <p>All sub commands return 0 if the operation is success, else return 1.</p>
1083
1084 <h3>Examples</h3>
1085
1086 <p>Operations for the node maser itself is not provided as APIs, use the raw sub command for that purpose. For example, the following command is used in order to shutdown the node master.</p>
1087
1088 <pre>estcall raw -auth admin admin \
1089 'http://localhost:1978/master?action=shutdown'
1090 </pre>
1091
1092 <p>In order to add a user, perform the following command.</p>
1093
1094 <pre>estcall raw -auth admin admin \
1095 'http://localhost:1978/master?action=useradd&amp;name=mikio&amp;passwd=iloveyou'
1096 </pre>
1097
1098 <p>In order to use POST method, perform the following command.</p>
1099
1100 <pre>echo -n 'action=useradd&amp;name=mikio&amp;passwd=iloveyou' |
1101 estcall raw -auth admin admin \
1102 -eh 'Content-Type: application/x-www-form-urlencoded' \
1103 'http://localhost:1978/master' -
1104 </pre>
1105
1106 <hr />
1107
1108 </body>
1109
1110 </html>
1111
1112 <!-- END OF FILE -->

  ViewVC Help
Powered by ViewVC 1.1.26