Groongaでの全文検索コマンドの使い方(groonga-httpd編)
Groongaでの全文検索コマンドの使い方(groongaコマンド編)のHTTPサーバを利用したバージョンです。
準備
前の記事と同じなので割愛します。
HTTPリクエストで実行する。
HTTPリクエストでの実行
# 通常の検索(artist_nameが「音楽家1」のレコードの、_key, name, album_name, artist_nameを出力
$ ruby -e 'require "cgi"; puts CGI.escape("artist_name==\"音楽家1\"");'
artist_name%3D%3D%22%E9%9F%B3%E6%A5%BD%E5%AE%B6%EF%BC%91%22
$ curl "http://localhost:10041/d/select.json?table=SearchTrack&query=artist_name%3A%E9%9F%B3%E6%A5%BD%E5%AE%B6%EF%BC%91&output_columns=_key,name,album_name,artist_name"
[
[0,1410366124.13972,0.000102996826171875],
[
[
[2],
[
["_key","UInt32"],
["name","ShortText"],
["album_name","ShortText"],
["artist_name","ShortText"]
],
[1,"曲名1","原盤1","音楽家1"],
[2,"曲名2","原盤1","音楽家1"]
]
]
]
# 全文検索(artist_nameが「家1」を含むレコードの、_key, name, album_name, artist_nameを出力
$ ruby -e 'require "cgi"; puts CGI.escape("家1");'
%E5%AE%B6%EF%BC%91
$ curl "http://localhost:10041/d/select.json?table=SearchTrack&match_columns=artist_name&query=%E5%AE%B6%EF%BC%91&output_columns=_key,name,album_name,artist_name"
[
[0,1410366359.34207,0.000776052474975586],
[
[
[2],
[
["_key","UInt32"],
["name","ShortText"],
["album_name","ShortText"],
["artist_name","ShortText"]
],
[1,"曲名1","原盤1","音楽家1"],
[2,"曲名2","原盤1","音楽家1"]
]
]
]
# 全文検索(album_nameが「原」と「2」を含むレコードの、_key, name, album_name, artist_nameを出力
$ ruby -e 'require "cgi"; puts CGI.escape("原盤 2");'
%E5%8E%9F%E7%9B%A4+%EF%BC%92
$ curl "http://localhost:10041/d/select.json?table=SearchTrack&match_columns=album_name&query=%E5%8E%9F%E7%9B%A4+%EF%BC%92&output_columns=_key,name,album_name,artist_name"
[
[0,1410366492.51681,0.000367164611816406],
[
[
[1],
[
["_key","UInt32"],
["name","ShortText"],
["album_name","ShortText"],
["artist_name","ShortText"]
],
[3,"曲名3","原盤2","音楽家2"]
]
]
]
# 全文検索(artist_nameかartist_name_kanaかartist_name_enのいずれかに「ち」を含むレコードの、_key, name, album_name, artist_nameを出力
> select SearchTrack --match_columns artist_name||artist_name_kana||artist_name_en --query 'ち' --output_columns '_key, name, album_name, artist_name'
$ ruby -e 'require "cgi"; puts CGI.escape("ち");'
%E3%81%A1
$ruby -e 'require "cgi"; puts CGI.escape("||");'
%7C%7C
$ curl "http://localhost:10041/d/select.json?table=SearchTrack&match_columns=artist_name%7C%7Cartist_name_kana%7C%7Cartist_name_en&query=%E3%81%A1&output_columns=_key,name,album_name,artist_name"
[
[0,1410366613.42943,0.000104904174804688],
[
[
[2],
[
["_key","UInt32"],
["name","ShortText"],
["album_name","ShortText"],
["artist_name","ShortText"]
],
[1,"曲名1","原盤1","音楽家1"],
[2,"曲名2","原盤1","音楽家1"]
]
]
]
前の記事と比較すると、基本的にgroongaコマンドを呼び出す時のパラメータを、そのままGETで渡せばOKだという事がわかります。
メモ
- load等でのデータ書き込みも出来てしまうため、させたくない場合はNginx側で制御が必要。