diff --git a/index/posts.mk b/index/posts.mk index 1f0b1b00..fda8e8ee 100644 --- a/index/posts.mk +++ b/index/posts.mk @@ -24,6 +24,7 @@ metadata: post_search_json 'referrer', p.referrer, 'fingerprint', p.fingerprint, 'topic_position', p.topic_position, + 'forum', f.short_name, 'forum_id', t.forum_id, 'user_id', p.user_id, 'anonymous', p.anonymous, diff --git a/lib/philomena/posts/elasticsearch_index.ex b/lib/philomena/posts/elasticsearch_index.ex index 0a165ed7..827d819c 100644 --- a/lib/philomena/posts/elasticsearch_index.ex +++ b/lib/philomena/posts/elasticsearch_index.ex @@ -27,6 +27,7 @@ defmodule Philomena.Posts.ElasticsearchIndex do subject: %{type: "text", analyzer: "snowball"}, author: %{type: "keyword"}, topic_position: %{type: "integer"}, + forum: %{type: "keyword"}, forum_id: %{type: "keyword"}, topic_id: %{type: "keyword"}, user_id: %{type: "keyword"}, @@ -54,6 +55,7 @@ defmodule Philomena.Posts.ElasticsearchIndex do referrer: post.referrer, fingerprint: post.fingerprint, topic_position: post.topic_position, + forum: post.topic.forum.short_name, forum_id: post.topic.forum_id, user_id: post.user_id, anonymous: post.anonymous, diff --git a/lib/philomena/posts/query.ex b/lib/philomena/posts/query.ex index ce9e3353..463216b9 100644 --- a/lib/philomena/posts/query.ex +++ b/lib/philomena/posts/query.ex @@ -52,7 +52,7 @@ defmodule Philomena.Posts.Query do [ int_fields: ~W(id topic_position), date_fields: ~W(created_at updated_at), - literal_fields: ~W(forum_id topic_id), + literal_fields: ~W(forum forum_id topic_id), ngram_fields: ~W(body subject), custom_fields: ~W(author user_id), default_field: {"body", :ngram}, @@ -76,7 +76,7 @@ defmodule Philomena.Posts.Query do fields = user_fields() Keyword.merge(fields, - literal_fields: ~W(forum_id topic_id user_id author fingerprint), + literal_fields: fields[:literal_fields] ++ ~W(user_id author fingerprint), ip_fields: ~W(ip), bool_fields: ~W(anonymous deleted), custom_fields: fields[:custom_fields] -- ~W(author user_id), diff --git a/lib/philomena_web/plugs/load_topic_plug.ex b/lib/philomena_web/plugs/load_topic_plug.ex index 7e238535..918ab9cc 100644 --- a/lib/philomena_web/plugs/load_topic_plug.ex +++ b/lib/philomena_web/plugs/load_topic_plug.ex @@ -15,7 +15,7 @@ defmodule PhilomenaWeb.LoadTopicPlug do Topic |> where(forum_id: ^forum.id, slug: ^to_string(conn.params[param])) - |> preload([:user, :forum, :deleted_by, poll: :options]) + |> preload([:user, :forum, :deleted_by, :locked_by, poll: :options]) |> Repo.one() |> maybe_hide_topic(conn, show_hidden) end diff --git a/lib/philomena_web/templates/forum/index.html.slime b/lib/philomena_web/templates/forum/index.html.slime index a82ed50e..3eaa978d 100644 --- a/lib/philomena_web/templates/forum/index.html.slime +++ b/lib/philomena_web/templates/forum/index.html.slime @@ -1,7 +1,9 @@ h1 Discussion Forums .block .block__header - /= icon_link 'Search Posts', 'fa fa-fw fa-search', posts_path + a href=Routes.post_path(@conn, :index) + i.fa.fa-fw.fa-search> + ' Search Posts span.block__header__item => @topic_count ' topics diff --git a/lib/philomena_web/templates/forum/show.html.slime b/lib/philomena_web/templates/forum/show.html.slime index fccee9d9..23a6c676 100644 --- a/lib/philomena_web/templates/forum/show.html.slime +++ b/lib/philomena_web/templates/forum/show.html.slime @@ -10,7 +10,9 @@ h1 = @forum.name i.fa.fa-fw.fa-edit> ' New Topic - /= icon_link 'Search Posts', 'fa fa-fw fa-search', posts_path(forum_id: @forum.id) + a href=Routes.post_path(@conn, :index, pq: "forum:#{@forum.short_name}") + i.fa.fa-fw.fa-search> + ' Search Posts span.spacing-left => @forum.topic_count ' topics diff --git a/lib/philomena_web/templates/post/index.html.slime b/lib/philomena_web/templates/post/index.html.slime index c35fab40..507fbd69 100644 --- a/lib/philomena_web/templates/post/index.html.slime +++ b/lib/philomena_web/templates/post/index.html.slime @@ -18,7 +18,18 @@ h2 Search Results - pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @posts, route: route, params: [pq: @conn.params["pq"]], conn: @conn = for {body, post} <- @posts, post.topic.hidden_from_users == false do - = render PhilomenaWeb.PostView, "_post.html", body: body, post: post, conn: @conn + div + h3 + =<> link post.topic.forum.name, to: Routes.forum_path(@conn, :show, post.topic.forum) + | » + =<> link post.topic.title, to: Routes.forum_topic_path(@conn, :show, post.topic.forum, post.topic) + | » + - post_link = Routes.forum_topic_path(@conn, :show, post.topic.forum, post.topic, post_id: post.id) <> "#post_#{post.id}" + = if post.topic_position == 0 do + =<> link "Topic Opener", to: post_link + - else + =<> link "Post #{post.topic_position}", to: post_link + = render PhilomenaWeb.PostView, "_post.html", body: body, post: post, conn: @conn .block .block__header.block__header--light.page__header @@ -134,3 +145,10 @@ table.table td Matches posts with the specified user_id. Anonymous users will never match this term. td code = link "user_id:211190", to: Routes.post_path(@conn, :index, pq: "user_id:211190") + tr + td + code forum + td Literal + td Matches the short name for the forum this post belongs to. + td + code = link "forum:meta", to: Routes.post_path(@conn, :index, pq: "forum:meta") diff --git a/lib/philomena_web/templates/topic/show.html.slime b/lib/philomena_web/templates/topic/show.html.slime index 07d2e80a..6fd87d54 100644 --- a/lib/philomena_web/templates/topic/show.html.slime +++ b/lib/philomena_web/templates/topic/show.html.slime @@ -81,6 +81,13 @@ h1 = @topic.title ' Lock reason: em = @topic.lock_reason + = if can?(@conn, :hide, @topic) and not is_nil(@topic.locked_by) do + p + ' Locked by: + em + strong + = link(@topic.locked_by.name, to: Routes.profile_path(@conn, :show, @topic.locked_by)) + / Post form = cond do - @conn.assigns.current_ban -> diff --git a/priv/repo/migrations/20210427022351_add_index_posts_on_topic_id_and_topic_position.exs b/priv/repo/migrations/20210427022351_add_index_posts_on_topic_id_and_topic_position.exs new file mode 100644 index 00000000..89c70ae5 --- /dev/null +++ b/priv/repo/migrations/20210427022351_add_index_posts_on_topic_id_and_topic_position.exs @@ -0,0 +1,21 @@ +defmodule Philomena.Repo.Migrations.AddIndexPostsOnTopicIdAndTopicPosition do + use Ecto.Migration + + def up do + execute("drop index index_posts_on_topic_id_and_topic_position;"); + execute( + """ + with mismatched_ranks as (select id,rank from (select id, topic_position, (rank() over (partition by topic_id order by created_at,id asc))-1 as rank from posts) s where s.topic_position <> s.rank) + update posts set topic_position=mismatched_ranks.rank + from mismatched_ranks + where posts.id=mismatched_ranks.id; + """); + execute("create unique index index_posts_on_topic_id_and_topic_position on posts (topic_id, topic_position);"); + end + + def down do + execute("drop index index_posts_on_topic_id_and_topic_position;"); + execute("create index index_posts_on_topic_id_and_topic_position on public.posts (topic_id, topic_position);"); + end + +end diff --git a/priv/repo/structure.sql b/priv/repo/structure.sql index 980129d3..3337ab7d 100644 --- a/priv/repo/structure.sql +++ b/priv/repo/structure.sql @@ -2,8 +2,8 @@ -- PostgreSQL database dump -- --- Dumped from database version 13.1 (Debian 13.1-1.pgdg100+1) --- Dumped by pg_dump version 13.1 (Debian 13.1-1.pgdg100+1) +-- Dumped from database version 13.2 +-- Dumped by pg_dump version 13.2 SET statement_timeout = 0; SET lock_timeout = 0; @@ -3503,7 +3503,7 @@ CREATE INDEX index_posts_on_topic_id_and_created_at ON public.posts USING btree -- Name: index_posts_on_topic_id_and_topic_position; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX index_posts_on_topic_id_and_topic_position ON public.posts USING btree (topic_id, topic_position); +CREATE UNIQUE INDEX index_posts_on_topic_id_and_topic_position ON public.posts USING btree (topic_id, topic_position); -- @@ -4843,3 +4843,4 @@ INSERT INTO public."schema_migrations" (version) VALUES (20200905214139); INSERT INTO public."schema_migrations" (version) VALUES (20201124224116); INSERT INTO public."schema_migrations" (version) VALUES (20210121200815); INSERT INTO public."schema_migrations" (version) VALUES (20210301012137); +INSERT INTO public."schema_migrations" (version) VALUES (20210427022351);