Groonga for PHP
PHP
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src no escape words in match (tentatively) Sep 3, 2014
test fix mock for input Sep 3, 2014
.gitignore add gitignore Aug 24, 2014
.travis.yml fix .travis.yml Sep 2, 2014
LICENSE Initial commit Aug 20, 2014
README.md add requirements Sep 3, 2014
composer.json fix stability in composer.json Sep 2, 2014

README.md

php-phroonga

Build Status Coverage Status

Groonga client for php

namespace

dooaki\Phroonga

requirements

php 5.5.0 or latter

installation

write composer.json and run composer install.

{
   "require": {
      "dooaki/phroonga": "dev-master"
   }
}

usage

GroongaEntity trait を use したクラスが entity として、 groonga の一つのテーブルを司ります。

table 定義は _schema という static method で self::Table, self::Column 等を用いて行います。

use dooaki\Phroonga\Groonga;
use dooaki\Phroonga\GroongaEntity;

class User
{
    use GroongaEntity;

    public static function _schema()
    {
        self::Table(
            'Users',
            [
                'flags' => 'TABLE_HASH_KEY',
                'key_type' => 'ShortText'
            ]
        );
        self::Column('age', 'Int32');
    }
}

$grn = new Groonga('http://localhost:10043');
$grn->activate();   // associate GroongaEntity and Groonga

$grn->create();  // table_create and column_create

$u1 = new User();
$u1->_key = 'alice';
$u1->age  = 18;
$u1->save();    // load

$u2 = new User();
$u2->_key = 'bob';
$u2->age  = 20;
$u2->save();    // load

$alice = User::select()->find('alice'); // select
echo "{$alice->_key} is {$alice->age} years old.", PHP_EOL;

上記のコードは groonga のコンソールで以下のコマンドを実行することと同じです

> table_create --name User --flags TABLE_HASH_KEY --key_type ShortText
> column_create --table User --name age --type Int32
> load --table User
[{"_key":"alice","age":18},{"_key":"bob","age":20}]
> select --table User --query "_key:alice"