mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-17 11:04:22 +01:00
format
This commit is contained in:
parent
1a44260211
commit
fdf53cb495
3 changed files with 24 additions and 13 deletions
|
@ -25,7 +25,13 @@ defmodule Philomena.Elasticsearch do
|
||||||
def index_document(doc) do
|
def index_document(doc) do
|
||||||
data = unquote(definition).as_json(doc)
|
data = unquote(definition).as_json(doc)
|
||||||
|
|
||||||
Elastix.Document.index(unquote(elastic_url), unquote(index_name), [unquote(doc_type)], data.id, data)
|
Elastix.Document.index(
|
||||||
|
unquote(elastic_url),
|
||||||
|
unquote(index_name),
|
||||||
|
[unquote(doc_type)],
|
||||||
|
data.id,
|
||||||
|
data
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def reindex(ecto_query, batch_size \\ 1000) do
|
def reindex(ecto_query, batch_size \\ 1000) do
|
||||||
|
|
|
@ -8,6 +8,7 @@ defmodule PhilomenaWeb.ImageController do
|
||||||
|
|
||||||
def index(conn, _params) do
|
def index(conn, _params) do
|
||||||
query = conn.assigns[:compiled_filter]
|
query = conn.assigns[:compiled_filter]
|
||||||
|
|
||||||
images =
|
images =
|
||||||
Image.search_records(
|
Image.search_records(
|
||||||
%{
|
%{
|
||||||
|
|
|
@ -4,7 +4,7 @@ defmodule PhilomenaWeb.SearchController do
|
||||||
alias Philomena.Images.{Image, Query}
|
alias Philomena.Images.{Image, Query}
|
||||||
alias Pow.Plug
|
alias Pow.Plug
|
||||||
|
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
plug ImageFilter
|
plug ImageFilter
|
||||||
|
|
||||||
|
@ -13,19 +13,23 @@ defmodule PhilomenaWeb.SearchController do
|
||||||
user = conn |> Plug.current_user()
|
user = conn |> Plug.current_user()
|
||||||
|
|
||||||
with {:ok, query} <- Query.compile(user, params["q"]) do
|
with {:ok, query} <- Query.compile(user, params["q"]) do
|
||||||
images =
|
images =
|
||||||
Image.search_records(
|
Image.search_records(
|
||||||
%{
|
%{
|
||||||
query: %{bool: %{must: query, must_not: filter}},
|
query: %{bool: %{must: query, must_not: filter}},
|
||||||
sort: %{created_at: :desc}
|
sort: %{created_at: :desc}
|
||||||
},
|
},
|
||||||
Image |> preload(:tags)
|
Image |> preload(:tags)
|
||||||
)
|
)
|
||||||
|
|
||||||
render(conn, PhilomenaWeb.ImageView, "index.html", images: images, search_query: params["q"])
|
render(conn, PhilomenaWeb.ImageView, "index.html", images: images, search_query: params["q"])
|
||||||
else
|
else
|
||||||
{:error, msg} ->
|
{:error, msg} ->
|
||||||
render(conn, PhilomenaWeb.ImageView, "index.html", images: [], error: msg, search_query: params["q"])
|
render(conn, PhilomenaWeb.ImageView, "index.html",
|
||||||
end
|
images: [],
|
||||||
|
error: msg,
|
||||||
|
search_query: params["q"]
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue