Tweak search ordering to hopefully return newer results
This commit is contained in:
parent
7b3701e6b9
commit
c3a04166a0
2 changed files with 23 additions and 5 deletions
|
@ -39,7 +39,7 @@ defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
|
||||||
fragment("data->>'type' = 'Note'") and
|
fragment("data->>'type' = 'Note'") and
|
||||||
fragment("LENGTH(data->>'source') > 0") and
|
fragment("LENGTH(data->>'source') > 0") and
|
||||||
fragment("data->'to' \\? ?", ^Pleroma.Constants.as_public()),
|
fragment("data->'to' \\? ?", ^Pleroma.Constants.as_public()),
|
||||||
order_by: fragment("data->'published' DESC")
|
order_by: [desc: fragment("data->'published'")]
|
||||||
),
|
),
|
||||||
timeout: :infinity
|
timeout: :infinity
|
||||||
)
|
)
|
||||||
|
@ -66,11 +66,15 @@ defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|> Stream.each(fn objects ->
|
|> Stream.each(fn objects ->
|
||||||
{:ok, _} =
|
{:ok, result} =
|
||||||
Pleroma.HTTP.post(
|
Pleroma.HTTP.post(
|
||||||
"#{endpoint}/indexes/objects/documents",
|
"#{endpoint}/indexes/objects/documents",
|
||||||
Jason.encode!(objects)
|
Jason.encode!(objects)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not Map.has_key?(Jason.decode!(result.body), "updateId") do
|
||||||
|
IO.puts("Failed to index: #{result}")
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|> Stream.run()
|
|> Stream.run()
|
||||||
end,
|
end,
|
||||||
|
@ -83,6 +87,11 @@ defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
|
||||||
|
|
||||||
endpoint = Pleroma.Config.get([Pleroma.Search.Meilisearch, :url])
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,7 +32,7 @@ defmodule Pleroma.Search.Meilisearch do
|
||||||
|> maybe_restrict_author(author)
|
|> maybe_restrict_author(author)
|
||||||
|> maybe_restrict_blocked(user)
|
|> maybe_restrict_blocked(user)
|
||||||
|> maybe_fetch(user, query)
|
|> maybe_fetch(user, query)
|
||||||
|> order_by([activity], desc: activity.id)
|
|> order_by([object: obj], desc: obj.data["published"])
|
||||||
|> Pleroma.Repo.all()
|
|> Pleroma.Repo.all()
|
||||||
rescue
|
rescue
|
||||||
_ -> maybe_fetch([], user, query)
|
_ -> maybe_fetch([], user, query)
|
||||||
|
@ -48,10 +48,19 @@ defmodule Pleroma.Search.Meilisearch do
|
||||||
|
|
||||||
endpoint = Pleroma.Config.get([Pleroma.Search.Meilisearch, :url])
|
endpoint = Pleroma.Config.get([Pleroma.Search.Meilisearch, :url])
|
||||||
|
|
||||||
|
{:ok, published, _} = DateTime.from_iso8601(data["published"])
|
||||||
|
|
||||||
{:ok, result} =
|
{:ok, result} =
|
||||||
Pleroma.HTTP.post(
|
Pleroma.HTTP.post(
|
||||||
"#{endpoint}/indexes/objects/documents",
|
"#{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
|
if not Map.has_key?(Jason.decode!(result.body), "updateId") do
|
||||||
|
|
Loading…
Reference in a new issue