Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c29e252
Showing
10 changed files
with
1,813 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| ((c-mode . ((c-file-style . "bsd") | ||
| (c-basic-offset . 4) | ||
| (tab-width . 4) | ||
| (indent-tabs-mode . t) | ||
| (show-trailing-whitespace . t)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| *.o | ||
| *.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| Portions Copyright (c) 2015, Kouhei Sutou | ||
| Portions Copyright (c) 2010, Itagaki Takahiro | ||
| Portions Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION | ||
| Portions Copyright (c) 1996-2010, The PostgreSQL Global Development Group | ||
| Portions Copyright (c) 1994, The Regents of the University of California | ||
|
|
||
| Permission to use, copy, modify, and distribute this software and | ||
| its documentation for any purpose, without fee, and without a written | ||
| agreement is hereby granted, provided that the above copyright notice and | ||
| this paragraph and the following two paragraphs appear in all copies. | ||
|
|
||
| IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE TO ANY PARTY FOR DIRECT, | ||
| INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST | ||
| PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN | ||
| IF THE COPYRIGHT HOLDERS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
|
||
| THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, | ||
| BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, | ||
| AND THE COPYRIGHT HOLDERS HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, | ||
| SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| MODULE_big = pgroonga | ||
| SRCS = pgroonga.c pgroonga_types.c | ||
| OBJS = $(SRCS:.c=.o) | ||
| EXTENSION = pgroonga | ||
| DATA = pgroonga--0.2.0.sql | ||
| PG_CPPFLAGS = $(shell pkg-config --cflags groonga) | ||
| SHLIB_LINK = $(shell pkg-config --libs groonga) | ||
| REGRESS = pgroonga update bench | ||
|
|
||
| PG_CONFIG = pg_config | ||
| PGXS := $(shell $(PG_CONFIG) --pgxs) | ||
| include $(PGXS) | ||
|
|
||
| .PHONY: subclean | ||
| clean: subclean | ||
|
|
||
| subclean: | ||
| rm -f pgroonga.sql.in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| # PGroonga(ぴーじーるんが) | ||
|
|
||
| ## 概要 | ||
|
|
||
| PGroongaはPostgreSQLからインデックスとして | ||
| [Groonga](http://groonga.org/ja/)を使うための拡張機能です。 | ||
|
|
||
| PostgreSQLは標準では日本語で全文検索できませんが、PGroongaを使うと日本 | ||
| 語で高速に全文検索できるようになります。日本語で全文検索機能を実現する | ||
| ための類似の拡張機能は次のものがあります。 | ||
|
|
||
| * [pg_trgm](https://www.postgresql.jp/document/9.3/html/pgtrgm.html) | ||
| * PostgreSQLに付属しているがデフォルトではインストールされない。 | ||
| * 日本語に対応させるにはソースコードを変更する必要がある。 | ||
| * [pg_bigm](http://pgbigm.sourceforge.jp/) | ||
| * ソースコードを変更しなくても日本語に対応している。 | ||
| * 正確な全文検索機能を使うには | ||
| [Recheck機能](http://pgbigm.sourceforge.jp/pg_bigm-1-1.html#enable_recheck) | ||
| を有効にする必要がある。 | ||
| * Recheck機能を有効にするとインデックスを使った検索をしてから、イ | ||
| ンデックスを使って見つかったレコードに対してシーケンシャルに検索 | ||
| をするのでインデックスを使った検索でのヒット件数が多くなると遅く | ||
| なりやすい。 | ||
| * Recheck機能を無効にするとキーワードが含まれていないレコードもヒッ | ||
| トする可能性がある。 | ||
|
|
||
| PGroongaはpg\_trgmのようにソースコードを変更しなくても日本語に対応して | ||
| います。 | ||
|
|
||
| PGroongaはpg\_bigmのようにRecheck機能を使わなくてもインデックスを使っ | ||
| た検索だけで正確な検索結果を返せます。そのため、インデックスを使った検 | ||
| 索でヒット件数が多くてもpg\_bigmほど遅くなりません。(仕組みの上は。要 | ||
| ベンチマーク。協力者募集。) | ||
|
|
||
| ただし、PGroongaは現時点ではWALに対応していないためクラッシュリカバリー | ||
| 機能やレプリケーションに対応していません。(pg\_trgmとpg\_bigmは対応し | ||
| ています。正確に言うとpg\_trgmとpg\_bigmが対応しているわけではなく、 | ||
| pg\_trgmとpg\_bigmが使っているGINやGiSTが対応しています。) | ||
|
|
||
| ## インストール | ||
|
|
||
| PostgreSQLをインストールします。 | ||
|
|
||
| [Groongaをインストール](http://groonga.org/ja/docs/install.html)します。 | ||
| パッケージでのインストールがオススメです。 | ||
|
|
||
| パッケージでインストールするときは次のパッケージをインストールしてください。 | ||
|
|
||
| * `groonga-devel`: CentOSの場合 | ||
| * `libgroonga-dev`: Debian GNU/Linux, Ubuntuの場合 | ||
|
|
||
| PGroongaをインストールします。 | ||
|
|
||
| % git clone https://github.com/pgroonga/pgroonga.git | ||
| % cd pgroonga | ||
| % make | ||
| % sudo make install | ||
|
|
||
| データベースに接続して`CREATE EXTENSION pgroonga`を実行します。 | ||
|
|
||
| % psql -d db | ||
| ... | ||
| db=# CREATE EXTENSION pgroonga; | ||
| CREATE EXTNESION | ||
|
|
||
| ## 使い方 | ||
|
|
||
| `text`型のカラムを作って`pgroonga`インデックスを張ります。 | ||
|
|
||
| ```sql | ||
| CREATE TABLE memos ( | ||
| id integer, | ||
| content text | ||
| ); | ||
|
|
||
| CREATE INDEX pgroonga_index ON memos USING pgroonga (content); | ||
| ``` | ||
|
|
||
| データを投入します。 | ||
|
|
||
| ```sql | ||
| INSERT INTO memos VALUES (1, 'PostgreSQLはリレーショナル・データベース管理システムです。'); | ||
| INSERT INTO memos VALUES (2, 'Groongaは日本語対応の高速な全文検索エンジンです。'); | ||
| INSERT INTO memos VALUES (3, 'PGroongaはインデックスとしてGroongaを使うためのPostgreSQLの拡張機能です。'); | ||
| ``` | ||
|
|
||
| 検索します。現時点ではシーケンシャルスキャンでの全文検索(インデックス | ||
| を使わない全文検索)には対応していないので、シーケンシャルスキャン機能 | ||
| を無効にします。(あるいはもっとたくさんのデータを投入します。) | ||
|
|
||
| ```sql | ||
| SET enable_seqscan = off; | ||
| ``` | ||
|
|
||
| 全文検索をするときは`%%`演算子を使います。 | ||
|
|
||
| ```sql | ||
| SELECT * FROM memos WHERE content %% '全文検索'; | ||
| -- id | content | ||
| -- ----+--------------------------------------------------- | ||
| -- 2 | Groongaは日本語対応の高速な全文検索エンジンです。 | ||
| -- (1 行) | ||
| ``` | ||
|
|
||
| ## アンインストール | ||
|
|
||
| 次のSQLでアンインストールできます。 | ||
|
|
||
| ```sql | ||
| DROP EXTENSION pgroonga CASCADE; | ||
| DELETE FROM pg_catalog.pg_am WHERE amname = 'pgroonga'; | ||
| ``` | ||
|
|
||
| `pg_catalog.pg_am`から手動でレコードを消さないといけないのはおかしい気 | ||
| がするので、何がおかしいか知っている人は教えてくれるとうれしいです。 | ||
|
|
||
| ## ライセンス | ||
|
|
||
| ライセンスはBSDライセンスやMITライセンスと類似の | ||
| [PostgreSQLライセンス](http://opensource.org/licenses/postgresql)です。 | ||
|
|
||
| 著作権保持者などの詳細は[COPYING](COPYING)ファイルを参照してください。 | ||
|
|
||
| ## TODO | ||
|
|
||
| * 実装 | ||
| * WAL対応 | ||
| * スコアー対応 | ||
| * クエリー構文対応(`キーワード1 OR キーワード2`のようなやつ) | ||
| * シーケンシャルスキャン対応(grn式を作って検索する?) | ||
| * COLLATE対応(今は必ずGroongaのNormalizerAutoを使っている) | ||
| * トークナイザーのカスタマイズ対応(今は必ずTokenBigramを使っている) | ||
| * ドキュメント | ||
| * 英語で書く | ||
| * サイトを用意する | ||
|
|
||
| ## 感謝 | ||
|
|
||
| * 板垣さん | ||
| * PGroongaは板垣さんが開発した[textsearch_groonga](http://textsearch-ja.projects.pgfoundry.org/textsearch_groonga.html)をベースにしています。 |
Oops, something went wrong.