extra cool
[akkoma] / lib / pleroma / search / elasticsearch / user_paser.ex
1 defmodule Pleroma.Search.Elasticsearch.Parsers.User do
2 defp to_es(term) when is_binary(term) do
3 %{
4 bool: %{
5 minimum_should_match: 1,
6 should: [
7 %{
8 match: %{
9 bio: %{
10 query: term,
11 operator: "AND"
12 }
13 }
14 },
15 %{
16 term: %{
17 nickname: %{
18 value: term
19 }
20 }
21 },
22 %{
23 match: %{
24 display_name: %{
25 query: term,
26 operator: "AND"
27 }
28 }
29 }
30 ]
31 }
32 }
33 end
34
35 defp to_es({:quoted, term}), do: to_es(term)
36
37 defp to_es({:filter, ["user", query]}) do
38 %{
39 term: %{
40 nickname: %{
41 value: query
42 }
43 }
44 }
45 end
46
47 defp to_es({:filter, _}), do: nil
48
49 def parse(q) do
50 Enum.map(q, &to_es/1)
51 |> Enum.filter(fn x -> x != nil end)
52 end
53 end