mirror of
https://github.com/tgdrive/teldrive.git
synced 2024-12-30 20:01:47 +08:00
refactor: add support for multilingual search using pgroonga extension
This commit is contained in:
parent
41311d6af7
commit
d8846d65e4
4 changed files with 11 additions and 3 deletions
|
@ -99,7 +99,7 @@ services:
|
|||
db:
|
||||
condition: service_healthy
|
||||
db:
|
||||
image: postgres:15
|
||||
image: groonga/pgroonga
|
||||
container_name: teldrive_db
|
||||
restart: always
|
||||
environment:
|
||||
|
|
|
@ -15,7 +15,7 @@ services:
|
|||
db:
|
||||
condition: service_healthy
|
||||
db:
|
||||
image: postgres:15
|
||||
image: groonga/pgroonga
|
||||
container_name: teldrive_db
|
||||
restart: always
|
||||
environment:
|
||||
|
|
8
internal/database/migrations/20240711163538_search.sql
Normal file
8
internal/database/migrations/20240711163538_search.sql
Normal 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
|
|
@ -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 != "" {
|
||||
|
|
Loading…
Reference in a new issue