forked from YokaiRick/akkoma
Add logging to milisiearch index and make it use desc(id)
This commit is contained in:
parent
e961cf2689
commit
41db5c8653
1 changed files with 21 additions and 5 deletions
|
@ -3,8 +3,9 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
|
||||
import Mix.Pleroma
|
||||
require Logger
|
||||
|
||||
import Mix.Pleroma
|
||||
import Ecto.Query
|
||||
|
||||
def run(["index"]) do
|
||||
|
@ -12,12 +13,25 @@ def run(["index"]) do
|
|||
|
||||
endpoint = Pleroma.Config.get([Pleroma.Search.Meilisearch, :url])
|
||||
|
||||
{:ok, _} =
|
||||
Pleroma.HTTP.post(
|
||||
"#{endpoint}/indexes/objects/settings/ranking-rules",
|
||||
Jason.encode!([
|
||||
"desc(id)",
|
||||
"typo",
|
||||
"words",
|
||||
"proximity",
|
||||
"attribute",
|
||||
"wordsPosition",
|
||||
"exactness"
|
||||
])
|
||||
)
|
||||
|
||||
Pleroma.Repo.chunk_stream(
|
||||
from(Pleroma.Object,
|
||||
limit: 200,
|
||||
where: fragment("data->>'type' = 'Note'") and fragment("LENGTH(data->>'source') > 0")
|
||||
),
|
||||
100,
|
||||
200,
|
||||
:batches
|
||||
)
|
||||
|> Stream.map(fn objects ->
|
||||
|
@ -26,12 +40,14 @@ def run(["index"]) do
|
|||
%{id: object.id, source: data["source"], ap: data["id"]}
|
||||
end)
|
||||
end)
|
||||
|> Stream.each(fn activities ->
|
||||
|> Stream.each(fn objects ->
|
||||
{:ok, _} =
|
||||
Pleroma.HTTP.post(
|
||||
"#{endpoint}/indexes/objects/documents",
|
||||
Jason.encode!(activities)
|
||||
Jason.encode!(objects)
|
||||
)
|
||||
|
||||
IO.puts("Indexed #{Enum.count(objects)} entries")
|
||||
end)
|
||||
|> Stream.run()
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue