2022-01-20 12:48:16 +00:00
|
|
|
# Akkoma: A lightweight social networking server
|
|
|
|
# Copyright © 2022-2022 Akkoma Authors <https://git.ihatebeinga.live/IHBAGang/akkoma/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-12-14 13:53:46 +00:00
|
|
|
defmodule Pleroma.Search.Elasticsearch.Parsers.Activity do
|
|
|
|
defp to_es(term) when is_binary(term) do
|
|
|
|
%{
|
|
|
|
match: %{
|
|
|
|
content: %{
|
|
|
|
query: term,
|
|
|
|
operator: "AND"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
defp to_es({:quoted, term}), do: to_es(term)
|
|
|
|
|
|
|
|
defp to_es({:filter, ["hashtag", query]}) do
|
|
|
|
%{
|
|
|
|
term: %{
|
|
|
|
hashtags: %{
|
|
|
|
value: query
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
defp to_es({:filter, [field, query]}) do
|
|
|
|
%{
|
|
|
|
term: %{
|
|
|
|
field => %{
|
|
|
|
value: query
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def parse(q) do
|
2022-07-28 12:02:36 +00:00
|
|
|
[
|
|
|
|
%{
|
|
|
|
exists: %{
|
|
|
|
field: "content"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
] ++
|
|
|
|
Enum.map(q, &to_es/1)
|
2021-12-14 13:53:46 +00:00
|
|
|
end
|
|
|
|
end
|