-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tipline search by explainers (#1971)
## Description Explainers can match incoming user queries to the tipline and be returned as search results, like fact-checks. This feature has two main parts: indexing and retrieving. Steps below: **Refactoring** - [x] Implement a class `TiplineSearchResult` class that abstracts the logic for fact-check reports and explainers **Indexing** - [x] When an explainer is saved, index in Alegre each paragraph as a separate document - [x] Before doing so, make sure that paragraphs that don't exist anymore are deleted from the index - [x] Since on the UI explainers are updated on blur, try to avoid race conditions by making sure that an indexing job is superseded by a more recent one - [x] Implement automated tests for this **Retrieving** - [x] In tipline queries, search for explainers if no published fact-checks are found - [x] In tipline queries, return explainers if matched media has no published fact-check - [x] Once explainers are returned by Alegre, get the items associated with them in order for the tipline request to be associated with the right media cluster - [x] There is no concept of published explainer or report for now, so, just format the search result with the title, summary and link for the explainer - [x] Search for explainers by keyword - [x] Search for explainers by similarity (by calling Alegre) - [x] Implement automated tests for this Reference: CV2-4664. ## How has this been tested? Automated tests implemented for new features. Things to test manually: - [x] Search by fact-checks that return both text report and visual card report - [x] Search that matches media clusters and return fact-checks - [x] Search that matches media clusters and return explainers - [x] Search that matches explainers and return explainers
- Loading branch information
Showing
8 changed files
with
262 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
class TiplineSearchResult | ||
attr_accessor :team, :title, :body, :image_url, :language, :url, :type, :format | ||
|
||
def initialize(team:, title:, body:, image_url:, language:, url:, type:, format:) | ||
self.team = team | ||
self.title = title | ||
self.body = body | ||
self.image_url = image_url | ||
self.language = language | ||
self.url = url | ||
self.type = type # :explainer or :fact_check | ||
self.format = format # :text or :image | ||
end | ||
|
||
def should_send_in_language?(language) | ||
return true if self.team.get_languages.to_a.size < 2 | ||
tbi = TeamBotInstallation.where(team_id: self.team.id, user: BotUser.alegre_user).last | ||
should_send_report_in_different_language = !tbi&.alegre_settings&.dig('single_language_fact_checks_enabled') | ||
self.language == language || should_send_report_in_different_language | ||
end | ||
|
||
def team_report_setting_value(key, language) | ||
self.team.get_report.to_h.with_indifferent_access.dig(language, key) | ||
end | ||
|
||
def footer(language) | ||
footer = [] | ||
prefixes = { | ||
whatsapp: 'WhatsApp: ', | ||
facebook: 'FB Messenger: m.me/', | ||
twitter: 'Twitter: twitter.com/', | ||
telegram: 'Telegram: t.me/', | ||
viber: 'Viber: ', | ||
line: 'LINE: ', | ||
instagram: 'Instagram: instagram.com/' | ||
} | ||
[:signature, :whatsapp, :facebook, :twitter, :telegram, :viber, :line, :instagram].each do |field| | ||
value = self.team_report_setting_value(field.to_s, language) | ||
footer << "#{prefixes[field]}#{value}" unless value.blank? | ||
end | ||
footer.join("\n") | ||
end | ||
|
||
def text(language = nil, hide_body = false) | ||
text = [] | ||
text << "*#{self.title.strip}*" unless self.title.blank? | ||
text << self.body.to_s unless hide_body | ||
text << self.url unless self.url.blank? | ||
text = text.collect do |part| | ||
self.team.get_shorten_outgoing_urls ? UrlRewriter.shorten_and_utmize_urls(part, self.team.get_outgoing_urls_utm_code) : part | ||
end | ||
unless language.nil? | ||
footer = self.footer(language) | ||
text << footer if !footer.blank? && self.team_report_setting_value('use_signature', language) | ||
end | ||
text.join("\n\n") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.