Skip cache when /objects or /activities is authenticated
[akkoma] / lib / pleroma / search / elasticsearch / user_paser.ex
1 # Akkoma: A lightweight social networking server
2 # Copyright © 2022-2022 Akkoma Authors <https://git.ihatebeinga.live/IHBAGang/akkoma/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Search.Elasticsearch.Parsers.User do
6 defp to_es(term) when is_binary(term) do
7 %{
8 bool: %{
9 minimum_should_match: 1,
10 should: [
11 %{
12 match: %{
13 bio: %{
14 query: term,
15 operator: "AND"
16 }
17 }
18 },
19 %{
20 term: %{
21 nickname: %{
22 value: term
23 }
24 }
25 },
26 %{
27 match: %{
28 display_name: %{
29 query: term,
30 operator: "AND"
31 }
32 }
33 }
34 ]
35 }
36 }
37 end
38
39 defp to_es({:quoted, term}), do: to_es(term)
40
41 defp to_es({:filter, ["user", query]}) do
42 %{
43 term: %{
44 nickname: %{
45 value: query
46 }
47 }
48 }
49 end
50
51 defp to_es({:filter, _}), do: nil
52
53 def parse(q) do
54 Enum.map(q, &to_es/1)
55 |> Enum.filter(fn x -> x != nil end)
56 end
57 end