fts

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2025 License: MIT Imports: 13 Imported by: 0

README

An xpb plugin for Pocketbase that allows for configurable sqlite full text search.

Provides an api endpoint to do full text searches.

Installation

  1. Install XPB.
  2. Use the builder:
xpb build --with github.com/pocketbuilds/fts@latest

Setup

  1. Launch Pocketbase with plugin installed. You will notice it added a collection named _fts.
  2. Create and _fts record to enable full text search for the chosen collection.
  3. Optionally, choose only certain fields to be used in the vocabulary using the _fts.fields JSON array field of field names. If left null it will be populated with all collection fields. The id field is required, but will be automatically added if missing.
  4. Optionally, change the tokenizer that will be used. The default tokenizer without changing the plugin config is porter.
  5. Use the fts api endpoint to access full text search capabilities:
GET /api/collections/{collection}/records/fts

Plugin Config

# pocketbuilds.toml

[fts]
# String default tokenizer to use for full text search
#  virtual tables. Can be changed individually in the
#  _fts record.
#  - default: "porter"
default_tokenizer = "porter"

Using the FTS Api Endpoint

JavaScript SDK
// One-Off use of endpoint<script type="module">
  const pb = new PocketBase("https://example.com")
  const collectionName = "news";

  const result = await pb.send(
    `/api/collections/${collectionName}/records/fts`,
    {
      query: {
        page: 1,
        perPage: 20,
        sort: '+created', // keep blank to use sort by fts rank
        filter: 'status = true && created > "2022-08-01 10:00:00"',
        // Use MATCH value
        // https://sqlite.org/fts5.html
        search: 'ghosts OR aliens',
      },
    },
  );
// Use beforeSend hook to always use fts route on record list
  const pb = new PocketBase("https://example.com")

  const re = new RegExp("/api/collections/[^/]+/records");
  pb.beforeSend = (url, options) => {
  	if (re.test(url) && options.method === "GET") {
  		url += "/fts";
  	}
  	return { url, options };
  }

  const result = await pb.collection("news").getList(1, 20, {    {
    page: 1,
    perPage: 20,
    sort: '+created', // keep blank to use sort by fts rank
    filter: 'status = true && created > "2022-08-01 10:00:00"',
    // Use MATCH value
    // https://sqlite.org/fts5.html
    search: 'ghosts OR aliens', // leave blank if fts is not enabled on collection
  );

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Plugin

type Plugin struct {
	DefaultTokenizer string `json:"default_tokenizer"`
}

func (*Plugin) Description

func (p *Plugin) Description() string

func (*Plugin) Init

func (p *Plugin) Init(app core.App) error

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) Version

func (p *Plugin) Version() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL