WIP: indexing Chinese better

This commit is contained in:
vector090
2024-11-21 22:43:31 +08:00
parent dd0319a14d
commit 11ed418ce5
3 changed files with 5 additions and 4 deletions

View File

@@ -36,7 +36,7 @@ export class SearchService {
'createdAt',
'updatedAt',
sql<number>`ts_rank(tsv, to_tsquery(${searchQuery}))`.as('rank'),
sql<string>`ts_headline('english', text_content, to_tsquery(${searchQuery}), 'MinWords=9, MaxWords=10, MaxFragments=10')`.as(
sql<string>`ts_headline('chinese_zh', text_content, to_tsquery(${searchQuery}), 'MinWords=9, MaxWords=10, MaxFragments=10')`.as(
'highlight',
),
])

View File

@@ -4,8 +4,8 @@ export async function up(db: Kysely<any>): Promise<void> {
await sql`CREATE OR REPLACE FUNCTION pages_tsvector_trigger() RETURNS trigger AS $$
begin
new.tsv :=
setweight(to_tsvector('english', coalesce(new.title, '')), 'A') ||
setweight(to_tsvector('english', coalesce(new.text_content, '')), 'B');
setweight(to_tsvector('chinese_zh', coalesce(new.title, '')), 'A') ||
setweight(to_tsvector('chinese_zh', coalesce(new.text_content, '')), 'B');
return new;
end;
$$ LANGUAGE plpgsql;`.execute(db);

View File

@@ -18,7 +18,8 @@ services:
- docmost:/app/data/storage
db:
image: postgres:16-alpine
#image: postgres:16-alpine
image: abcfy2/zhparser:16-alpine
environment:
POSTGRES_DB: docmost
POSTGRES_USER: docmost