mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-17 11:04:22 +01:00
move search, textile, date parser to app namespace
This commit is contained in:
parent
8e9d6285e4
commit
a1b8ed9d33
29 changed files with 43 additions and 43 deletions
|
@ -1,5 +1,5 @@
|
||||||
defmodule Philomena.Comments.Query do
|
defmodule Philomena.Comments.Query do
|
||||||
alias Search.Parser
|
alias Philomena.Search.Parser
|
||||||
|
|
||||||
defp user_id_transform(_ctx, data) do
|
defp user_id_transform(_ctx, data) do
|
||||||
case Integer.parse(data) do
|
case Integer.parse(data) do
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
defmodule Philomena.Galleries.Query do
|
defmodule Philomena.Galleries.Query do
|
||||||
alias Search.Parser
|
alias Philomena.Search.Parser
|
||||||
|
|
||||||
defp fields do
|
defp fields do
|
||||||
[
|
[
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
defmodule Philomena.Images.Query do
|
defmodule Philomena.Images.Query do
|
||||||
alias Search.Parser
|
alias Philomena.Search.Parser
|
||||||
alias Philomena.Repo
|
alias Philomena.Repo
|
||||||
|
|
||||||
defp gallery_id_transform(_ctx, value),
|
defp gallery_id_transform(_ctx, value),
|
||||||
|
@ -53,7 +53,7 @@ defmodule Philomena.Images.Query do
|
||||||
do: {:error, "Unknown `my' value."}
|
do: {:error, "Unknown `my' value."}
|
||||||
|
|
||||||
defp invalid_filter_guard(ctx, search_string) do
|
defp invalid_filter_guard(ctx, search_string) do
|
||||||
case parse(user_fields(), ctx, Search.String.normalize(search_string)) do
|
case parse(user_fields(), ctx, Philomena.Search.String.normalize(search_string)) do
|
||||||
{:ok, query} -> query
|
{:ok, query} -> query
|
||||||
_error -> %{match_all: %{}}
|
_error -> %{match_all: %{}}
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
defmodule Philomena.Posts.Query do
|
defmodule Philomena.Posts.Query do
|
||||||
alias Search.Parser
|
alias Philomena.Search.Parser
|
||||||
|
|
||||||
defp user_id_transform(_ctx, data) do
|
defp user_id_transform(_ctx, data) do
|
||||||
case Integer.parse(data) do
|
case Integer.parse(data) do
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule RelativeDate.Parser do
|
defmodule Philomena.RelativeDate do
|
||||||
import NimbleParsec
|
import NimbleParsec
|
||||||
|
|
||||||
number_words =
|
number_words =
|
|
@ -1,5 +1,5 @@
|
||||||
defmodule Philomena.Reports.Query do
|
defmodule Philomena.Reports.Query do
|
||||||
alias Search.Parser
|
alias Philomena.Search.Parser
|
||||||
|
|
||||||
defp fields do
|
defp fields do
|
||||||
[
|
[
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
defmodule Philomena.Schema.Search do
|
defmodule Philomena.Schema.Search do
|
||||||
alias Philomena.Images.Query
|
alias Philomena.Images.Query
|
||||||
alias Search.String
|
alias Philomena.Search.String
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
def validate_search(changeset, field, user, watched \\ false) do
|
def validate_search(changeset, field, user, watched \\ false) do
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
defmodule Philomena.Schema.Time do
|
defmodule Philomena.Schema.Time do
|
||||||
alias RelativeDate.Parser
|
alias Philomena.RelativeDate
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
def assign_time(changeset, field, target_field) do
|
def assign_time(changeset, field, target_field) do
|
||||||
changeset
|
changeset
|
||||||
|> get_field(field)
|
|> get_field(field)
|
||||||
|> Parser.parse()
|
|> RelativeDate.parse()
|
||||||
|> case do
|
|> case do
|
||||||
{:ok, time} ->
|
{:ok, time} ->
|
||||||
put_change(changeset, target_field, time)
|
put_change(changeset, target_field, time)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Search.BoolParser do
|
defmodule Philomena.Search.BoolParser do
|
||||||
import NimbleParsec
|
import NimbleParsec
|
||||||
|
|
||||||
space =
|
space =
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Search.DateParser do
|
defmodule Philomena.Search.DateParser do
|
||||||
import NimbleParsec
|
import NimbleParsec
|
||||||
|
|
||||||
defp build_datetime(naive, tz_off, tz_hour, tz_minute) do
|
defp build_datetime(naive, tz_off, tz_hour, tz_minute) do
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Search.Evaluator do
|
defmodule Philomena.Search.Evaluator do
|
||||||
# TODO: rethink the necessity of this module.
|
# TODO: rethink the necessity of this module.
|
||||||
# Can we do this in elasticsearch instead?
|
# Can we do this in elasticsearch instead?
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
defmodule Search.FloatParser do
|
defmodule Philomena.Search.FloatParser do
|
||||||
import NimbleParsec
|
import NimbleParsec
|
||||||
|
|
||||||
defp to_number(input), do: Search.Helpers.to_number(input)
|
defp to_number(input), do: Philomena.Search.Helpers.to_number(input)
|
||||||
defp range(input), do: Search.Helpers.range(input)
|
defp range(input), do: Philomena.Search.Helpers.range(input)
|
||||||
|
|
||||||
space =
|
space =
|
||||||
choice([string(" "), string("\t"), string("\n"), string("\r"), string("\v"), string("\f")])
|
choice([string(" "), string("\t"), string("\n"), string("\r"), string("\v"), string("\f")])
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Search.Helpers do
|
defmodule Philomena.Search.Helpers do
|
||||||
# Apparently, it's too hard for the standard library to to parse a number
|
# Apparently, it's too hard for the standard library to to parse a number
|
||||||
# as a float if it doesn't contain a decimal point. WTF
|
# as a float if it doesn't contain a decimal point. WTF
|
||||||
def to_number(term) do
|
def to_number(term) do
|
|
@ -1,8 +1,8 @@
|
||||||
defmodule Search.IntParser do
|
defmodule Philomena.Search.IntParser do
|
||||||
import NimbleParsec
|
import NimbleParsec
|
||||||
|
|
||||||
defp to_int(input), do: Search.Helpers.to_int(input)
|
defp to_int(input), do: Philomena.Search.Helpers.to_int(input)
|
||||||
defp range(input), do: Search.Helpers.range(input)
|
defp range(input), do: Philomena.Search.Helpers.range(input)
|
||||||
|
|
||||||
space =
|
space =
|
||||||
choice([string(" "), string("\t"), string("\n"), string("\r"), string("\v"), string("\f")])
|
choice([string(" "), string("\t"), string("\n"), string("\r"), string("\v"), string("\f")])
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Search.IpParser do
|
defmodule Philomena.Search.IpParser do
|
||||||
import NimbleParsec
|
import NimbleParsec
|
||||||
|
|
||||||
ipv4_octet =
|
ipv4_octet =
|
|
@ -1,7 +1,7 @@
|
||||||
defmodule Search.Lexer do
|
defmodule Philomena.Search.Lexer do
|
||||||
import NimbleParsec
|
import NimbleParsec
|
||||||
|
|
||||||
defp to_number(input), do: Search.Helpers.to_number(input)
|
defp to_number(input), do: Philomena.Search.Helpers.to_number(input)
|
||||||
|
|
||||||
space =
|
space =
|
||||||
choice([string(" "), string("\t"), string("\n"), string("\r"), string("\v"), string("\f")])
|
choice([string(" "), string("\t"), string("\n"), string("\r"), string("\v"), string("\f")])
|
|
@ -1,7 +1,7 @@
|
||||||
defmodule Search.LiteralParser do
|
defmodule Philomena.Search.LiteralParser do
|
||||||
import NimbleParsec
|
import NimbleParsec
|
||||||
|
|
||||||
defp to_number(input), do: Search.Helpers.to_number(input)
|
defp to_number(input), do: Philomena.Search.Helpers.to_number(input)
|
||||||
|
|
||||||
float =
|
float =
|
||||||
ascii_string([?0..?9], min: 1)
|
ascii_string([?0..?9], min: 1)
|
|
@ -1,5 +1,5 @@
|
||||||
defmodule Search.NgramParser do
|
defmodule Philomena.Search.NgramParser do
|
||||||
alias Search.LiteralParser
|
alias Philomena.Search.LiteralParser
|
||||||
|
|
||||||
# Dummy stub. Used for convenient parser implementation.
|
# Dummy stub. Used for convenient parser implementation.
|
||||||
def parse(input), do: LiteralParser.parse(input)
|
def parse(input), do: LiteralParser.parse(input)
|
|
@ -1,5 +1,5 @@
|
||||||
defmodule Search.Parser do
|
defmodule Philomena.Search.Parser do
|
||||||
alias Search.{
|
alias Philomena.Search.{
|
||||||
BoolParser,
|
BoolParser,
|
||||||
DateParser,
|
DateParser,
|
||||||
FloatParser,
|
FloatParser,
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Search.String do
|
defmodule Philomena.Search.String do
|
||||||
def normalize(nil) do
|
def normalize(nil) do
|
||||||
""
|
""
|
||||||
end
|
end
|
|
@ -1,6 +1,6 @@
|
||||||
defmodule Search.TermRangeParser do
|
defmodule Philomena.Search.TermRangeParser do
|
||||||
alias Search.LiteralParser
|
alias Philomena.Search.LiteralParser
|
||||||
alias Search.NgramParser
|
alias Philomena.Search.NgramParser
|
||||||
|
|
||||||
# Unfortunately, we can't use NimbleParsec here. It requires
|
# Unfortunately, we can't use NimbleParsec here. It requires
|
||||||
# the compiler, and we're not in a macro environment.
|
# the compiler, and we're not in a macro environment.
|
|
@ -1,5 +1,5 @@
|
||||||
defmodule Philomena.Tags.Query do
|
defmodule Philomena.Tags.Query do
|
||||||
alias Search.Parser
|
alias Philomena.Search.Parser
|
||||||
|
|
||||||
defp fields do
|
defp fields do
|
||||||
[
|
[
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Textile.Lexer do
|
defmodule Philomena.Textile.Lexer do
|
||||||
import NimbleParsec
|
import NimbleParsec
|
||||||
|
|
||||||
space = utf8_char('\f \r\t\u00a0\u1680\u180e\u202f\u205f\u3000' ++ Enum.to_list(0x2000..0x200A))
|
space = utf8_char('\f \r\t\u00a0\u1680\u180e\u202f\u205f\u3000' ++ Enum.to_list(0x2000..0x200A))
|
|
@ -1,5 +1,5 @@
|
||||||
defmodule Textile.Parser do
|
defmodule Philomena.Textile.Parser do
|
||||||
alias Textile.Lexer
|
alias Philomena.Textile.Lexer
|
||||||
alias Phoenix.HTML
|
alias Phoenix.HTML
|
||||||
|
|
||||||
def parse(parser, input) do
|
def parse(parser, input) do
|
|
@ -1,6 +1,6 @@
|
||||||
defmodule PhilomenaWeb.ImageFilterPlug do
|
defmodule PhilomenaWeb.ImageFilterPlug do
|
||||||
import Plug.Conn
|
import Plug.Conn
|
||||||
import Search.String
|
import Philomena.Search.String
|
||||||
|
|
||||||
alias Philomena.Images.Query
|
alias Philomena.Images.Query
|
||||||
alias Pow.Plug
|
alias Pow.Plug
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
defmodule PhilomenaWeb.TextileRenderer do
|
defmodule PhilomenaWeb.TextileRenderer do
|
||||||
alias Textile.Parser
|
alias Philomena.Textile.Parser
|
||||||
alias Philomena.Images.Image
|
alias Philomena.Images.Image
|
||||||
alias Philomena.Repo
|
alias Philomena.Repo
|
||||||
import Phoenix.HTML
|
import Phoenix.HTML
|
||||||
|
|
|
@ -259,6 +259,6 @@ defmodule PhilomenaWeb.ImageView do
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Search.Evaluator.hits?(doc, query)
|
Philomena.Search.Evaluator.hits?(doc, query)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,9 +40,9 @@ defmodule PhilomenaWeb.LayoutView do
|
||||||
data = [
|
data = [
|
||||||
filter_id: filter.id,
|
filter_id: filter.id,
|
||||||
hidden_tag_list: Jason.encode!(filter.hidden_tag_ids),
|
hidden_tag_list: Jason.encode!(filter.hidden_tag_ids),
|
||||||
hidden_filter: Search.String.normalize(filter.hidden_complex_str || ""),
|
hidden_filter: Philomena.Search.String.normalize(filter.hidden_complex_str || ""),
|
||||||
spoilered_tag_list: Jason.encode!(filter.spoilered_tag_ids),
|
spoilered_tag_list: Jason.encode!(filter.spoilered_tag_ids),
|
||||||
spoilered_filter: Search.String.normalize(filter.spoilered_complex_str || ""),
|
spoilered_filter: Philomena.Search.String.normalize(filter.spoilered_complex_str || ""),
|
||||||
user_id: if(user, do: user.id, else: nil),
|
user_id: if(user, do: user.id, else: nil),
|
||||||
user_name: if(user, do: user.name, else: nil),
|
user_name: if(user, do: user.name, else: nil),
|
||||||
user_slug: if(user, do: user.slug, else: nil),
|
user_slug: if(user, do: user.slug, else: nil),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
defmodule PhilomenaWeb.PostView do
|
defmodule PhilomenaWeb.PostView do
|
||||||
alias Philomena.Attribution
|
alias Philomena.Attribution
|
||||||
alias Textile.Parser
|
alias Philomena.Textile.Parser
|
||||||
|
|
||||||
use PhilomenaWeb, :view
|
use PhilomenaWeb, :view
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue