YUKI Hiroshi
null+****@clear*****
Fri Dec 20 18:52:17 JST 2013
YUKI Hiroshi 2013-12-20 18:52:17 +0900 (Fri, 20 Dec 2013) New Revision: bab07853d76eefcf67d48a0a7fbe5884251b9937 https://github.com/droonga/droonga.org/commit/bab07853d76eefcf67d48a0a7fbe5884251b9937 Message: Use Starbucks store locationss in NY instead of taiyaki stores in Tokyo Modified files: tutorial/index.md Modified: tutorial/index.md (+113 -153) =================================================================== --- tutorial/index.md 2013-12-20 18:18:47 +0900 (a140293) +++ tutorial/index.md 2013-12-20 18:52:17 +0900 (2838b8b) @@ -56,7 +56,7 @@ This tutorial describes steps to build a system like following: User agents (ex. an Web browser) sends search requests to a protocol adapter. The adapter receives them, and sends internal (translated) search requests to a Droonga engine. The engine processes them actually. Search results are sent from the engine to the protocol adapter, and finally delivered to the user agent. -For example lets's try to build a database system to find [taiyaki](http://en.wikipedia.org/wiki/Taiyaki) shops, based on location data used in [another tutorial of Groonga](http://www.clear-code.com/blog/2011/9/13.html). +For example lets's try to build a database system to find [Starbucks stores in New York](http://geocommons.com/overlays/430038). ## Prepare an environment for experiments @@ -96,8 +96,8 @@ fluentd.conf: type forward port 24224 </source> - <match taiyaki.message> - name localhost:24224/taiyaki + <match starbucks.message> + name localhost:24224/starbucks type droonga </match> <match output.message> @@ -108,15 +108,15 @@ catalog.json: { "effective_date": "2013-09-01T00:00:00Z", - "zones": ["localhost:24224/taiyaki"], + "zones": ["localhost:24224/starbucks"], "farms": { - "localhost:24224/taiyaki": { + "localhost:24224/starbucks": { "device": ".", "capacity": 10 } }, "datasets": { - "Taiyaki": { + "Starbucks": { "workers": 0, "plugins": ["search", "groonga", "add"], "number_of_replicas": 2, @@ -128,8 +128,8 @@ catalog.json: "weight": 50, "partitions": { "2013-09-01": [ - "localhost:24224/taiyaki.000", - "localhost:24224/taiyaki.001" + "localhost:24224/starbucks.000", + "localhost:24224/starbucks.001" ] } }, @@ -137,8 +137,8 @@ catalog.json: "weight": 50, "partitions": { "2013-09-01": [ - "localhost:24224/taiyaki.002", - "localhost:24224/taiyaki.003" + "localhost:24224/starbucks.002", + "localhost:24224/starbucks.003" ] } } @@ -150,7 +150,7 @@ catalog.json: } } -This `catalog.json` defines a dataset `Taiyaki` with two replicas and two partitions. +This `catalog.json` defines a dataset `Starbucks` with two replicas and two partitions. All of replicas and partitions are stored locally (in other words, they are managed by a `fluent-plugin-droonga` instance). For more details of the configuration file `catalog.json`, see [the reference manual of catalog.json](/reference/catalog). @@ -169,8 +169,8 @@ Start a Droonga engine, it is a fluentd server with fluentd-plugin-droonga start type forward port 24224 </source> - <match taiyaki.message> - name localhost:24224/taiyaki + <match starbucks.message> + name localhost:24224/starbucks type droonga </match> <match output.message> @@ -178,72 +178,76 @@ Start a Droonga engine, it is a fluentd server with fluentd-plugin-droonga start </match> </ROOT> 2013-11-12 14:14:20 +0900 [info]: adding source type="forward" - 2013-11-12 14:14:20 +0900 [info]: adding match pattern="taiyaki.message" type="droonga" + 2013-11-12 14:14:20 +0900 [info]: adding match pattern="starbucks.message" type="droonga" 2013-11-12 14:14:20 +0900 [info]: adding match pattern="output.message" type="stdout" 2013-11-12 14:14:20 +0900 [info]: listening fluent socket on 0.0.0.0:24224 ### Create a database After a Dronga engine is started, let's load data. -Prepare two jsons files, `ddl.jsons` including the database schema and `shops.jsons` including location data of shops. +Prepare two jsons files, `ddl.jsons` including the database schema and `stores.jsons` including location data of stores. ddl.jsons: - {"id":"ddl:0","dataset":"Taiyaki","type":"table_create","replyTo":"localhost:24224/output","body":{"name":"Shop","flags":"TABLE_HASH_KEY","key_type":"ShortText"}} - {"id":"ddl:1","dataset":"Taiyaki","type":"column_create","replyTo":"localhost:24224/output","body":{"table":"Shop","name":"location","flags":"COLUMN_SCALAR","type":"WGS84GeoPoint"}} - {"id":"ddl:2","dataset":"Taiyaki","type":"table_create","replyTo":"localhost:24224/output","body":{"name":"Location","flags":"TABLE_PAT_KEY","key_type":"WGS84GeoPoint"}} - {"id":"ddl:3","dataset":"Taiyaki","type":"column_create","replyTo":"localhost:24224/output","body":{"table":"Location","name":"shop","flags":"COLUMN_INDEX","type":"Shop","source":"location"}} - {"id":"ddl:4","dataset":"Taiyaki","type":"table_create","replyTo":"localhost:24224/output","body":{"name":"Term","flags":"TABLE_PAT_KEY","key_type":"ShortText","default_tokenizer":"TokenBigram","normalizer":"NormalizerAuto"}} - {"id":"ddl:5","dataset":"Taiyaki","type":"column_create","replyTo":"localhost:24224/output","body":{"table":"Term","name":"shops__key","flags":"COLUMN_INDEX|WITH_POSITION","type":"Shop","source":"_key"}} - - -shops.jsons: - - {"id":"shops:0","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"根津のたいやき","values":{"location":"35.720253,139.762573"}}} - {"id":"shops:1","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"たい焼 カタオカ","values":{"location":"35.712521,139.715591"}}} - {"id":"shops:2","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"そばたいやき空","values":{"location":"35.683712,139.659088"}}} - {"id":"shops:3","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"車","values":{"location":"35.721516,139.706207"}}} - {"id":"shops:4","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"広瀬屋","values":{"location":"35.714844,139.685608"}}} - {"id":"shops:5","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"さざれ","values":{"location":"35.714653,139.685043"}}} - {"id":"shops:6","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"おめで鯛焼き本舗錦糸町東急店","values":{"location":"35.700516,139.817154"}}} - {"id":"shops:7","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"尾長屋 錦糸町店","values":{"location":"35.698254,139.81105"}}} - {"id":"shops:8","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"たいやき工房白家 阿佐ヶ谷店","values":{"location":"35.705517,139.638611"}}} - {"id":"shops:9","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"たいやき本舗 藤家 阿佐ヶ谷店","values":{"location":"35.703938,139.637115"}}} - {"id":"shops:10","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"みよし","values":{"location":"35.644539,139.537323"}}} - {"id":"shops:11","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"寿々屋 菓子","values":{"location":"35.628922,139.695755"}}} - {"id":"shops:12","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"たい焼き / たつみや","values":{"location":"35.665501,139.638657"}}} - {"id":"shops:13","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"たい焼き鉄次 大丸東京店","values":{"location":"35.680912,139.76857"}}} - {"id":"shops:14","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"吾妻屋","values":{"location":"35.700817,139.647598"}}} - {"id":"shops:15","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"ほんま門","values":{"location":"35.722736,139.652573"}}} - {"id":"shops:16","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"浪花家","values":{"location":"35.730061,139.796234"}}} - {"id":"shops:17","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"代官山たい焼き黒鯛","values":{"location":"35.650345,139.704834"}}} - {"id":"shops:18","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"たいやき神田達磨 八重洲店","values":{"location":"35.681461,139.770599"}}} - {"id":"shops:19","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"柳屋 たい焼き","values":{"location":"35.685341,139.783981"}}} - {"id":"shops:20","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"たい焼き写楽","values":{"location":"35.716969,139.794846"}}} - {"id":"shops:21","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"たかね 和菓子","values":{"location":"35.698601,139.560913"}}} - {"id":"shops:22","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"たい焼き ちよだ","values":{"location":"35.642601,139.652817"}}} - {"id":"shops:23","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"ダ・カーポ","values":{"location":"35.627346,139.727356"}}} - {"id":"shops:24","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"松島屋","values":{"location":"35.640556,139.737381"}}} - {"id":"shops:25","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"銀座 かずや","values":{"location":"35.673508,139.760895"}}} - {"id":"shops:26","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"ふるや古賀音庵 和菓子","values":{"location":"35.680603,139.676071"}}} - {"id":"shops:27","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"蜂の家 自由が丘本店","values":{"location":"35.608021,139.668106"}}} - {"id":"shops:28","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"薄皮たい焼き あづきちゃん","values":{"location":"35.64151,139.673203"}}} - {"id":"shops:29","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"横浜 くりこ庵 浅草店","values":{"location":"35.712013,139.796829"}}} - {"id":"shops:30","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"夢ある街のたいやき屋さん戸越銀座店","values":{"location":"35.616199,139.712524"}}} - {"id":"shops:31","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"何故屋","values":{"location":"35.609039,139.665833"}}} - {"id":"shops:32","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"築地 さのきや","values":{"location":"35.66592,139.770721"}}} - {"id":"shops:33","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"しげ田","values":{"location":"35.672626,139.780273"}}} - {"id":"shops:34","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"にしみや 甘味処","values":{"location":"35.671825,139.774628"}}} - {"id":"shops:35","replyTo":"localhost:24224/output","dataset":"Taiyaki","type":"add","body":{"table":"Shop","key":"たいやきひいらぎ","values":{"location":"35.647701,139.711517"}}} - - -Open another terminal to keep the fluentd server working, and send those two jsons `ddl.jsons` and `shops.jsons` to the fluentd server: - - $ fluent-cat taiyaki.message < ddl.jsons - $ fluent-cat taiyaki.message < shops.jsons - - -Now a Droonga engine for searching taiyaki shops database is ready. + {"id":"ddl:0","dataset":"Starbucks","type":"table_create","replyTo":"localhost:24224/output","body":{"name":"Store","flags":"TABLE_HASH_KEY","key_type":"ShortText"}} + {"id":"ddl:1","dataset":"Starbucks","type":"column_create","replyTo":"localhost:24224/output","body":{"table":"Store","name":"location","flags":"COLUMN_SCALAR","type":"WGS84GeoPoint"}} + {"id":"ddl:2","dataset":"Starbucks","type":"table_create","replyTo":"localhost:24224/output","body":{"name":"Location","flags":"TABLE_PAT_KEY","key_type":"WGS84GeoPoint"}} + {"id":"ddl:3","dataset":"Starbucks","type":"column_create","replyTo":"localhost:24224/output","body":{"table":"Location","name":"store","flags":"COLUMN_INDEX","type":"Store","source":"location"}} + {"id":"ddl:4","dataset":"Starbucks","type":"table_create","replyTo":"localhost:24224/output","body":{"name":"Term","flags":"TABLE_PAT_KEY","key_type":"ShortText","default_tokenizer":"TokenBigram","normalizer":"NormalizerAuto"}} + {"id":"ddl:5","dataset":"Starbucks","type":"column_create","replyTo":"localhost:24224/output","body":{"table":"Term","name":"stores__key","flags":"COLUMN_INDEX|WITH_POSITION","type":"Store","source":"_key"}} + + +stores.jsons: + + {"id":"stores:0","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"1st Avenue & 75th St. - New York NY (W)","values":{"location":"40.770262,-73.954798"}}} + {"id":"stores:1","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"76th & Second - New York NY (W)","values":{"location":"40.771056,-73.956757"}}} + {"id":"stores:2","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"2nd Ave. & 9th Street - New York NY","values":{"location":"40.729445,-73.987471"}}} + {"id":"stores:3","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"15th & Third - New York NY (W)","values":{"location":"40.733946,-73.9867"}}} + {"id":"stores:4","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"41st and Broadway - New York NY (W)","values":{"location":"40.755111,-73.986225"}}} + {"id":"stores:5","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"84th & Third Ave - New York NY (W)","values":{"location":"40.777485,-73.954979"}}} + {"id":"stores:6","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"150 E. 42nd Street - New York NY (W)","values":{"location":"40.750784,-73.975582"}}} + {"id":"stores:7","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"West 43rd and Broadway - New York NY (W)","values":{"location":"40.756197,-73.985624"}}} + {"id":"stores:8","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"Macy's 35th Street Balcony - New York NY","values":{"location":"40.750703,-73.989787"}}} + {"id":"stores:9","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"Macy's 6th Floor - Herald Square - New York NY (W)","values":{"location":"40.750703,-73.989787"}}} + {"id":"stores:10","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"Herald Square- Macy's - New York NY","values":{"location":"40.750703,-73.989787"}}} + {"id":"stores:11","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"Macy's 5th Floor - Herald Square - New York NY (W)","values":{"location":"40.750703,-73.989787"}}} + {"id":"stores:12","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"80th & York - New York NY (W)","values":{"location":"40.772204,-73.949862"}}} + {"id":"stores:13","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"Columbus @ 67th - New York NY (W)","values":{"location":"40.774009,-73.981472"}}} + {"id":"stores:14","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"45th & Broadway - New York NY (W)","values":{"location":"40.75766,-73.985719"}}} + {"id":"stores:15","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"Marriott Marquis - Lobby - New York NY","values":{"location":"40.759123,-73.984927"}}} + {"id":"stores:16","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"Second @ 81st - New York NY (W)","values":{"location":"40.77466,-73.954447"}}} + {"id":"stores:17","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"52nd & Seventh - New York NY (W)","values":{"location":"40.761829,-73.981141"}}} + {"id":"stores:18","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"1585 Broadway (47th) - New York NY (W)","values":{"location":"40.759806,-73.985066"}}} + {"id":"stores:19","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"85th & First - New York NY (W)","values":{"location":"40.776101,-73.949971"}}} + {"id":"stores:20","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"92nd & 3rd - New York NY (W)","values":{"location":"40.782606,-73.951235"}}} + {"id":"stores:21","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"165 Broadway - 1 Liberty - New York NY (W)","values":{"location":"40.709727,-74.011395"}}} + {"id":"stores:22","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"1656 Broadway - New York NY (W)","values":{"location":"40.762434,-73.983364"}}} + {"id":"stores:23","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"54th & Broadway - New York NY (W)","values":{"location":"40.764275,-73.982361"}}} + {"id":"stores:24","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"Limited Brands-NYC - New York NY","values":{"location":"40.765219,-73.982025"}}} + {"id":"stores:25","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"19th & 8th - New York NY (W)","values":{"location":"40.743218,-74.000605"}}} + {"id":"stores:26","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"60th & Broadway-II - New York NY (W)","values":{"location":"40.769196,-73.982576"}}} + {"id":"stores:27","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"63rd & Broadway - New York NY (W)","values":{"location":"40.771376,-73.982709"}}} + {"id":"stores:28","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"195 Broadway - New York NY (W)","values":{"location":"40.710703,-74.009485"}}} + {"id":"stores:29","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"2 Broadway - New York NY (W)","values":{"location":"40.704538,-74.01324"}}} + {"id":"stores:30","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"2 Columbus Ave. - New York NY (W)","values":{"location":"40.769262,-73.984764"}}} + {"id":"stores:31","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"NY Plaza - New York NY (W)","values":{"location":"40.702802,-74.012784"}}} + {"id":"stores:32","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"36th and Madison - New York NY (W)","values":{"location":"40.748917,-73.982683"}}} + {"id":"stores:33","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"125th St. btwn Adam Clayton & FDB - New York NY","values":{"location":"40.808952,-73.948229"}}} + {"id":"stores:34","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"70th & Broadway - New York NY (W)","values":{"location":"40.777463,-73.982237"}}} + {"id":"stores:35","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"2138 Broadway - New York NY (W)","values":{"location":"40.781078,-73.981167"}}} + {"id":"stores:36","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"118th & Frederick Douglas Blvd. - New York NY (W)","values":{"location":"40.806176,-73.954109"}}} + {"id":"stores:37","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"42nd & Second - New York NY (W)","values":{"location":"40.750069,-73.973393"}}} + {"id":"stores:38","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"Broadway @ 81st - New York NY (W)","values":{"location":"40.784972,-73.978987"}}} + {"id":"stores:39","replyTo":"localhost:24224/output","dataset":"Starbucks","type":"add","body":{"table":"Store","key":"Fashion Inst of Technology - New York NY","values":{"location":"40.746948,-73.994557"}}} + + +Open another terminal to keep the fluentd server working, and send those two jsons `ddl.jsons` and `stores.jsons` to the fluentd server: + + $ fluent-cat starbucks.message < ddl.jsons + $ fluent-cat starbucks.message < stores.jsons + + +Now a Droonga engine for searching starbucks stores database is ready. Next, setup a protocol adapter for clients to accept search requests using popular protocols. @@ -293,8 +297,8 @@ application.js: application.droonga({ prefix: '/droonga', - tag: 'taiyaki', - defaultDataset: 'Taiyaki', + tag: 'starbucks', + defaultDataset: 'Starbucks', server: server, // this is required to initialize Socket.IO API! plugins: [ droonga.API_REST, @@ -312,97 +316,53 @@ Then, run the `application.js`. ### Synchronous 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 `Shops` 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.) +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.) - $ curl "http://localhost:3000/droonga/tables/Shop?attributes=_key&limit=-1" + $ curl "http://localhost:3000/droonga/tables/Store?attributes=_key&limit=-1" { "result": { - "count": 36, + "count": 40, "records": [ - [ - "たい焼 カタオカ" - ], - [ - "根津のたいやき" - ], - [ - "そばたいやき空" - ], - [ - "さざれ" - ], - [ - "おめで鯛焼き本舗錦糸町東急店" - ], - [ - "尾長屋 錦糸町店" - ], - [ - "たいやき本舗 藤家 阿佐ヶ谷店" - ], - [ - "みよし" - ], - [ - "たい焼き / たつみや" - ], - [ - "吾妻屋" - ], - [ - "たいやき神田達磨 八重洲店" - ], - [ - "車" - ], - [ - "広瀬屋" - ], - [ - "たいやき工房白家 阿佐ヶ谷店" - ], - [ - "寿々屋 菓子" - ], - [ - "たい焼き鉄次 大丸東京店" - ], - [ - "ほんま門" - ], - [ - "浪花家" - ], - [ - "代官山たい焼き黒鯛" - ], - [ - "ダ・カーポ" - ] + ["1st Avenue & 75th St. - New York NY (W)"], + ["76th & Second - New York NY (W)"], + ["2nd Ave. & 9th Street - New York NY"], + ["15th & Third - New York NY (W)"], + ["41st and Broadway - New York NY (W)"], + ["84th & Third Ave - New York NY (W)"], + ["150 E. 42nd Street - New York NY (W)"], + ["West 43rd and Broadway - New York NY (W)"], + ["Macy's 35th Street Balcony - New York NY"], + ["Macy's 6th Floor - Herald Square - New York NY (W)"], + ["Herald Square- Macy's - New York NY"], + ["Macy's 5th Floor - Herald Square - New York NY (W)"], + ["80th & York - New York NY (W)"], + ["Columbus @ 67th - New York NY (W)"], + ["45th & Broadway - New York NY (W)"], + ["Marriott Marquis - Lobby - New York NY"], + ["Second @ 81st - New York NY (W)"], + ["52nd & Seventh - New York NY (W)"], + ["1585 Broadway (47th) - New York NY (W)"], + ["85th & First - New York NY (W)"] ] } } -Because the `count` says `36`, you know there are all 36 records in the table. Search result records are returned as an array `records`. +Because the `count` says `40`, you know there are all 40 records in the table. Search result records are returned as an array `records`. -Next step, let's try more meaningful query. To search shops which contain "阿佐ヶ谷" (Asagaya, a town name in Japan) in their name, give `阿佐ヶ谷` as the parameter `query`, and give `_key` as the parameter `match_to` which means the column to be searched. Non-ASCII characters in the `query` must be URL-encoded like `%E9%98%BF%E4%BD%90%E3%83%B6%E8%B0%B7`. Then: +Next step, let's try more meaningful query. To search stores which contain "Columbus" in their name, give `Columbus` as the parameter `query`, and give `_key` as the parameter `match_to` which means the column to be searched. Then: - $ curl "http://localhost:3000/droonga/tables/Shop?query=%E9%98%BF%E4%BD%90%E3%83%B6%E8%B0%B7&match_to=_key&attributes=_key&limit=-1" + $ curl "http://localhost:3000/droonga/tables/Store?query=Columbus&match_to=_key&attributes=_key&limit=-1" { "result": { "count": 2, "records": [ - [ - "たいやき工房白家 阿佐ヶ谷店" - ], - [ - "たいやき本舗 藤家 阿佐ヶ谷店" - ] + ["Columbus @ 67th - New York NY (W)"], + ["2 Columbus Ave. - New York NY (W)"] ] } } -As the result two shops are found by the search condition. +As the result two stores are found by the search condition. ### Asynchronous search request via Socket.IO @@ -426,7 +386,7 @@ index.html: }); socket.emit('search', { queries: { result: { - source: 'Shop', + source: 'Store', output: { elements: [ 'startTime', @@ -465,8 +425,8 @@ application.js: application.droonga({ prefix: '/droonga', - tag: 'taiyaki', - defaultDataset: 'Taiyaki', + tag: 'starbucks', + defaultDataset: 'Starbucks', server: server, // this is required to initialize Socket.IO API! plugins: [ droonga.API_REST, @@ -484,11 +444,11 @@ application.js: 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: - "result":{"count":36,"records":[["たい焼 カタオカ"],["根津のたいやき"],["そばたいやき空"],["さざれ"],["おめで鯛焼き本舗錦糸町東急店"],["尾長屋 錦糸町店"],["たいやき本舗 藤家 阿佐ヶ谷店"],["みよし"],["たい焼き / たつみや"],["吾妻屋"],["たいやき神田達磨 八重洲店"],["車"],["広瀬屋"],["たいやき工房白家 阿佐ヶ谷店"],["寿々屋 菓子"],["たい焼き鉄次 大丸東京店"],["ほんま門"],["浪花家"],["代官山たい焼き黒鯛"],["ダ・カーポ"]]}} + "result":{"count":40,"records":[["1st Avenue & 75th St. - New York NY (W)"],["76th & Second - New York NY (W)"],["2nd Ave. & 9th Street - New York NY"],["15th & Third - New York NY (W)"],["41st and Broadway - New York NY (W)"],["84th & Third Ave - New York NY (W)"],["150 E. 42nd Street - New York NY (W)"],["West 43rd and Broadway - New York NY (W)"],["Macy's 35th Street Balcony - New York NY"],["Macy's 6th Floor - Herald Square - New York NY (W)"],["Herald Square- Macy's - New York NY"],["Macy's 5th Floor - Herald Square - New York NY (W)"],["80th & York - New York NY (W)"],["Columbus @ 67th - New York NY (W)"],["45th & Broadway - New York NY (W)"],["Marriott Marquis - Lobby - New York NY"],["Second @ 81st - New York NY (W)"],["52nd & Seventh - New York NY (W)"],["1585 Broadway (47th) - New York NY (W)"],["85th & First - New York NY (W)"]]}} 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 shops with the town name "阿佐ヶ谷". +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> @@ -501,9 +461,9 @@ Modify the parameter given to the `socket.emit()` method in the `index.html`, li }); socket.emit('search', { queries: { result: { - source: 'Shop', + source: 'Store', condition: { - query: '阿佐ヶ谷', + query: 'Columbus', matchTo: '_key' }, output: { @@ -527,7 +487,7 @@ Modify the parameter given to the `socket.emit()` method in the `index.html`, li Reload the current page `http://192.0.2.1:3000` in your Web browser, then you'll see a search result like following: - {"result":{"count":2,"records":[["たいやき工房白家 阿佐ヶ谷店"],["たいやき本舗 藤家 阿佐ヶ谷店"]]}} + {"result":{"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. -------------- next part -------------- HTML����������������������������...Download