LoginSignup
1
0

More than 5 years have passed since last update.

PHPからGroongaを利用する - Groongaクラス

Last updated at Posted at 2014-11-30

Groongaクラス

PHP bindings for Groonga.

サンプル micro_blog.php

Groonga {
  /* メソッド */
  public void __construct(string str[[, integer port], integer flags])
  public void __destruct(void)
  public mixed command(string query[[, int assoc], integer flags])
  public GCommand command(string command)
  public array status(void)
  public array tableList(void)
  public integer cacheLimit(integer max)
  public array dump(void)
  public GTable table(string name)
}

コンストラクタ Groonga::__construct

基礎クラスの生成

$gdb = new Groonga('./db/test.db');

引数

名前 概要
str string DBパスかホスト名
[port] integer ポート番号
[flags] integer フラグ

戻り値

なし

  $gdb = new Groonga('./db/test.db');

  $result = $gdb->status();
  print_r($result);

結果

Array
(
    [alloc_count] => 142
    [starttime] => 1417368970
    [uptime] => 0
    [version] => 4.0.7
    [n_queries] => 0
    [cache_hit_rate] => 0
    [command_version] => 1
    [default_command_version] => 1
    [max_command_version] => 2
)

クエリ送信 Groonga::query

Groongaへクエリを送信する

引数

名前 概要
query string クエリ内容
assoc integer 結果フォーマット
flags integer フラグ

戻り値

クエリ結果

$gdb = new Groonga('./db/test.db');

$result = $gdb->query('/d/status.json');
echo $result;

結果

{"alloc_count":142,"starttime":1417494042,"uptime":0,"version":"4.0.7","n_queries":0,"cache_hit_rate":0.0,"command_version":1,"default_command_version":1,"max_command_version":2}

組み込みコマンド生成 Groonga::command

組み込みコマンド生成

$gdb->command('status');

引数

名前 概要
command string コマンド名

戻り値

コマンドオブジェクト

  $gdb = new Groonga('./db/test.db');

  $command = $gdb->command('status');
  print_r($command);

結果

GCommand Object
(
)

ステータス Groonga::status

ステータスの取得

$gdb->status();

引数

なし

戻り値

配列

  $gdb = new Groonga('./db/test.db');

  $result = $gdb->status();
  print_r($result);

結果

Array
(
    [alloc_count] => 142
    [starttime] => 1417368970
    [uptime] => 0
    [version] => 4.0.7
    [n_queries] => 0
    [cache_hit_rate] => 0
    [command_version] => 1
    [default_command_version] => 1
    [max_command_version] => 2
)

テーブル一覧 Groonga::tableList

テーブル一覧の取得

$gdb->tableList();

引数

なし

戻り値

配列

  $gdb = new Groonga('./db/test.db');

  $result = $gdb->tableList();
  print_r($result);

結果

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [0] => id
                    [1] => UInt32
                )

            [1] => Array
                (
                    [0] => name
                    [1] => ShortText
                )

            [2] => Array
                (
                    [0] => path
                    [1] => ShortText
                )

            [3] => Array
                (
                    [0] => flags
                    [1] => ShortText
                )

            [4] => Array
                (
                    [0] => domain
                    [1] => ShortText
                )

            [5] => Array
                (
                    [0] => range
                    [1] => ShortText
                )

            [6] => Array
                (
                    [0] => default_tokenizer
                    [1] => ShortText
                )

            [7] => Array
                (
                    [0] => normalizer
                    [1] => ShortText
                )

        )

    [1] => Array
        (
            [0] => 256
            [1] => Sample
            [2] => ./db/test.db.0000100
            [3] => TABLE_HASH_KEY|PERSISTENT
            [4] => ShortText
            [5] =>
            [6] =>
            [7] =>
        )

)

キャッシュ設定 Groonga::cacheLimit

キャッシュ上限の設定、取得

$gdb->cacheLimit();

引数

名前 概要
max integer キャッシュ上限

戻り値

なし

  $gdb = new Groonga('./db/test.db');

  $result = $gdb->cacheLimit();
  echo $result."\n";

  $result = $gdb->cacheLimit(50);
  echo $result."\n";

結果

100
50

ダンプ Groonga::dump

ダンプ内容の取得

$gdb->cacheLimit();

引数

名前 概要
max integer キャッシュ上限

戻り値

なし

  $gdb = new Groonga('./db/test.db');

  $result = $gdb->cacheLimit();
  echo $result."\n";

  $result = $gdb->cacheLimit(50);
  echo $result."\n";

結果

100
50

テーブル Groonga::table

テーブルオブジェクトの取得

$gdb->table('Sample');

引数

名前 概要
name string テーブル名

戻り値

テーブルオブジェクト

  $gdb = new Groonga('./db/test.db');

  $table = $gdb->table('Users');
  print_r($table);

結果

GTable Object
(
)

PHPからGroongaを利用する-Groongaクラス
PHPからGroongaを利用する-GCommandクラス
PHPからGroongaを利用する-GTableクラス
PHPからGroongaを利用する-GColumnクラス
PHPからGroongaを利用する-GLoadクラス
PHPからGroongaを利用する-GDeleteクラス
PHPからGroongaを利用する-GSelectクラス

PHPからGroongaを利用する-PHPバインディング

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0