Support for setting PGroonga indexing options
This commit is contained in:
parent
3859c4bbcf
commit
2634723958
2 changed files with 40 additions and 34 deletions
|
@ -331,12 +331,10 @@ def run(["set_text_search_config", tsconfig]) do
|
||||||
shell_info("Error: #{inspect(msg, pretty: true)}")
|
shell_info("Error: #{inspect(msg, pretty: true)}")
|
||||||
else
|
else
|
||||||
rum_enabled = Pleroma.Config.get([:database, :rum_enabled])
|
rum_enabled = Pleroma.Config.get([:database, :rum_enabled])
|
||||||
pgroonga_enabled = Pleroma.Config.get([:database, :pgroonga_enabled])
|
shell_info("Recreate index, RUM: #{rum_enabled}")
|
||||||
shell_info("Recreate index, RUM: #{rum_enabled}, PGroonga: #{pgroonga_enabled}")
|
|
||||||
|
|
||||||
# Note SQL below needs to be kept up-to-date with latest GIN or RUM index definition in future
|
# Note SQL below needs to be kept up-to-date with latest GIN or RUM index definition in future
|
||||||
cond do
|
if rum_enabled do
|
||||||
rum_enabled ->
|
|
||||||
Ecto.Adapters.SQL.query!(
|
Ecto.Adapters.SQL.query!(
|
||||||
Pleroma.Repo,
|
Pleroma.Repo,
|
||||||
"CREATE OR REPLACE FUNCTION objects_fts_update() RETURNS trigger AS $$ BEGIN
|
"CREATE OR REPLACE FUNCTION objects_fts_update() RETURNS trigger AS $$ BEGIN
|
||||||
|
@ -350,18 +348,7 @@ def run(["set_text_search_config", tsconfig]) do
|
||||||
|
|
||||||
shell_info("Refresh RUM index")
|
shell_info("Refresh RUM index")
|
||||||
Ecto.Adapters.SQL.query!(Pleroma.Repo, "UPDATE objects SET updated_at = NOW();")
|
Ecto.Adapters.SQL.query!(Pleroma.Repo, "UPDATE objects SET updated_at = NOW();")
|
||||||
|
else
|
||||||
pgroonga_enabled ->
|
|
||||||
Ecto.Adapters.SQL.query!(Pleroma.Repo, "DROP INDEX IF EXISTS object_content_pgroonga;")
|
|
||||||
|
|
||||||
Ecto.Adapters.SQL.query!(
|
|
||||||
Pleroma.Repo,
|
|
||||||
"CREATE INDEX object_content_pgroonga ON objects USING pgroonga ((data->'content')) WITH (tokenizer='TokenMecab');",
|
|
||||||
[],
|
|
||||||
timeout: :infinity
|
|
||||||
)
|
|
||||||
|
|
||||||
true ->
|
|
||||||
Ecto.Adapters.SQL.query!(Pleroma.Repo, "DROP INDEX IF EXISTS objects_fts;")
|
Ecto.Adapters.SQL.query!(Pleroma.Repo, "DROP INDEX IF EXISTS objects_fts;")
|
||||||
|
|
||||||
Ecto.Adapters.SQL.query!(
|
Ecto.Adapters.SQL.query!(
|
||||||
|
@ -376,6 +363,27 @@ def run(["set_text_search_config", tsconfig]) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def run(["set_pgroonga_options", pg_options]) do
|
||||||
|
start_pleroma()
|
||||||
|
pgroonga_enabled = Pleroma.Config.get([:database, :pgroonga_enabled])
|
||||||
|
|
||||||
|
if pgroonga_enabled do
|
||||||
|
shell_info("Recreate index with options #{pg_options}")
|
||||||
|
Ecto.Adapters.SQL.query!(Pleroma.Repo, "DROP INDEX IF EXISTS object_content_pgroonga;")
|
||||||
|
|
||||||
|
Ecto.Adapters.SQL.query!(
|
||||||
|
Pleroma.Repo,
|
||||||
|
"CREATE INDEX object_content_pgroonga ON objects USING pgroonga ((data->'content')) WITH (#{pg_options});",
|
||||||
|
[],
|
||||||
|
timeout: :infinity
|
||||||
|
)
|
||||||
|
|
||||||
|
shell_info('Done.')
|
||||||
|
else
|
||||||
|
shell_info('PGroonga is not enabled.')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Rolls back a specific migration (leaving subsequent migrations applied).
|
# Rolls back a specific migration (leaving subsequent migrations applied).
|
||||||
# WARNING: imposes a risk of unrecoverable data loss — proceed at your own responsibility.
|
# WARNING: imposes a risk of unrecoverable data loss — proceed at your own responsibility.
|
||||||
# Based on https://stackoverflow.com/a/53825840
|
# Based on https://stackoverflow.com/a/53825840
|
||||||
|
|
|
@ -11,9 +11,7 @@ def up do
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
execute(
|
execute("CREATE INDEX object_content_pgroonga ON objects USING pgroonga ((data->'content'))")
|
||||||
"CREATE INDEX object_content_pgroonga ON objects USING pgroonga ((data->'content')) WITH (tokenizer='TokenMecab')"
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def down do
|
def down do
|
||||||
|
|
Loading…
Reference in a new issue