Tweak search ordering to hopefully return newer results

This commit is contained in:
Ekaterina Vaartis 2021-08-17 00:30:14 +03:00
parent 38996f551a
commit 9beaebd97e
2 changed files with 23 additions and 5 deletions

View File

@ -39,7 +39,7 @@ defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
fragment("data->>'type' = 'Note'") and
fragment("LENGTH(data->>'source') > 0") and
fragment("data->'to' \\? ?", ^Pleroma.Constants.as_public()),
order_by: fragment("data->'published' DESC")
order_by: [desc: fragment("data->'published'")]
),
timeout: :infinity
)
@ -66,11 +66,15 @@ defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
end)
end)
|> Stream.each(fn objects ->
{:ok, _} =
{:ok, result} =
Pleroma.HTTP.post(
"#{endpoint}/indexes/objects/documents",
Jason.encode!(objects)
)
if not Map.has_key?(Jason.decode!(result.body), "updateId") do
IO.puts("Failed to index: #{result}")
end
end)
|> Stream.run()
end,
@ -83,6 +87,11 @@ defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
endpoint = Pleroma.Config.get([Pleroma.Search.Meilisearch, :url])
{:ok, _} = Pleroma.HTTP.request(:delete, "#{endpoint}/indexes/objects/documents", "", [], [])
{:ok, result} =
Pleroma.HTTP.request(:delete, "#{endpoint}/indexes/objects/documents", "", [], [])
if not Map.has_key?(Jason.decode!(result.body), "updateId") do
IO.puts("Failed to clear: #{result}")
end
end
end

View File

@ -32,7 +32,7 @@ defmodule Pleroma.Search.Meilisearch do
|> maybe_restrict_author(author)
|> maybe_restrict_blocked(user)
|> maybe_fetch(user, query)
|> order_by([activity], desc: activity.id)
|> order_by([object: obj], desc: obj.data["published"])
|> Pleroma.Repo.all()
rescue
_ -> maybe_fetch([], user, query)
@ -48,10 +48,19 @@ defmodule Pleroma.Search.Meilisearch do
endpoint = Pleroma.Config.get([Pleroma.Search.Meilisearch, :url])
{:ok, published, _} = DateTime.from_iso8601(data["published"])
{:ok, result} =
Pleroma.HTTP.post(
"#{endpoint}/indexes/objects/documents",
Jason.encode!([%{id: object.id, source: data["source"], ap: data["id"]}])
Jason.encode!([
%{
id: object.id,
source: data["source"],
ap: data["id"],
published: published |> DateTime.to_unix()
}
])
)
if not Map.has_key?(Jason.decode!(result.body), "updateId") do