Write both summary and content searches in the same where to keep other conditions

This commit is contained in:
Sergey Suprunenko 2020-03-31 20:49:54 +02:00
parent 6650c69aaf
commit e7048471e0
No known key found for this signature in database
GPG Key ID: 5DCA7D1BE3914F9C

View File

@ -54,16 +54,15 @@ defmodule Pleroma.Activity.Search do
from([a, o] in q, from([a, o] in q,
where: where:
fragment( fragment(
"(to_tsvector('english', ?->>'summary') @@ plainto_tsquery('english', ?))", "to_tsvector('english', ?->>'summary') @@ plainto_tsquery('english', ?)",
o.data, o.data,
^search_query ^search_query
), ) or
or_where: fragment(
fragment( "to_tsvector('english', ?->>'content') @@ plainto_tsquery('english', ?)",
"(to_tsvector('english', ?->>'content') @@ plainto_tsquery('english', ?))", o.data,
o.data, ^search_query
^search_query )
)
) )
end end
@ -72,15 +71,14 @@ defmodule Pleroma.Activity.Search do
where: where:
fragment( fragment(
"? @@ plainto_tsquery('english', ?)", "? @@ plainto_tsquery('english', ?)",
o.fts_content,
^search_query
),
or_where:
fragment(
"? @@ plainto_tsquery('english', ?)",
o.fts_summary, o.fts_summary,
^search_query ^search_query
), ) or
fragment(
"? @@ plainto_tsquery('english', ?)",
o.fts_content,
^search_query
),
order_by: [fragment("? <=> now()::date", o.inserted_at)] order_by: [fragment("? <=> now()::date", o.inserted_at)]
) )
end end