Skip to content

Commit

Permalink
Update search trial subsection
Browse files Browse the repository at this point in the history
  • Loading branch information
darashi committed Nov 13, 2013
1 parent 2d7adf8 commit 206db5c
Showing 1 changed file with 44 additions and 16 deletions.
60 changes: 44 additions & 16 deletions tutorial/index.md
Expand Up @@ -321,52 +321,81 @@ application.js:

準備が整いました。 Protocol Adapter に向けて HTTP 経由でリクエストを発行し、データベースに問い合わせを行ってみましょう。まずは `Shops` テーブルの中身を取得してみます。以下のようなリクエストを用います。(`attributes=_key` を指定しているのは「検索結果に `_key` 値を含めて返してほしい」という意味です。これがないと、`records` に何も値がないレコードが返ってきてしまいます。`attributes` パラメータには `,` 区切りで複数の属性を指定することができます。`attributes=_key,location` と指定することで、緯度経度もレスポンスとして受け取ることができます)

$ curl "http://localhost:3000/droonga/tables/Shops?attributes=_key"
$ curl "http://localhost:3000/droonga/tables/Shop?attrbutes=_key"
{
"result": {
"count": 36,
"records": [
[
"根津のたいやき"
"たい焼 カタオカ"
],
[
"たい焼 カタオカ"
"根津のたいやき"
],
[
"そばたいやき空"
],
[
"さざれ"
],
[
"おめで鯛焼き本舗錦糸町東急店"
],
[
"尾長屋 錦糸町店"
],
[
"たいやき本舗 藤家 阿佐ヶ谷店"
],
[
"みよし"
],
[
"たい焼き / たつみや"
],
[
"吾妻屋"
],
[
"たいやき神田達磨 八重洲店"
],
[
"車"
],
[
"広瀬屋"
],
[
"さざれ"
"たいやき工房白家 阿佐ヶ谷店"
],
[
"おめで鯛焼き本舗錦糸町東急店"
"寿々屋 菓子"
],
[
"尾長屋 錦糸町店"
"たい焼き鉄次 大丸東京店"
],
[
"たいやき工房白家 阿佐ヶ谷店"
"ほんま門"
],
[
"たいやき本舗 藤家 阿佐ヶ谷店"
"浪花家"
],
[
"代官山たい焼き黒鯛"
],
[
"ダ・カーポ"
]
],
"startTime": "2013-08-28T06:00:13+00:00",
"elapsedTime": 0.0002779960632324219
]
}
}

`count` の値からデータが全部で 36 件あることがわかります。そのうちの 10 件が取得できました
`count` の値からデータが全部で 36 件あることがわかります。`records` に配列として検索結果が入っています

もう少し複雑なクエリを試してみましょう。例えば、店名に「阿佐ヶ谷」を含むたいやき屋を検索します。`query` パラメータにクエリ `阿佐ヶ谷` を URL エンコードした `%E9%98%BF%E4%BD%90%E3%83%B6%E8%B0%B7` を、`match_to` パラメータに検索対象として `_key` を指定し、以下のようなリクエストを発行します。

$ curl "http://localhost:3000/droonga/tables/Shops?query=%E9%98%BF%E4%BD%90%E3%83%B6%E8%B0%B7&match_to=_key&attributes=_key"

$ curl "http://localhost:3000/droonga/tables/Shop?quer=%E9%98%BF%E4%BD%90%E3%83%B6%E8%B0%B7&match_to=_key&attributes=_key"
{
"result": {
"count": 2,
Expand All @@ -377,10 +406,9 @@ application.js:
[
"たいやき本舗 藤家 阿佐ヶ谷店"
]
],
"startTime": "2013-08-28T06:18:08+00:00",
"elapsedTime": 0.0005409717559814453
]
}
}

以上 2 件が検索結果として該当することがわかりました。

Expand Down

0 comments on commit 206db5c

Please sign in to comment.