mirror of
https://github.com/minetest/contentdb.git
synced 2024-11-08 08:33:45 +01:00
Add migration to fix fulltext search
This commit is contained in:
parent
c2fbf7603a
commit
f6ce676e7e
54
migrations/versions/3710e5fbbe87_.py
Normal file
54
migrations/versions/3710e5fbbe87_.py
Normal file
@ -0,0 +1,54 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 3710e5fbbe87
|
||||
Revises: f6ef5f35abca
|
||||
Create Date: 2022-01-27 18:50:11.705061
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '3710e5fbbe87'
|
||||
down_revision = 'f6ef5f35abca'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
command = """
|
||||
CREATE OR REPLACE FUNCTION parse_websearch(config regconfig, search_query text)
|
||||
RETURNS tsquery AS $$
|
||||
SELECT
|
||||
string_agg(
|
||||
(
|
||||
CASE
|
||||
WHEN position('''' IN words.word) > 0 THEN CONCAT(words.word, ':*')
|
||||
ELSE words.word
|
||||
END
|
||||
),
|
||||
' '
|
||||
)::tsquery
|
||||
FROM (
|
||||
SELECT trim(
|
||||
regexp_split_to_table(
|
||||
websearch_to_tsquery(config, lower(search_query))::text,
|
||||
' '
|
||||
)
|
||||
) AS word
|
||||
) AS words
|
||||
$$ LANGUAGE SQL IMMUTABLE;
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION parse_websearch(search_query text)
|
||||
RETURNS tsquery AS $$
|
||||
SELECT parse_websearch('pg_catalog.simple', search_query);
|
||||
$$ LANGUAGE SQL IMMUTABLE;"""
|
||||
|
||||
op.execute(command)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.execute('DROP FUNCTION public.parse_websearch(regconfig, text);')
|
||||
op.execute('DROP FUNCTION public.parse_websearch(text);')
|
Loading…
Reference in New Issue
Block a user