Tweak search ordering to hopefully return newer results

This commit is contained in:
Ekaterina Vaartis 2021-08-17 00:30:14 +03:00 committed by FloatingGhost
parent 7b3701e6b9
commit c3a04166a0
2 changed files with 23 additions and 5 deletions

View file

@ -39,7 +39,7 @@ def run(["index"]) 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 @@ def run(["index"]) 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 @@ def run(["clear"]) 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 @@ def search(user, query, options \\ []) 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 @@ def add_to_index(activity) 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