An xpb plugin for Pocketbase that allows for configurable sqlite full text search.
Provides an api endpoint to do full text searches.
xpb build --with github.com/pocketbuilds/fts@latest- Launch Pocketbase with plugin installed. You will notice it added a collection named
_fts. - Create and
_ftsrecord to enable full text search for the chosen collection. - Optionally, choose only certain fields to be used in the vocabulary using the
_fts.fieldsJSON array field of field names. If leftnullit will be populated with all collection fields. The id field is required, but will be automatically added if missing. - Optionally, change the tokenizer that will be used. The default tokenizer without changing the plugin config is
porter. - Use the fts api endpoint to access full text search capabilities:
GET /api/collections/{collection}/records/fts
# 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"// 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
);