graphile-pg-textsearch-plugin enables auto-discovered BM25 ranked full-text search for PostGraphile v5 schemas using pg_textsearch.
npm install graphile-pg-textsearch-plugin- Auto-discovery: Finds all text columns with BM25 indexes automatically — zero configuration
- Condition fields:
bm25<Column>condition inputs accepting{ query, threshold? }for BM25 ranked search - Score fields:
bm25<Column>Scorecomputed fields returning BM25 relevance scores (negative values, more negative = more relevant) - OrderBy:
BM25_<COLUMN>_SCORE_ASC/DESCenum values for sorting by relevance - Works with PostGraphile v5 preset/plugin pipeline
import { Bm25SearchPreset } from 'graphile-pg-textsearch-plugin';
const preset = {
extends: [
// ... your other presets
Bm25SearchPreset(),
],
};import { Bm25CodecPlugin, Bm25SearchPlugin } from 'graphile-pg-textsearch-plugin';
const preset = {
plugins: [
Bm25CodecPlugin,
Bm25SearchPlugin(),
],
};query SearchArticles($search: Bm25SearchInput!) {
articles(condition: { bm25Body: $search }) {
nodes {
id
title
body
bm25BodyScore
}
}
}Variables:
{
"search": {
"query": "postgres full text search",
"threshold": -0.5
}
}query SearchArticlesSorted($search: Bm25SearchInput!) {
articles(
condition: { bm25Body: $search }
orderBy: BM25_BODY_SCORE_ASC
) {
nodes {
id
title
bm25BodyScore
}
}
}- PostgreSQL with pg_textsearch extension installed
- PostGraphile v5 (rc.5+)
- A BM25 index on the text column(s) you want to search:
CREATE INDEX articles_body_idx ON articles USING bm25(body)
WITH (text_config='english');# requires constructiveio/postgres-plus:18 Docker image with pg_textsearch pre-installed
pnpm --filter graphile-pg-textsearch-plugin test