Use compile with opts for filter queries

This commit is contained in:
Liam 2024-07-13 14:42:37 -04:00
parent fc2ab285c7
commit e9eb638d79
3 changed files with 5 additions and 4 deletions

View file

@ -33,7 +33,8 @@ defmodule Philomena.Filters.Query do
|> Parser.parse(query_string, context) |> Parser.parse(query_string, context)
end end
def compile(user, query_string) do def compile(query_string, opts \\ []) do
user = Keyword.get(opts, :user)
query_string = query_string || "" query_string = query_string || ""
case user do case user do

View file

@ -9,7 +9,7 @@ defmodule PhilomenaWeb.Api.Json.Search.FilterController do
def index(conn, params) do def index(conn, params) do
user = conn.assigns.current_user user = conn.assigns.current_user
case Query.compile(user, params["q"] || "") do case Query.compile(params["q"], user: user) do
{:ok, query} -> {:ok, query} ->
filters = filters =
Filter Filter

View file

@ -13,8 +13,8 @@ defmodule PhilomenaWeb.FilterController do
def index(conn, %{"fq" => fq}) do def index(conn, %{"fq" => fq}) do
user = conn.assigns.current_user user = conn.assigns.current_user
user fq
|> Query.compile(fq) |> Query.compile(user: user)
|> render_index(conn, user) |> render_index(conn, user)
end end