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,33 +54,31 @@ 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
defp query_with(q, :rum, search_query) do
from([a, o] in q,
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