refactor: add support for multilingual search using pgroonga extension

This commit is contained in:
divyam234 2024-07-11 19:16:25 +05:30
parent 41311d6af7
commit d8846d65e4
4 changed files with 11 additions and 3 deletions

View file

@ -99,7 +99,7 @@ services:
db:
condition: service_healthy
db:
image: postgres:15
image: groonga/pgroonga
container_name: teldrive_db
restart: always
environment:

View file

@ -15,7 +15,7 @@ services:
db:
condition: service_healthy
db:
image: postgres:15
image: groonga/pgroonga
container_name: teldrive_db
restart: always
environment:

View file

@ -0,0 +1,8 @@
-- +goose Up
-- +goose StatementBegin
CREATE EXTENSION IF NOT EXISTS pgroonga;
DROP INDEX IF EXISTS teldrive.name_search_idx;
DROP FUNCTION IF EXISTS teldrive.get_tsquery;
DROP FUNCTION IF EXISTS teldrive.get_tsvector;
CREATE INDEX name_search_idx ON teldrive.files USING pgroonga (REGEXP_REPLACE(name, '[.,-_]', ' ', 'g')) WITH (tokenizer = 'TokenNgram');
-- +goose StatementEnd

View file

@ -261,7 +261,7 @@ func (fs *FileService) ListFiles(userId int64, fquery *schemas.FileQuery) (*sche
}
if fquery.Query != "" {
query.Where("teldrive.get_tsquery(?) @@ teldrive.get_tsvector(name)", fquery.Query)
query.Where("name &@~ REGEXP_REPLACE(?, '[.,-_]', ' ', 'g')", fquery.Query)
}
if fquery.Category != "" {