Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ DB_SCHEMA=docs
# OpenAI Embedding API Key
OPENAI_API_KEY=sk-

# Enable keyword search for TigerData docs
ENABLE_KEYWORD_SEARCH=
52 changes: 52 additions & 0 deletions migrations/1759876252954-add-tiger-textsearch-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'dotenv/config';
import { Client } from 'pg';

const schema = process.env.DB_SCHEMA || 'docs';

// We only want to run this if keyword search is enabled, where this expects
// that the user is using a Tiger Cloud backed database that has pg_textsearch
// available.
const keywordSearchEnabled = process.env.ENABLE_KEYWORD_SEARCH === 'true';

export const description = 'Add textsearch indexes to tiger docs content column';

export async function up() {
if (!keywordSearchEnabled) {
return;
}

const client = new Client();

try {
await client.connect();
await client.query(/* sql */ `
CREATE EXTENSION pg_textsearch;
`);
await client.query(/* sql */ `
CREATE INDEX IF NOT EXISTS ON ${schema}.timescaledb_chunks USING bm25(content) WITH (text_config='english');
`);
} catch (e) {
throw e;
} finally {
await client.end();
}
}

export async function down() {
if (!keywordSearchEnabled) {
return;
}

const client = new Client();

try {
await client.connect();
await client.query(/* sql */ `
DROP INDEX IF EXISTS ${schema}.timescale_chunks_content_idx;
`);
} catch (e) {
throw e;
} finally {
await client.end();
}
}