diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts index 524a305ffaa..9ee08b53777 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts @@ -388,7 +388,7 @@ export const database = { url: undefined, items: [ { name: 'Overview', url: '/guides/database/extensions', items: [] }, -{ + { name: 'HypoPG: Hypothetical indexes', url: '/guides/database/extensions/hypopg', items: [], @@ -399,6 +399,11 @@ export const database = { items: [], }, { name: 'http: RESTful Client', url: '/guides/database/extensions/http', items: [] }, + { + name: 'PGRoonga: Multilingual Full Text Search', + url: '/guides/database/extensions/pgroonga', + items: [], + }, { name: 'pg_cron: Job Scheduling', url: '/guides/database/extensions/pgcron', diff --git a/apps/docs/pages/guides/database/extensions/pgroonga.mdx b/apps/docs/pages/guides/database/extensions/pgroonga.mdx new file mode 100644 index 00000000000..0b8b480bf08 --- /dev/null +++ b/apps/docs/pages/guides/database/extensions/pgroonga.mdx @@ -0,0 +1,113 @@ +import Layout from '~/layouts/DefaultGuideLayout' + +export const meta = { + id: 'pgroonga', + title: 'PGRoonga: Multilingual Full Text Search', + description: 'Full Text Search for multiple languages in PostgreSQL', +} + +`PGroonga` is a PostgreSQL extension adding a full text search indexing method based on [Groonga](https://groonga.org). While native PostgreSQL supports full text indexing, it is limited to alphabet and digit based languages. `PGroonga` offers a wider range of character support making it viable for a superset of languages supported by PostgreSQL including Japanese, Chinese, etc. + +## Usage + +### Enable the extension + + + + +1. Go to the [Database](https://app.supabase.com/project/_/database/tables) page in the Dashboard. +2. Click on **Extensions** in the sidebar. +3. Search for "pgroonga" and enable the extension. + + + + +```sql +-- Enable the "pgroonga" extension +create extension pgroonga with schema extensions; + +-- Disable the "pgroonga" extension +drop extension if exists pgroonga; +``` + +Even though the SQL code is `create extension`, this is the equivalent of "enabling the extension". +To disable an extension you can call `drop extension`. + +It's good practice to create the extension within a separate schema (like `extensions`) to keep your database clean. + + + + +### Creating a Full Text Search Index + +Given a table with a `text` column + +```sql +create table memos ( + id serial primary key, + content text +); +``` + +We can index the column for full text search with a `pgroonga` index + +```sql +create index ix_memos_content ON memos USING pgroonga(content); +``` + +To test the full text index, we'll add some data. + +```sql +insert into memos(content) +values + ('PostgreSQL is a relational database management system.'), + ('Groonga is a fast full text search engine that supports all languages.'), + ('PGroonga is a PostgreSQL extension that uses Groonga as index.'), + ('There is groonga command.'); +``` + +The PostgreSQL query planner is smart enough to know that, for extremely small tables, its faster to scan the whole table rather than loading an index. To force the index to be used, we can disable sequential scans + +```sql +-- For testing only. Don't do this in production +set enable_seqscan = off; +``` + +Now if we run an explain plan on a query filtering on `memos.content`, + +```sql +explain +select + * +from + memos +where + content like '%engine%'; + + QUERY PLAN +----------------------------------------------------------------------------- +Index Scan using ix_memos_content on memos (cost=0.00..1.11 rows=1 width=36) + Index Cond: (content ~~ '%engine%'::text) +(2 rows) +``` + +The pgroonga index is used to retrive the result set + +```markdown +| id | content | +| -- | ------------------------------------------------------------------------ | +| 2 | 'Groonga is a fast full text search engine that supports all languages.' | +``` + +## Resources + +- Official [`PGroonga` documentation](https://pgroonga.github.io/tutorial/) + +export const Page = ({ children }) => + +export default Page