From eef29910de8ec68ec7c4ae8950123af16f633e49 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sun, 17 Nov 2019 22:48:47 -0500 Subject: [PATCH] fix parser, add last page back to pagination --- .../pagination/_pagination.html.slime | 5 ++++- .../templates/topic/show.html.slime | 4 +++- lib/search/parser.ex | 18 ++++++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/philomena_web/templates/pagination/_pagination.html.slime b/lib/philomena_web/templates/pagination/_pagination.html.slime index 69234a6a..e805daa1 100644 --- a/lib/philomena_web/templates/pagination/_pagination.html.slime +++ b/lib/philomena_web/templates/pagination/_pagination.html.slime @@ -1,4 +1,5 @@ - params = assigns[:params] || [] +- last = assigns[:last] || false = if @page.total_pages > 1 do nav.pagination @@ -24,4 +25,6 @@ = if not last_page?(@page) do = link("Next ›", to: next_page_path(@page, @route, params)) - /= link("Last »", to: last_page_path(@page, @route, params)) \ No newline at end of file + + = if last do + = link("Last »", to: last_page_path(@page, @route, params)) \ No newline at end of file diff --git a/lib/philomena_web/templates/topic/show.html.slime b/lib/philomena_web/templates/topic/show.html.slime index 1faaa139..9990b50a 100644 --- a/lib/philomena_web/templates/topic/show.html.slime +++ b/lib/philomena_web/templates/topic/show.html.slime @@ -1,4 +1,6 @@ -- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @posts, route: fn p -> Routes.forum_topic_path(@conn, :show, @forum, @topic, p) end +elixir: + route = fn p -> Routes.forum_topic_path(@conn, :show, @forum, @topic, p) end + pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @posts, route: route, last: true h1 = @topic.title / Header section diff --git a/lib/search/parser.ex b/lib/search/parser.ex index 914219a6..7ba5c88d 100644 --- a/lib/search/parser.ex +++ b/lib/search/parser.ex @@ -192,29 +192,29 @@ defmodule Search.Parser do # Types which do not support ranges defp field_type(parser, [{LiteralParser, field_name}, range: :eq, literal: value]), - do: {:ok, {%{term: %{field(parser, field_name) => String.trim(value)}}, []}} + do: {:ok, {%{term: %{field(parser, field_name) => normalize_value(parser, value)}}, []}} defp field_type(parser, [{LiteralParser, field_name}, range: :eq, literal: value, fuzz: fuzz]), - do: {:ok, {%{fuzzy: %{field(parser, field_name) => %{value: String.trim(value), fuzziness: fuzz}}}, []}} + do: {:ok, {%{fuzzy: %{field(parser, field_name) => %{value: normalize_value(parser, value), fuzziness: fuzz}}}, []}} defp field_type(_parser, [{LiteralParser, _field_name}, range: :eq, wildcard: "*"]), do: {:ok, {%{match_all: %{}}, []}} defp field_type(parser, [{LiteralParser, field_name}, range: :eq, wildcard: value]), - do: {:ok, {%{wildcard: %{field(parser, field_name) => String.trim(value)}}, []}} + do: {:ok, {%{wildcard: %{field(parser, field_name) => normalize_value(parser, value)}}, []}} defp field_type(parser, [{NgramParser, field_name}, range: :eq, literal: value]), - do: {:ok, {%{match_phrase: %{field(parser, field_name) => String.trim(value)}}, []}} + do: {:ok, {%{match_phrase: %{field(parser, field_name) => normalize_value(parser, value)}}, []}} defp field_type(parser, [{NgramParser, field_name}, range: :eq, literal: value, fuzz: _fuzz]), - do: {:ok, {%{match_phrase: %{field(parser, field_name) => String.trim(value)}}, []}} + do: {:ok, {%{match_phrase: %{field(parser, field_name) => normalize_value(parser, value)}}, []}} defp field_type(_parser, [{NgramParser, _field_name}, range: :eq, wildcard: "*"]), do: {:ok, {%{match_all: %{}}, []}} defp field_type(parser, [{NgramParser, field_name}, range: :eq, wildcard: value]), - do: {:ok, {%{wildcard: %{field(parser, field_name) => String.trim(value)}}, []}} + do: {:ok, {%{wildcard: %{field(parser, field_name) => normalize_value(parser, value)}}, []}} defp field_type(parser, [{BoolParser, field_name}, range: :eq, bool: value]), @@ -265,4 +265,10 @@ defmodule Search.Parser do defp field(parser, field_name) do parser.aliases[field_name] || field_name end + + defp normalize_value(_parser, value) do + value + |> String.trim() + |> String.downcase() + end end \ No newline at end of file