YUKI Hiroshi
null+****@clear*****
Fri Mar 28 16:45:39 JST 2014
YUKI Hiroshi 2014-03-28 16:45:39 +0900 (Fri, 28 Mar 2014) New Revision: 06e2f17c2c1572a4de29b4bff543b3c23ed1b307 https://github.com/droonga/droonga.org/commit/06e2f17c2c1572a4de29b4bff543b3c23ed1b307 Message: Use droonga-http-server instead of express-droonga Modified files: _po/ja/tutorial/basic/index.po ja/tutorial/basic/index.md tutorial/basic/index.md Modified: _po/ja/tutorial/basic/index.po (+37 -311) =================================================================== --- _po/ja/tutorial/basic/index.po 2014-03-28 15:21:22 +0900 (51b566e) +++ _po/ja/tutorial/basic/index.po 2014-03-28 16:45:39 +0900 (ec50f12) @@ -102,13 +102,14 @@ msgstr "" "TTP、Socket.IOなど)とを翻訳することになります。" msgid "" -"Currently, there is an implementation for the HTTP: [express-droonga][], a [No" -"de.js][] module package.\n" -"In other words, the express-droonga is a Droonga HTTP Protocol Adapter." +"Currently, there is an implementation for the HTTP: [droonga-http-server][], a" +" [Node.js][] module package.\n" +"In other words, the droonga-http-server is one of Droonga Progocol Adapters, a" +"nd it's a \"Droonga HTTP Protocol Adapter\"." msgstr "" -"現在の所、HTTP用の実装として、[Node.js][]用モジュールパッケージの[express-droonga][]が存在しています。\n" -"言い直すと、express-droongaはDroonga Protocol Adapterの一実装で、言わば「Droonga HTTP Protocol " -"Adapter」であるという事です。" +"現在の所、HTTP用の実装として、[Node.js][]用モジュールパッケージの[droonga-http-server][]が存在しています。\n" +"言い直すと、droonga-http-serverはDroonga Protocol Adapterの一実装で、言わば「Droonga HTTP Proto" +"col Adapter」であるという事です。" msgid "## Abstract of the system described in this tutorial" msgstr "## チュートリアルでつくるシステムの全体像" @@ -121,11 +122,11 @@ msgid "" "-----+\n" " | Web Browser | <--------> | Protocol Adapter | <-------> | Droonga En" "gine |\n" -" +-------------+ HTTP / +------------------+ Fluent +-----------" +" +-------------+ HTTP +------------------+ Fluent +-----------" "-----+\n" -" Socket.IO w/express-droonga protocol w/fluent-pl" -"ugin\n" -" -dr" +" w/droonga-http protocol w/fluent-plu" +"gin\n" +" -server -dr" "oonga" msgstr "" @@ -1517,102 +1518,35 @@ msgstr "" msgid "" "Now the store names are retrieved. The engine looks working correctly.\n" -"Next, setup a protocol adapter for clients to accept search requests using pop" -"ular protocols." +"Next, setup a protocol adapter for clients to accept search requests via HTTP." msgstr "" -"店舗の名前が取得できました。エンジンは正しく動作しているようです。引き続き Protocol Adapter を構築して、検索リクエストを受け付けられるよう" -"にしましょう。" +"店舗の名前が取得できました。エンジンは正しく動作しているようです。引き続き Protocol Adapter を構築して、検索リクエストをHTTPで受け付け" +"られるようにしましょう。" -msgid "## Build a protocol adapter" -msgstr "## Protocol Adapter を構築する" +msgid "## Setup an HTTP Protocol Adapter" +msgstr "## HTTP Protocol Adapter を用意する" msgid "" -"Let's use the `express-droonga` to build a protocol adapter. It is an npm pack" -"age for the Node.js." +"Let's use the `droonga-http-server` as an HTTP protocol adapter. It is an npm " +"package for the Node.js." msgstr "" -"Protocol Adapter を構築するために、 `express-droonga` を使用します。 `express-droonga` は、Node." -"js のパッケージです。" +"HTTP Protocol Adapterとして`droonga-http-server`を使用します。`droonga-http-server`は、Nod" +"e.js のパッケージです。" -msgid "### Install a express-droonga" -msgstr "### express-droonga をインストールする" +msgid "### Install the droonga-http-server" +msgstr "### droonga-http-serverをインストールする" -msgid "" -" # cd ~\n" -" # mkdir protocol-adapter\n" -" # cd protocol-adapter" -msgstr "" - -msgid "After that, put a file `package.json` like following, into the directory:" -msgstr "以下のような `package.json` を用意します。" - -msgid "package.json:" -msgstr "" - -msgid "" -" {\n" -" \"name\": \"protocol-adapter\",\n" -" \"description\": \"Droonga Protocol Adapter\",\n" -" \"version\": \"0.0.0\",\n" -" \"author\": \"Droonga Project\",\n" -" \"private\": true,\n" -" \"dependencies\": {\n" -" \"express\": \"*\",\n" -" \"express-droonga\": \"*\"\n" -" }\n" -" }" -msgstr "" - -msgid "Install depending packages." -msgstr "必要なパッケージをインストールします。" - -msgid " $ npm install" -msgstr "" - -msgid "### Create a protocol adapter" -msgstr "### Protocol Adapter を作成する" - -msgid "Put a file `application.js` like following, into the directory:" -msgstr "以下のような内容で `application.js` を作成します。" - -msgid "application.js:" -msgstr "" - -msgid "" -" var express = require('express'),\n" -" droonga = require('express-droonga');" +msgid " # npm install -g droonga-http-server" msgstr "" -msgid "" -" var application = express();\n" -" var server = require('http').createServer(application);\n" -" server.listen(3000); // the port to communicate with clients" -msgstr "" - -msgid "" -" application.droonga({\n" -" prefix: '/droonga',\n" -" tag: 'starbucks',\n" -" defaultDataset: 'Starbucks',\n" -" server: server, // this is required to initialize Socket.IO API!\n" -" plugins: [\n" -" droonga.API_REST,\n" -" droonga.API_SOCKET_IO,\n" -" droonga.API_GROONGA,\n" -" droonga.API_DROONGA\n" -" ]\n" -" });" -msgstr "" +msgid "Then, run it." +msgstr "次に、サーバを起動します。" -msgid "Then, run the `application.js`." -msgstr "`application.js` を実行します。" - -msgid "" -" # nodejs application.js\n" -" info - socket.io started" +msgid " # droonga-http-server" msgstr "" -msgid "### Synchronous search request via HTTP" -msgstr "### HTTPでの同期的な検索のリクエスト" +msgid "### Search request via HTTP" +msgstr "### HTTPでの検索リクエスト" msgid "" "We're all set. Let's send a search request to the protocol adapter via HTTP. A" @@ -1795,234 +1729,26 @@ msgstr "" msgid "As the result, two stores are found by the search condition." msgstr "以上 2 件が検索結果として該当することがわかりました。" -msgid "### Asynchronous search request via Socket.IO" -msgstr "### Socket.IO を用いた非同期処理" - -msgid "" -"A Droonga protocol adapter supports not only REST API, but also [Socket.IO][]." -" If you send a request to a protocol adapter via Socket.IO, then the protocol " -"adapter sends back the response for the request after the operation is finishe" -"d. So you can develop a system based on a client application and an API server" -" communicating with each other asynchronously." -msgstr "" -"Droonga の Protocol Adapter は、 REST API だけでなく、 [Socket.IO][] にも対応しています。Socket.I" -"O 経由で Protocol Adapter へリクエストを送ると、処理が完了した時点で Protocol Adapter から結果を送り返してもらえます。" -"この仕組を利用すると、クライアントアプリケーションと Droonga の間でリクエストとレスポンスを別々に送り合う、非同期な通信を行うことができます。" - -msgid "Now, let's create such a system based on Socket.IO." -msgstr "" -"ここでは、Webブラウザを「クライアントアプリケーション」とし、Protocol Adapter との間で Socket.IO を利用して通信するアプリケー" -"ションを作成してみましょう。" - -msgid "" -"The sample client application is a simple Web page `index.html` loaded in a We" -"b browser, returned by the protocol adapter itself.\n" -"Put a file `index.html` into the `protocol-adaptor` directory, like following:" -msgstr "" -"Protocol Adapter から `index.html` を配信し、Webブラウザに渡すことにしましょう。\n" -"`protocol-adapter` ディレクトリの下に以下の内容の `index.html` を配置します。" - -msgid "index.html:" -msgstr "" - -msgid "" -" <html>\n" -" <head>\n" -" <script src=\"/socket.io/socket.io.js\"></script>\n" -" <script>\n" -" var socket = io.connect();\n" -" socket.on('search.result', function (data) {\n" -" document.body.textContent += JSON.stringify(data);\n" -" });\n" -" socket.emit('search', { queries: {\n" -" stores: {\n" -" source: 'Store',\n" -" output: {\n" -" elements: [\n" -" 'startTime',\n" -" 'elapsedTime',\n" -" 'count',\n" -" 'attributes',\n" -" 'records'\n" -" ],\n" -" attributes: ['_key'],\n" -" limit: -1\n" -" }\n" -" }\n" -" }});\n" -" </script>\n" -" </head>\n" -" <body>\n" -" </body>\n" -" </html>" -msgstr "" - -msgid "" -"This client sends a search query by `socket.emit()`. After the request is proc" -"essed and the result is returned, the callback given as `socket.on('search.res" -"ult', ...)` will be called with the result, and it will render the result to t" -"he page." -msgstr "" -"`socket.emit()` でクエリを送信します。クエリの処理が完了し、結果が戻ってくると、 `socket.on('search.result', ." -"..)` のコールバックが呼ばれ、ページ内にその結果が表示されます。" - -msgid "" -"The first argument `'search'` for the method call `socket.emit()` means that t" -"he request is a search request.\n" -"The second argument includes parameters of the search request. See the command" -" reference of the [`search` command](/reference/commands/search) for more deta" -"ils.\n" -"(By the way, we used a REST API to do search in the previous section. In the c" -"ase the protocol adapter translates a HTTP request to a message in the format " -"described in the [command reference of the `search`](/reference/commands/searc" -"h) internally and sends it to the Droonga engine.)" -msgstr "" -"`socket.emit()` の第1引数 `'search'` は、このリクエストが検索リクエストであることを指定しています。\n" -"第2引数でどのような検索を行うかを指定しています。\n" -"詳しくは [search](/ja/reference/commands/search) を参照してください。\n" -"ところで、前のセクションでは、REST API を利用して検索を行いました。\n" -"REST API を利用した場合は、 `express-droonga` が内部で REST リクエストから上記の形式のメッセージへと変換し、`fluent" -"-plugin-droonga` に送信するようになっています。" - -msgid "" -"Next, modify the `application.js` to host the `index.html` by the protocol ada" -"pter, like:" -msgstr "" -"では、この `index.html` を Protocol Adapter でホストできるようにするため、`application.js` を以下のように書" -"き換えます。" - -msgid "" -" //============== INSERTED ==============\n" -" application.get('/', function(req, res) {\n" -" res.sendfile(__dirname + '/index.html');\n" -" });\n" -" //============= /INSERTED ==============" -msgstr "" - -msgid "" -"Then, type the IP address of the server for experiments into the address bar o" -"f your Web browser. For example, if the IP address is `192.0.2.1`, then the lo" -"cation is `http://192.0.2.1:3000/` and you can see the contents of the `index." -"html`. When you see the search result like following, then the search request " -"is successfully processed:" -msgstr "" -"Web ブラウザにサーバの IP アドレスを入れて、リクエストを送信してみましょう。\n" -"以降、サーバの IP アドレスが `192.0.2.1` であったとします。\n" -"`http://192.0.2.1:3000/` をリクエストすると、先の `index.html` が返されるようになります。\n" -"Webブラウザから `http://192.0.2.1:3000` を開いてみてください。以下のように検索結果が表示されれば成功です。" - -msgid "" -" {\"stores\":{\"count\":40,\"records\":[[\"76th & Second - New York NY (W)\"],[\"15t" -"h & Third - New York NY (W)\"],[\"41st and Broadway - New York NY (W)\"],[\"West 4" -"3rd and Broadway - New York NY (W)\"],[\"Macy's 6th Floor - Herald Square - New " -"York NY (W)\"],[\"Herald Square- Macy's - New York NY\"],[\"Columbus @ 67th - New " -"York NY (W)\"],[\"45th & Broadway - New York NY (W)\"],[\"1585 Broadway (47th) - N" -"ew York NY (W)\"],[\"85th & First - New York NY (W)\"],[\"92nd & 3rd - New York NY" -" (W)\"],[\"1656 Broadway - New York NY (W)\"],[\"19th & 8th - New York NY (W)\"],[\"" -"60th & Broadway-II - New York NY (W)\"],[\"195 Broadway - New York NY (W)\"],[\"2 " -"Broadway - New York NY (W)\"],[\"NY Plaza - New York NY (W)\"],[\"36th and Madison" -" - New York NY (W)\"],[\"125th St. btwn Adam Clayton & FDB - New York NY\"],[\"213" -"8 Broadway - New York NY (W)\"],[\"118th & Frederick Douglas Blvd. - New York NY" -" (W)\"],[\"42nd & Second - New York NY (W)\"],[\"1st Avenue & 75th St. - New York " -"NY (W)\"],[\"2nd Ave. & 9th Street - New York NY\"],[\"84th & Third Ave - New York" -" NY (W)\"],[\"150 E. 42nd Street - New York NY (W)\"],[\"Macy's 35th Street Balcon" -"y - New York NY\"],[\"Macy's 5th Floor - Herald Square - New York NY (W)\"],[\"80t" -"h & York - New York NY (W)\"],[\"Marriott Marquis - Lobby - New York NY\"],[\"Seco" -"nd @ 81st - New York NY (W)\"],[\"52nd & Seventh - New York NY (W)\"],[\"165 Broad" -"way - 1 Liberty - New York NY (W)\"],[\"54th & Broadway - New York NY (W)\"],[\"Li" -"mited Brands-NYC - New York NY\"],[\"63rd & Broadway - New York NY (W)\"],[\"2 Col" -"umbus Ave. - New York NY (W)\"],[\"70th & Broadway - New York NY (W)\"],[\"Broadwa" -"y @ 81st - New York NY (W)\"],[\"Fashion Inst of Technology - New York NY\"]]}}" -msgstr "" - -msgid "" -"Your Web browser sends a request to the protocol adapter via Socket.IO, the pr" -"otocol adapter sends it to the Droonga engine via fluent protocol, the engine " -"returns the search result to the protocol adapter, and the protocol adapter se" -"nds back the search result to the client." -msgstr "" -"Web ブラウザから Socket.IO 経由でリクエストが Protocol Adapter に送信され、それが Engine に送られ、検索結果が Pr" -"otocol Adapter に返され、さらに Web ブラウザに返されます。" - -msgid "" -"Next, try a fulltext search request like the previous section, to find stores " -"with the town name \"Columbus\".\n" -"Modify the parameter given to the `socket.emit()` method in the `index.html`, " -"like following:" -msgstr "" -"今度は全文検索を行ってみましょう。先ほどと同様に「Columbus」を店名に含む店舗を検索します。`index.html` の `socket.emit()" -"` の呼び出しを書き換え、以下の様な `index.html` を用意します。" - -msgid "" -" <html>\n" -" <head>\n" -" <script src=\"/socket.io/socket.io.js\"></script>\n" -" <script>\n" -" var socket = io.connect();\n" -" socket.on('search.result', function (data) {\n" -" document.body.textContent += JSON.stringify(data);\n" -" });\n" -" socket.emit('search', { queries: {\n" -" stores: {\n" -" source: 'Store',\n" -" condition: {\n" -" query: 'Columbus',\n" -" matchTo: '_key'\n" -" },\n" -" output: {\n" -" elements: [\n" -" 'startTime',\n" -" 'elapsedTime',\n" -" 'count',\n" -" 'attributes',\n" -" 'records'\n" -" ],\n" -" attributes: ['_key'],\n" -" limit: -1\n" -" }\n" -" }\n" -" }});\n" -" </script>\n" -" </head>\n" -" <body>\n" -" </body>\n" -" </html>" -msgstr "" - -msgid "" -"Reload the current page `http://192.0.2.1:3000` in your Web browser, then you'" -"ll see a search result like following:" -msgstr "ブラウザで再度 `http://192.0.2.1:3000` を開くと、以下のような検索結果が表示されます。" - -msgid "" -" {\"stores\":{\"count\":2,\"records\":[[\"Columbus @ 67th - New York NY (W)\"],[\"2 " -"Columbus Ave. - New York NY (W)\"]]}}" -msgstr "" - -msgid "" -"OK, you've successfully created a client application which can send search req" -"uests and receive responses asynchronously via Socket.IO." -msgstr "このように、Socket.IO を利用して、リクエストとレスポンスを非同期に送受信する検索クライアントを作成することができました。" - msgid "## Conclusion" msgstr "## まとめ" msgid "" -"In this tutorial, you did setup both packages [fluent-plugin-droonga][] and [e" -"xpress-droonga][] which construct [Droonga][] service on a [Ubuntu Linux][Ubun" -"tu].\n" -"Moreover, you built a search system based on a protocol adapter with a Droonga" -" engine, and successfully searched." +"In this tutorial, you did setup both packages [fluent-plugin-droonga][] and [d" +"roonga-http-server][] which construct [Droonga][] service on a [Ubuntu Linux][" +"Ubuntu].\n" +"Moreover, you built a search system based on an HTTP protocol adapter with a D" +"roonga engine, and successfully searched." msgstr "" "[Ubuntu Linux][Ubuntu] 上に [Droonga][] を構成するパッケージである [fluent-plugin-droonga][] " -"と [express-droonga][] をセットアップしました。\n" -"これらのパッケージを利用することで、Protocol Adapter と Droonga Engine からなるシステムを構築し、実際に検索を行いました。" +"と [droonga-http-server][] をセットアップしました。\n" +"これらのパッケージを利用することで、HTTP Protocol Adapter と Droonga Engine からなるシステムを構築し、実際に検索を行い" +"ました。" msgid "" " [Ubuntu]: http://www.ubuntu.com/\n" " [Droonga]: https://droonga.org/\n" " [fluent-plugin-droonga]: https://github.com/droonga/fluent-plugin-droonga\n" -" [express-droonga]: https://github.com/droonga/express-droonga\n" +" [droonga-http-server]: https://github.com/droonga/droonga-http-server\n" " [Groonga]: http://groonga.org/\n" " [Ruby]: http://www.ruby-lang.org/\n" " [nvm]: https://github.com/creationix/nvm\n" Modified: ja/tutorial/basic/index.md (+16 -197) =================================================================== --- ja/tutorial/basic/index.md 2014-03-28 15:21:22 +0900 (fdd9dbc) +++ ja/tutorial/basic/index.md 2014-03-28 16:45:39 +0900 (fa72721) @@ -48,8 +48,8 @@ Protocol Adapter は、Droonga を様々なプロトコルで利用できるよ Droonga Engine自体は通信プロトコルとしてfluentdプロトコルにのみ対応しています。 その代わりに、Protocol AdapterがDroonga Engineとクライアントの間に立って、fluentdプロトコルと他の一般的なプロトコル(HTTP、Socket.IOなど)とを翻訳することになります。 -Currently, there is an implementation for the HTTP: [express-droonga][], a [Node.js][] module package. -In other words, the express-droonga is one of Droonga Progocol Adapters, and it's a "Droonga HTTP Protocol Adapter". +現在の所、HTTP用の実装として、[Node.js][]用モジュールパッケージの[droonga-http-server][]が存在しています。 +言い直すと、droonga-http-serverはDroonga Protocol Adapterの一実装で、言わば「Droonga HTTP Protocol Adapter」であるという事です。 ## チュートリアルでつくるシステムの全体像 @@ -57,9 +57,9 @@ In other words, the express-droonga is one of Droonga Progocol Adapters, and it' +-------------+ +------------------+ +----------------+ | Web Browser | <--------> | Protocol Adapter | <-------> | Droonga Engine | - +-------------+ HTTP / +------------------+ Fluent +----------------+ - Socket.IO w/express-droonga protocol w/fluent-plugin - -droonga + +-------------+ HTTP +------------------+ Fluent +----------------+ + w/droonga-http protocol w/fluent-plugin + -server -droonga \--------------------------------------------------/ @@ -1333,72 +1333,22 @@ Elapsed time: 0.008286785 ] ~~~ -店舗の名前が取得できました。エンジンは正しく動作しているようです。引き続き Protocol Adapter を構築して、検索リクエストを受け付けられるようにしましょう。 +店舗の名前が取得できました。エンジンは正しく動作しているようです。引き続き Protocol Adapter を構築して、検索リクエストをHTTPで受け付けられるようにしましょう。 -## Protocol Adapter を構築する +## HTTP Protocol Adapter を用意する -Protocol Adapter を構築するために、 `express-droonga` を使用します。 `express-droonga` は、Node.js のパッケージです。 +HTTP Protocol Adapterとして`droonga-http-server`を使用します。`droonga-http-server`は、Node.js のパッケージです。 -### express-droonga をインストールする +### droonga-http-serverをインストールする - # cd ~ - # mkdir protocol-adapter - # cd protocol-adapter + # npm install -g droonga-http-server -以下のような `package.json` を用意します。 +次に、サーバを起動します。 -package.json: + # droonga-http-server - { - "name": "protocol-adapter", - "description": "Droonga Protocol Adapter", - "version": "0.0.0", - "author": "Droonga Project", - "private": true, - "dependencies": { - "express": "*", - "express-droonga": "*" - } - } - -必要なパッケージをインストールします。 - - $ npm install - - -### Protocol Adapter を作成する - -以下のような内容で `application.js` を作成します。 - -application.js: - - var express = require('express'), - droonga = require('express-droonga'); - - var application = express(); - var server = require('http').createServer(application); - server.listen(3000); // the port to communicate with clients - - application.droonga({ - prefix: '/droonga', - tag: 'starbucks', - defaultDataset: 'Starbucks', - server: server, // this is required to initialize Socket.IO API! - plugins: [ - droonga.API_REST, - droonga.API_SOCKET_IO, - droonga.API_GROONGA, - droonga.API_DROONGA - ] - }); - -`application.js` を実行します。 - # nodejs application.js - info - socket.io started - - -### HTTPでの同期的な検索のリクエスト +### HTTPでの検索リクエスト 準備が整いました。 Protocol Adapter に向けて HTTP 経由でリクエストを発行し、データベースに問い合わせを行ってみましょう。まずは `Shops` テーブルの中身を取得してみます。以下のようなリクエストを用います。(`attributes=_key` を指定しているのは「検索結果に `_key` 値を含めて返してほしい」という意味です。これがないと、`records` に何も値がないレコードが返ってきてしまいます。`attributes` パラメータには `,` 区切りで複数の属性を指定することができます。`attributes=_key,location` と指定することで、緯度経度もレスポンスとして受け取ることができます) @@ -1553,146 +1503,15 @@ application.js: 以上 2 件が検索結果として該当することがわかりました。 -### Socket.IO を用いた非同期処理 - -Droonga の Protocol Adapter は、 REST API だけでなく、 [Socket.IO][] にも対応しています。Socket.IO 経由で Protocol Adapter へリクエストを送ると、処理が完了した時点で Protocol Adapter から結果を送り返してもらえます。この仕組を利用すると、クライアントアプリケーションと Droonga の間でリクエストとレスポンスを別々に送り合う、非同期な通信を行うことができます。 - -ここでは、Webブラウザを「クライアントアプリケーション」とし、Protocol Adapter との間で Socket.IO を利用して通信するアプリケーションを作成してみましょう。 - -Protocol Adapter から `index.html` を配信し、Webブラウザに渡すことにしましょう。 -`protocol-adapter` ディレクトリの下に以下の内容の `index.html` を配置します。 - -index.html: - - <html> - <head> - <script src="/socket.io/socket.io.js"></script> - <script> - var socket = io.connect(); - socket.on('search.result', function (data) { - document.body.textContent += JSON.stringify(data); - }); - socket.emit('search', { queries: { - stores: { - source: 'Store', - output: { - elements: [ - 'startTime', - 'elapsedTime', - 'count', - 'attributes', - 'records' - ], - attributes: ['_key'], - limit: -1 - } - } - }}); - </script> - </head> - <body> - </body> - </html> - -`socket.emit()` でクエリを送信します。クエリの処理が完了し、結果が戻ってくると、 `socket.on('search.result', ...)` のコールバックが呼ばれ、ページ内にその結果が表示されます。 - -`socket.emit()` の第1引数 `'search'` は、このリクエストが検索リクエストであることを指定しています。 -第2引数でどのような検索を行うかを指定しています。 -詳しくは [search](/ja/reference/commands/search) を参照してください。 -ところで、前のセクションでは、REST API を利用して検索を行いました。 -REST API を利用した場合は、 `express-droonga` が内部で REST リクエストから上記の形式のメッセージへと変換し、`fluent-plugin-droonga` に送信するようになっています。 - -では、この `index.html` を Protocol Adapter でホストできるようにするため、`application.js` を以下のように書き換えます。 - -application.js: - - var express = require('express'), - droonga = require('express-droonga'); - - var application = express(); - var server = require('http').createServer(application); - server.listen(3000); // the port to communicate with clients - - application.droonga({ - prefix: '/droonga', - tag: 'starbucks', - defaultDataset: 'Starbucks', - server: server, // this is required to initialize Socket.IO API! - plugins: [ - droonga.API_REST, - droonga.API_SOCKET_IO, - droonga.API_GROONGA, - droonga.API_DROONGA - ] - }); - - //============== INSERTED ============== - application.get('/', function(req, res) { - res.sendfile(__dirname + '/index.html'); - }); - //============= /INSERTED ============== - -Web ブラウザにサーバの IP アドレスを入れて、リクエストを送信してみましょう。 -以降、サーバの IP アドレスが `192.0.2.1` であったとします。 -`http://192.0.2.1:3000/` をリクエストすると、先の `index.html` が返されるようになります。 -Webブラウザから `http://192.0.2.1:3000` を開いてみてください。以下のように検索結果が表示されれば成功です。 - - {"stores":{"count":40,"records":[["76th & Second - New York NY (W)"],["15th & Third - New York NY (W)"],["41st and Broadway - New York NY (W)"],["West 43rd and Broadway - New York NY (W)"],["Macy's 6th Floor - Herald Square - New York NY (W)"],["Herald Square- Macy's - New York NY"],["Columbus @ 67th - New York NY (W)"],["45th & Broadway - New York NY (W)"],["1585 Broadway (47th) - New York NY (W)"],["85th & First - New York NY (W)"],["92nd & 3rd - New York NY (W)"],["1656 Broadway - New York NY (W)"],["19th & 8th - New York NY (W)"],["60th & Broadway-II - New York NY (W)"],["195 Broadway - New York NY (W)"],["2 Broadway - New York NY (W)"],["NY Plaza - New York NY (W)"],["36th and Madison - New York NY (W)"],["125th St. btwn Adam Clayton & FDB - New York NY"],["2138 Broadway - New York NY (W)"],["118th & Frederick Douglas Blvd. - New York NY (W)"],["42nd & Second - New York NY (W)"],["1st Avenue & 75th St. - New York NY (W)"],["2nd Ave. & 9th Street - New York NY"],["84 th & Thi rd Ave - New York NY (W)"],["150 E. 42nd Street - New York NY (W)"],["Macy's 35th Street Balcony - New York NY"],["Macy's 5th Floor - Herald Square - New York NY (W)"],["80th & York - New York NY (W)"],["Marriott Marquis - Lobby - New York NY"],["Second @ 81st - New York NY (W)"],["52nd & Seventh - New York NY (W)"],["165 Broadway - 1 Liberty - New York NY (W)"],["54th & Broadway - New York NY (W)"],["Limited Brands-NYC - New York NY"],["63rd & Broadway - New York NY (W)"],["2 Columbus Ave. - New York NY (W)"],["70th & Broadway - New York NY (W)"],["Broadway @ 81st - New York NY (W)"],["Fashion Inst of Technology - New York NY"]]}} - -Web ブラウザから Socket.IO 経由でリクエストが Protocol Adapter に送信され、それが Engine に送られ、検索結果が Protocol Adapter に返され、さらに Web ブラウザに返されます。 - -今度は全文検索を行ってみましょう。先ほどと同様に「Columbus」を店名に含む店舗を検索します。`index.html` の `socket.emit()` の呼び出しを書き換え、以下の様な `index.html` を用意します。 - - <html> - <head> - <script src="/socket.io/socket.io.js"></script> - <script> - var socket = io.connect(); - socket.on('search.result', function (data) { - document.body.textContent += JSON.stringify(data); - }); - socket.emit('search', { queries: { - stores: { - source: 'Store', - condition: { - query: 'Columbus', - matchTo: '_key' - }, - output: { - elements: [ - 'startTime', - 'elapsedTime', - 'count', - 'attributes', - 'records' - ], - attributes: ['_key'], - limit: -1 - } - } - }}); - </script> - </head> - <body> - </body> - </html> - -ブラウザで再度 `http://192.0.2.1:3000` を開くと、以下のような検索結果が表示されます。 - - {"stores":{"count":2,"records":[["Columbus @ 67th - New York NY (W)"],["2 Columbus Ave. - New York NY (W)"]]}} - -このように、Socket.IO を利用して、リクエストとレスポンスを非同期に送受信する検索クライアントを作成することができました。 - - ## まとめ -[Ubuntu Linux][Ubuntu] 上に [Droonga][] を構成するパッケージである [fluent-plugin-droonga][] と [express-droonga][] をセットアップしました。 -これらのパッケージを利用することで、Protocol Adapter と Droonga Engine からなるシステムを構築し、実際に検索を行いました。 +[Ubuntu Linux][Ubuntu] 上に [Droonga][] を構成するパッケージである [fluent-plugin-droonga][] と [droonga-http-server][] をセットアップしました。 +これらのパッケージを利用することで、HTTP Protocol Adapter と Droonga Engine からなるシステムを構築し、実際に検索を行いました。 [Ubuntu]: http://www.ubuntu.com/ [Droonga]: https://droonga.org/ [fluent-plugin-droonga]: https://github.com/droonga/fluent-plugin-droonga - [express-droonga]: https://github.com/droonga/express-droonga + [droonga-http-server]: https://github.com/droonga/droonga-http-server [Groonga]: http://groonga.org/ [Ruby]: http://www.ruby-lang.org/ [nvm]: https://github.com/creationix/nvm Modified: tutorial/basic/index.md (+16 -193) =================================================================== --- tutorial/basic/index.md 2014-03-28 15:21:22 +0900 (6d6c335) +++ tutorial/basic/index.md 2014-03-28 16:45:39 +0900 (2b12046) @@ -39,8 +39,8 @@ The component "Protocol Adapter" provides ability for clients to communicate wit The only one available protocol of a Droonga engine is the fluentd protocol. Instead, protocol adapters translate it to other common protocols (like HTTP, Socket.OP, etc.) between the Droonga Engine and clients. -Currently, there is an implementation for the HTTP: [express-droonga][], a [Node.js][] module package. -In other words, the express-droonga is one of Droonga Progocol Adapters, and it's a "Droonga HTTP Protocol Adapter". +Currently, there is an implementation for the HTTP: [droonga-http-server][], a [Node.js][] module package. +In other words, the droonga-http-server is one of Droonga Progocol Adapters, and it's a "Droonga HTTP Protocol Adapter". ## Abstract of the system described in this tutorial @@ -48,9 +48,9 @@ This tutorial describes steps to build a system like following: +-------------+ +------------------+ +----------------+ | Web Browser | <--------> | Protocol Adapter | <-------> | Droonga Engine | - +-------------+ HTTP / +------------------+ Fluent +----------------+ - Socket.IO w/express-droonga protocol w/fluent-plugin - -droonga + +-------------+ HTTP +------------------+ Fluent +----------------+ + w/droonga-http protocol w/fluent-plugin + -server -droonga \--------------------------------------------------/ @@ -1326,72 +1326,22 @@ Elapsed time: 0.008286785 ~~~ Now the store names are retrieved. The engine looks working correctly. -Next, setup a protocol adapter for clients to accept search requests using popular protocols. +Next, setup a protocol adapter for clients to accept search requests via HTTP. -## Build a protocol adapter +## Setup an HTTP Protocol Adapter -Let's use the `express-droonga` to build a protocol adapter. It is an npm package for the Node.js. +Let's use the `droonga-http-server` as an HTTP protocol adapter. It is an npm package for the Node.js. -### Install a express-droonga +### Install the droonga-http-server - # cd ~ - # mkdir protocol-adapter - # cd protocol-adapter + # npm install -g droonga-http-server -After that, put a file `package.json` like following, into the directory: +Then, run it. -package.json: + # droonga-http-server - { - "name": "protocol-adapter", - "description": "Droonga Protocol Adapter", - "version": "0.0.0", - "author": "Droonga Project", - "private": true, - "dependencies": { - "express": "*", - "express-droonga": "*" - } - } - -Install depending packages. - - $ npm install - - -### Create a protocol adapter - -Put a file `application.js` like following, into the directory: - -application.js: - - var express = require('express'), - droonga = require('express-droonga'); - - var application = express(); - var server = require('http').createServer(application); - server.listen(3000); // the port to communicate with clients - - application.droonga({ - prefix: '/droonga', - tag: 'starbucks', - defaultDataset: 'Starbucks', - server: server, // this is required to initialize Socket.IO API! - plugins: [ - droonga.API_REST, - droonga.API_SOCKET_IO, - droonga.API_GROONGA, - droonga.API_DROONGA - ] - }); - -Then, run the `application.js`. - # nodejs application.js - info - socket.io started - - -### Synchronous search request via HTTP +### Search request via HTTP We're all set. Let's send a search request to the protocol adapter via HTTP. At first, try to get all records of the `Stores` table by a request like following. (Note: The `attributes=_key` parameter means "export the value of the column `_key` to the search result". If you don't set the parameter, each record returned in the `records` will become just a blank array. You can specify multiple column names by the delimiter `,`. For example `attributes=_key,location` will return both the primary key and the location for each record.) @@ -1546,142 +1496,15 @@ Next step, let's try more meaningful query. To search stores which contain "Colu As the result, two stores are found by the search condition. -### Asynchronous search request via Socket.IO - -A Droonga protocol adapter supports not only REST API, but also [Socket.IO][]. If you send a request to a protocol adapter via Socket.IO, then the protocol adapter sends back the response for the request after the operation is finished. So you can develop a system based on a client application and an API server communicating with each other asynchronously. - -Now, let's create such a system based on Socket.IO. - -The sample client application is a simple Web page `index.html` loaded in a Web browser, returned by the protocol adapter itself. -Put a file `index.html` into the `protocol-adaptor` directory, like following: - -index.html: - - <html> - <head> - <script src="/socket.io/socket.io.js"></script> - <script> - var socket = io.connect(); - socket.on('search.result', function (data) { - document.body.textContent += JSON.stringify(data); - }); - socket.emit('search', { queries: { - stores: { - source: 'Store', - output: { - elements: [ - 'startTime', - 'elapsedTime', - 'count', - 'attributes', - 'records' - ], - attributes: ['_key'], - limit: -1 - } - } - }}); - </script> - </head> - <body> - </body> - </html> - -This client sends a search query by `socket.emit()`. After the request is processed and the result is returned, the callback given as `socket.on('search.result', ...)` will be called with the result, and it will render the result to the page. - -The first argument `'search'` for the method call `socket.emit()` means that the request is a search request. -The second argument includes parameters of the search request. See the command reference of the [`search` command](/reference/commands/search) for more details. -(By the way, we used a REST API to do search in the previous section. In the case the protocol adapter translates a HTTP request to a message in the format described in the [command reference of the `search`](/reference/commands/search) internally and sends it to the Droonga engine.) - -Next, modify the `application.js` to host the `index.html` by the protocol adapter, like: - -application.js: - - var express = require('express'), - droonga = require('express-droonga'); - - var application = express(); - var server = require('http').createServer(application); - server.listen(3000); // the port to communicate with clients - - application.droonga({ - prefix: '/droonga', - tag: 'starbucks', - defaultDataset: 'Starbucks', - server: server, // this is required to initialize Socket.IO API! - plugins: [ - droonga.API_REST, - droonga.API_SOCKET_IO, - droonga.API_GROONGA, - droonga.API_DROONGA - ] - }); - - //============== INSERTED ============== - application.get('/', function(req, res) { - res.sendfile(__dirname + '/index.html'); - }); - //============= /INSERTED ============== - -Then, type the IP address of the server for experiments into the address bar of your Web browser. For example, if the IP address is `192.0.2.1`, then the location is `http://192.0.2.1:3000/` and you can see the contents of the `index.html`. When you see the search result like following, then the search request is successfully processed: - - {"stores":{"count":40,"records":[["76th & Second - New York NY (W)"],["15th & Third - New York NY (W)"],["41st and Broadway - New York NY (W)"],["West 43rd and Broadway - New York NY (W)"],["Macy's 6th Floor - Herald Square - New York NY (W)"],["Herald Square- Macy's - New York NY"],["Columbus @ 67th - New York NY (W)"],["45th & Broadway - New York NY (W)"],["1585 Broadway (47th) - New York NY (W)"],["85th & First - New York NY (W)"],["92nd & 3rd - New York NY (W)"],["1656 Broadway - New York NY (W)"],["19th & 8th - New York NY (W)"],["60th & Broadway-II - New York NY (W)"],["195 Broadway - New York NY (W)"],["2 Broadway - New York NY (W)"],["NY Plaza - New York NY (W)"],["36th and Madison - New York NY (W)"],["125th St. btwn Adam Clayton & FDB - New York NY"],["2138 Broadway - New York NY (W)"],["118th & Frederick Douglas Blvd. - New York NY (W)"],["42nd & Second - New York NY (W)"],["1st Avenue & 75th St. - New York NY (W)"],["2nd Ave. & 9th Street - New York NY"],["84 th & Thi rd Ave - New York NY (W)"],["150 E. 42nd Street - New York NY (W)"],["Macy's 35th Street Balcony - New York NY"],["Macy's 5th Floor - Herald Square - New York NY (W)"],["80th & York - New York NY (W)"],["Marriott Marquis - Lobby - New York NY"],["Second @ 81st - New York NY (W)"],["52nd & Seventh - New York NY (W)"],["165 Broadway - 1 Liberty - New York NY (W)"],["54th & Broadway - New York NY (W)"],["Limited Brands-NYC - New York NY"],["63rd & Broadway - New York NY (W)"],["2 Columbus Ave. - New York NY (W)"],["70th & Broadway - New York NY (W)"],["Broadway @ 81st - New York NY (W)"],["Fashion Inst of Technology - New York NY"]]}} - -Your Web browser sends a request to the protocol adapter via Socket.IO, the protocol adapter sends it to the Droonga engine via fluent protocol, the engine returns the search result to the protocol adapter, and the protocol adapter sends back the search result to the client. - -Next, try a fulltext search request like the previous section, to find stores with the town name "Columbus". -Modify the parameter given to the `socket.emit()` method in the `index.html`, like following: - - <html> - <head> - <script src="/socket.io/socket.io.js"></script> - <script> - var socket = io.connect(); - socket.on('search.result', function (data) { - document.body.textContent += JSON.stringify(data); - }); - socket.emit('search', { queries: { - stores: { - source: 'Store', - condition: { - query: 'Columbus', - matchTo: '_key' - }, - output: { - elements: [ - 'startTime', - 'elapsedTime', - 'count', - 'attributes', - 'records' - ], - attributes: ['_key'], - limit: -1 - } - } - }}); - </script> - </head> - <body> - </body> - </html> - -Reload the current page `http://192.0.2.1:3000` in your Web browser, then you'll see a search result like following: - - {"stores":{"count":2,"records":[["Columbus @ 67th - New York NY (W)"],["2 Columbus Ave. - New York NY (W)"]]}} - -OK, you've successfully created a client application which can send search requests and receive responses asynchronously via Socket.IO. - - ## Conclusion -In this tutorial, you did setup both packages [fluent-plugin-droonga][] and [express-droonga][] which construct [Droonga][] service on a [Ubuntu Linux][Ubuntu]. -Moreover, you built a search system based on a protocol adapter with a Droonga engine, and successfully searched. +In this tutorial, you did setup both packages [fluent-plugin-droonga][] and [droonga-http-server][] which construct [Droonga][] service on a [Ubuntu Linux][Ubuntu]. +Moreover, you built a search system based on an HTTP protocol adapter with a Droonga engine, and successfully searched. [Ubuntu]: http://www.ubuntu.com/ [Droonga]: https://droonga.org/ [fluent-plugin-droonga]: https://github.com/droonga/fluent-plugin-droonga - [express-droonga]: https://github.com/droonga/express-droonga + [droonga-http-server]: https://github.com/droonga/droonga-http-server [Groonga]: http://groonga.org/ [Ruby]: http://www.ruby-lang.org/ [nvm]: https://github.com/creationix/nvm -------------- next part -------------- HTML����������������������������...Download