diff --git a/README.md b/README.md index 270714e..e10cb52 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ services: db: condition: service_healthy db: - image: postgres:15 + image: groonga/pgroonga container_name: teldrive_db restart: always environment: diff --git a/docker-compose.postgres.yml b/docker-compose.postgres.yml index 3b673fe..8980e04 100644 --- a/docker-compose.postgres.yml +++ b/docker-compose.postgres.yml @@ -15,7 +15,7 @@ services: db: condition: service_healthy db: - image: postgres:15 + image: groonga/pgroonga container_name: teldrive_db restart: always environment: diff --git a/internal/database/migrations/20240711163538_search.sql b/internal/database/migrations/20240711163538_search.sql new file mode 100644 index 0000000..ae05e86 --- /dev/null +++ b/internal/database/migrations/20240711163538_search.sql @@ -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 \ No newline at end of file diff --git a/pkg/services/file.go b/pkg/services/file.go index 133e81d..6ef7826 100644 --- a/pkg/services/file.go +++ b/pkg/services/file.go @@ -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 != "" {