Skip to content

Commit

Permalink
unaccent + fix trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
fontanierh committed Aug 31, 2023
1 parent 7a3b10f commit eee28d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { sequelize_conn } from "@connectors/lib/models";
async function main() {
await sequelize_conn.query(`
UPDATE "notion_pages"
SET "titleSearchVector" = to_tsvector('english', coalesce("title", ''));
SET "titleSearchVector" = to_tsvector('english', unaccent(coalesce("title", '')));
`);
await sequelize_conn.query(`
UPDATE "notion_databases"
SET "titleSearchVector" = to_tsvector('english', coalesce("title", ''));
SET "titleSearchVector" = to_tsvector('english', unaccent(coalesce("title", '')));
`);
}

Expand Down
6 changes: 4 additions & 2 deletions connectors/src/admin/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ async function main(): Promise<void> {
await GoogleDriveFiles.sync({ alter: true });
await GoogleDriveSyncToken.sync({ alter: true });
await GoogleDriveWebhook.sync({ alter: true });
await GoogleDriveBFSDedup.sync({ alter: true });

// enable the `unaccent` extension
await sequelize_conn.query("CREATE EXTENSION IF NOT EXISTS unaccent;");

await addSearchVectorTrigger(
sequelize_conn,
Expand Down Expand Up @@ -78,7 +80,7 @@ async function addSearchVectorTrigger(
CREATE OR REPLACE FUNCTION ${functionName}() RETURNS trigger AS $$
begin
if TG_OP = 'INSERT' OR new.title IS DISTINCT FROM old.title then
new.titleSearchVector := to_tsvector('english', coalesce(new.title, ''));
new."titleSearchVector" := to_tsvector('english', unaccent(coalesce(new.title, '')));
end if;
return new;
end
Expand Down

0 comments on commit eee28d5

Please sign in to comment.