Tag Archives: drilldown

Compare Groonga with SQL


I had to use groonga. The reason is simple, there is data only in groonga.

groonga も含め 全文検索エンジンを使うのは初めてだったので、 公式ドキュメントを見ながら探っていきました。 データベースで使用する SQL と groonga のクエリを比較してみると次のようになりました。 もともと別物なので参考程度に見ていただければと思います。

SELECT

We use SELECT to get some data from groonga, also from database. But there’s considerable difference between the structure of data between groonga and database. As for groonga, sql command is like the following.

Simple comparison is as follows.

Database groonga
表示カラム (listed after select) ––output_columns
Table from ––table
Search Condition where ––filter, ––query, ––match_column, ––scorer
Order order by ––sortby
Offset offset ––offset
Limit limit ––limit
Group group by ––drilldown (drilldown したときの件数指定などは下の説明を参照)
Logical Operator and, or &&, ||

Supplemental Explanation

––output_columns

検索結果に表示するカラムを指定する。カンマで区切ることにより、複数カラムを指定できる。

––query

全文検索を行う。

title カラムについて 文字列 “this” の全文検索を行う。

––match_columns, ––query

検索結果に含めるカラムを指定する。複数指定もできる。

––query と一緒に使い、 title カラムについて 文字列 “this” の全文検索を行う。

––filter

Specify query condition. Likewise javascript, we can use operator “==”, “<=“, “>”, etc. AND, OR should be represented as &&, ||.

––drilldown

バージョン4.0.1 の資料を見るかぎり、 drilldown に指定したそれぞれのカラムについてグループ化した結果が表示される。 column_1 と column_2 を指定していれば、 column_1 だけでグループ化した結果と、 column_2 でグループ化した結果が続けて表示される。 ORDER BY column_1, column_2 のようなことはできない。

drilldown の結果に対する件数指定(オフセットなど)は下記のように、 通常の ––sortby, ––offset, ––limit の頭に drilldown をつけて指定する。 drilldown した結果だけがほしければ、 ––limit0 を指定して出てくる通常カラムを制限する。

Specific Column

Column Name Description
_id ID column whose is generated by groonga automatically in query.
_key The column which contains primary key.
_score Virtual column in query result. (Likewise ROWNUM in Oracle DB.) It has higher number if the record matches to query condition more.
_nsubrecs The column which contains query drilldown result number when drilldown is used. It’s like COUNT function in SELECT COUNT(1) FROM ….