From e7048471e067466a31cedee308219ed6fc0bc1cd Mon Sep 17 00:00:00 2001 From: Sergey Suprunenko Date: Tue, 31 Mar 2020 20:49:54 +0200 Subject: [PATCH] Write both summary and content searches in the same `where` to keep other conditions --- lib/pleroma/activity/search.ex | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/pleroma/activity/search.ex b/lib/pleroma/activity/search.ex index aea371102..fd3b5ee8f 100644 --- a/lib/pleroma/activity/search.ex +++ b/lib/pleroma/activity/search.ex @@ -54,16 +54,15 @@ defmodule Pleroma.Activity.Search do from([a, o] in q, where: fragment( - "(to_tsvector('english', ?->>'summary') @@ plainto_tsquery('english', ?))", + "to_tsvector('english', ?->>'summary') @@ plainto_tsquery('english', ?)", o.data, ^search_query - ), - or_where: - fragment( - "(to_tsvector('english', ?->>'content') @@ plainto_tsquery('english', ?))", - o.data, - ^search_query - ) + ) or + fragment( + "to_tsvector('english', ?->>'content') @@ plainto_tsquery('english', ?)", + o.data, + ^search_query + ) ) end @@ -72,15 +71,14 @@ defmodule Pleroma.Activity.Search do where: fragment( "? @@ plainto_tsquery('english', ?)", - o.fts_content, - ^search_query - ), - or_where: - fragment( - "? @@ plainto_tsquery('english', ?)", o.fts_summary, ^search_query - ), + ) or + fragment( + "? @@ plainto_tsquery('english', ?)", + o.fts_content, + ^search_query + ), order_by: [fragment("? <=> now()::date", o.inserted_at)] ) end