Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CV2-5915: Delete search filters that are not needed anymore #2191

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/lib/check_elastic_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def create_elasticsearch_doc_bg(options)
# TODO: Sawy remove annotation_type field
ms.attributes[:annotation_type] = 'mediasearch'
ms.attributes[:team_id] = self.team_id
ms.attributes[:project_id] = self.project_id
ms.attributes[:annotated_type] = self.class.name
ms.attributes[:annotated_id] = self.id
ms.attributes[:parent_id] = self.id
Expand Down
22 changes: 0 additions & 22 deletions app/models/annotations/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ class Comment < ApplicationRecord

before_save :extract_check_entities, unless: proc { |p| p.is_being_copied }
after_commit :send_slack_notification, on: [:create, :update]
after_commit :add_elasticsearch_comment, on: :create
after_commit :update_elasticsearch_comment, on: :update
after_commit :destroy_elasticsearch_comment, on: :destroy

notifies_pusher on: :destroy,
event: 'media_updated',
Expand Down Expand Up @@ -86,23 +83,4 @@ def extract_check_entities
end
self.entities = ids
end

def add_elasticsearch_comment
add_update_elasticsearch_comment('create')
end

def update_elasticsearch_comment
add_update_elasticsearch_comment('update')
end

def add_update_elasticsearch_comment(op)
# add item/task notes
if self.annotated_type == 'ProjectMedia'
add_update_nested_obj({ op: op, nested_key: 'comments', keys: ['text'], pm_id: self.annotated_id })
end
end

def destroy_elasticsearch_comment
destroy_es_items('comments', 'destroy_doc_nested', self.annotated_id) if self.annotated_type == 'ProjectMedia'
end
end
2 changes: 1 addition & 1 deletion app/models/project_media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ def add_extra_elasticsearch_data(ms)
# set fields with integer value including cached fields
fields_i = [
'archived', 'sources_count', 'linked_items_count', 'share_count','last_seen', 'demand', 'user_id',
'read', 'suggestions_count','related_count', 'reaction_count', 'comment_count', 'media_published_at',
'read', 'suggestions_count','related_count', 'reaction_count', 'media_published_at',
'unmatched', 'fact_check_published_on'
]
fields_i.each{ |f| ms.attributes[f] = self.send(f).to_i }
Expand Down
10 changes: 0 additions & 10 deletions app/repositories/media_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class MediaSearch

mapping do
indexes :team_id, { type: 'integer' }
indexes :project_id, { type: 'integer' }
indexes :annotated_type, { type: 'text' }
indexes :annotated_id, { type: 'integer' }
indexes :parent_id, { type: 'integer' }
Expand All @@ -21,13 +20,6 @@ class MediaSearch
indexes :created_at, { type: 'date' }
indexes :updated_at, { type: 'date' }
indexes :language, { type: 'text', analyzer: 'keyword' }
indexes :comments, {
type: 'nested',
properties: {
id: { type: 'text'},
text: { type: 'text', analyzer: 'check'}
}
}
indexes :tags, {
type: 'nested',
properties: {
Expand Down Expand Up @@ -83,8 +75,6 @@ class MediaSearch

indexes :reaction_count, { type: 'long' }

indexes :comment_count, { type: 'long' }

indexes :related_count, { type: 'long' }

indexes :suggestions_count, { type: 'long' }
Expand Down
2 changes: 1 addition & 1 deletion app/workers/project_media_cache_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ProjectMediaCacheWorker
PROJECT_MEDIA_CACHED_FIELDS = [
'linked_items_count', 'suggestions_count', 'is_suggested', 'is_confirmed', 'related_count',
'requests_count', 'demand', 'last_seen', 'description', 'title', 'status', 'share_count',
'reaction_count', 'comment_count', 'report_status', 'tags_as_sentence', 'sources_as_sentence',
'reaction_count', 'report_status', 'tags_as_sentence', 'sources_as_sentence',
'media_published_at', 'published_by', 'type_of_media', 'added_as_similar_by_name',
'confirmed_as_similar_by_name', 'folder', 'show_warning_cover', 'picture',
'team_name', 'creator_name'
Expand Down
13 changes: 2 additions & 11 deletions lib/check_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def initialize(options, file = nil, team_id = Team.current&.id)
'recent_activity' => 'updated_at', 'recent_added' => 'created_at', 'demand' => 'demand',
'related' => 'linked_items_count', 'last_seen' => 'last_seen', 'share_count' => 'share_count',
'report_status' => 'report_status', 'tags_as_sentence' => 'tags_as_sentence',
'media_published_at' => 'media_published_at', 'reaction_count' => 'reaction_count', 'comment_count' => 'comment_count',
'media_published_at' => 'media_published_at', 'reaction_count' => 'reaction_count',
'related_count' => 'related_count', 'suggestions_count' => 'suggestions_count', 'status_index' => 'status_index',
'type_of_media' => 'type_of_media', 'title' => 'title_index', 'creator_name' => 'creator_name',
'cluster_size' => 'cluster_size', 'cluster_first_item_at' => 'cluster_first_item_at',
Expand Down Expand Up @@ -166,7 +166,7 @@ def should_hit_elasticsearch?
status_blank = false unless @options[field].blank?
end
filters_blank = true
['tags', 'keyword', 'rules', 'language', 'fc_language', 'request_language', 'report_language', 'team_tasks', 'assigned_to', 'report_status', 'range_numeric',
['tags', 'keyword', 'language', 'fc_language', 'request_language', 'report_language', 'team_tasks', 'assigned_to', 'report_status', 'range_numeric',
'has_claim', 'cluster_teams', 'published_by', 'annotated_by', 'channels', 'cluster_published_reports'
].each do |filter|
filters_blank = false unless @options[filter].blank?
Expand Down Expand Up @@ -463,15 +463,6 @@ def keyword_conditions
keyword_c = []
field_conditions = build_keyword_conditions_media_fields
keyword_c.concat field_conditions
# Search in comments
keyword_c << {
nested: {
path: "comments",
query: {
simple_query_string: { query: @options["keyword"], fields: ["comments.text"], default_operator: "AND" }
}
}
} if should_include_keyword_field?('comments')
# Search in requests
[['request_username', 'username'], ['request_identifier', 'identifier'], ['request_content', 'content']].each do |pair|
keyword_c << {
Expand Down
26 changes: 0 additions & 26 deletions test/controllers/elastic_search_2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,6 @@ def setup
super
setup_elasticsearch
end

test "should update elasticsearch after move media to other projects" do
t = create_team
u = create_user
create_team_user team: t, user: u, role: 'admin'
p = create_project team: t
p2 = create_project team: t
m = create_valid_media
User.stubs(:current).returns(u)
pm = create_project_media project: p, media: m, disable_es_callbacks: false
create_comment annotated: pm
create_tag annotated: pm
sleep 1
id = get_es_id(pm)
ms = $repository.find(id)
assert_equal ms['project_id'].to_i, p.id
assert_equal ms['team_id'].to_i, t.id
pm = ProjectMedia.find pm.id
pm.project_id = p2.id
pm.save!
# confirm annotations log
sleep 1
ms = $repository.find(id)
assert_equal ms['project_id'].to_i, p2.id
assert_equal ms['team_id'].to_i, t.id
end

test "should destroy elasticseach project media" do
t = create_team
Expand Down
5 changes: 0 additions & 5 deletions test/controllers/elastic_search_4_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ def setup
# keyword & tags & status
result = CheckSearch.new({keyword: 'report_title', tags: ['sports'], verification_status: ['verified']}.to_json)
assert_equal [pm.id], result.medias.map(&:id)
# search keyword in comments
create_comment text: 'add_comment', annotated: pm, disable_es_callbacks: false
sleep 1
result = CheckSearch.new({keyword: 'add_comment'}.to_json)
assert_equal [pm.id], result.medias.map(&:id)
end

test "should sort results by recent activities and recent added" do
Expand Down
53 changes: 2 additions & 51 deletions test/controllers/elastic_search_5_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ def setup
Sidekiq::Testing.inline! do
pm = create_project_media project: p, media: m, disable_es_callbacks: false
c = create_comment annotated: pm, disable_es_callbacks: false
sleep 1
result = $repository.find(get_es_id(pm))
assert_equal 1, result['comments'].count
id = pm.id
m.destroy
assert_equal 0, ProjectMedia.where(media_id: id).count
Expand Down Expand Up @@ -108,28 +105,6 @@ def setup
end
end

test "should create update destroy elasticsearch comment" do
t = create_team
p = create_project team: t
m = create_valid_media
s = create_source
pm = create_project_media project: p, media: m, disable_es_callbacks: false
c = create_comment annotated: pm, text: 'test', disable_es_callbacks: false
sleep 1
result = $repository.find(get_es_id(pm))
assert_equal [c.id], result['comments'].collect{|i| i["id"]}
# update es comment
c.text = 'test-mod'; c.save!
sleep 1
result = $repository.find(get_es_id(pm))
assert_equal ['test-mod'], result['comments'].collect{|i| i["text"]}
# destroy es comment
c.destroy
sleep 1
result = $repository.find(get_es_id(pm))
assert_empty result['comments']
end

test "should create update destroy elasticsearch tag" do
t = create_team
p = create_project team: t
Expand Down Expand Up @@ -169,9 +144,8 @@ def setup

test "should create parent if not exists" do
t = create_team
p = create_project team: t
pm = create_project_media project: p
c = create_comment annotated: pm, disable_es_callbacks: false
pm = create_project_media team: t
t = create_tag annotated: pm, tag: 'sports', disable_es_callbacks: false
sleep 1
result = $repository.find(get_es_id(pm))
assert_not_nil result
Expand Down Expand Up @@ -223,28 +197,5 @@ def setup
end
end

test "should update elasticsearch after move project to other team" do
u = create_user
t = create_team
t2 = create_team
u.is_admin = true; u.save!
p = create_project team: t
m = create_valid_media
User.stubs(:current).returns(u)
Sidekiq::Testing.inline! do
pm = create_project_media project: p, media: m, disable_es_callbacks: false
pm2 = create_project_media project: p, quote: 'Claim', disable_es_callbacks: false
sleep 2
results = $repository.search(query: { match: { team_id: t.id } }).results
assert_equal [pm.id, pm2.id], results.collect{|i| i['annotated_id']}.sort
p.team_id = t2.id; p.save!
sleep 2
results = $repository.search(query: { match: { team_id: t.id } }).results
assert_equal [], results.collect{|i| i['annotated_id']}
results = $repository.search(query: { match: { team_id: t2.id } }).results
assert_equal [pm.id, pm2.id], results.collect{|i| i['annotated_id']}.sort
end
end

# Please add new tests to test/controllers/elastic_search_7_test.rb
end
3 changes: 0 additions & 3 deletions test/controllers/elastic_search_7_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@ def setup
assert_equal [pm2.id, pm3.id], result.medias.map(&:id).sort
create_comment annotated: pm, text: 'item notepm', disable_es_callbacks: false
create_comment annotated: pm2, text: 'item comment', disable_es_callbacks: false
sleep 2
result = CheckSearch.new({keyword: 'item', keyword_fields: {fields: ['comments']}}.to_json, nil, t.id)
assert_equal [pm.id, pm2.id], result.medias.map(&:id).sort
end

test "should search by media url" do
Expand Down
12 changes: 0 additions & 12 deletions test/controllers/elastic_search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ def setup
ids << id["node"]["dbid"]
end
assert_equal [pm2.id], ids
create_comment text: 'title_a', annotated: pm1, disable_es_callbacks: false
sleep 2
Team.stubs(:current).returns(@team)
query = 'query Search { search(query: "{\"keyword\":\"title_a\",\"sort\":\"recent_activity\"}") { medias(first: 10) { edges { node { dbid } } } } }'
post :create, params: { query: query }
Team.unstub(:current)
assert_response :success
ids = []
JSON.parse(@response.body)['data']['search']['medias']['edges'].each do |id|
ids << id["node"]["dbid"]
end
assert_equal [pm1.id, pm2.id], ids.sort
end

test "should search media with multiple projects" do
Expand Down
19 changes: 2 additions & 17 deletions test/models/project_media_5_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -757,50 +757,35 @@ def setup
end

test "should restore and confirm item if not super admin" do
setup_elasticsearch
t = create_team
p = create_project team: t
p3 = create_project team: t
u = create_user
create_team_user user: u, team: t, role: 'admin', is_admin: false
Sidekiq::Testing.inline! do
# test restore
pm = create_project_media project: p, disable_es_callbacks: false, archived: CheckArchivedFlags::FlagCodes::TRASHED
sleep 1
result = $repository.find(get_es_id(pm))['project_id']
assert_equal p.id, result
pm = create_project_media project: p, archived: CheckArchivedFlags::FlagCodes::TRASHED
assert_equal CheckArchivedFlags::FlagCodes::TRASHED, pm.archived
with_current_user_and_team(u, t) do
pm.archived = CheckArchivedFlags::FlagCodes::NONE
pm.disable_es_callbacks = false
pm.project_id = p3.id
pm.save!
end
pm = pm.reload
assert_equal CheckArchivedFlags::FlagCodes::NONE, pm.archived
assert_equal p3.id, pm.project_id
sleep 1
result = $repository.find(get_es_id(pm))['project_id']
assert_equal p3.id, result
# test confirm
pm = create_project_media project: p, disable_es_callbacks: false, archived: CheckArchivedFlags::FlagCodes::UNCONFIRMED
sleep 1
pm = create_project_media project: p, archived: CheckArchivedFlags::FlagCodes::UNCONFIRMED
assert_equal p.id, pm.project_id
result = $repository.find(get_es_id(pm))['project_id']
assert_equal p.id, result
assert_equal CheckArchivedFlags::FlagCodes::UNCONFIRMED, pm.archived
with_current_user_and_team(u, t) do
pm.archived = CheckArchivedFlags::FlagCodes::NONE
pm.disable_es_callbacks = false
pm.project_id = p3.id
pm.save!
end
pm = pm.reload
assert_equal CheckArchivedFlags::FlagCodes::NONE, pm.archived
assert_equal p3.id, pm.project_id
sleep 1
result = $repository.find(get_es_id(pm))['project_id']
assert_equal p3.id, result
end
end

Expand Down
4 changes: 0 additions & 4 deletions test/models/project_media_6_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@ def setup
assert_equal CheckArchivedFlags::FlagCodes::TRASHED, result['archived']
result = $repository.find(get_es_id(pm1_s))
assert_equal CheckArchivedFlags::FlagCodes::NONE, result['archived']
assert_equal p.id, result['project_id']
result = $repository.find(get_es_id(pm2_s))
assert_equal CheckArchivedFlags::FlagCodes::NONE, result['archived']
assert_equal p.id, result['project_id']
end

test "should detach similar items when spam parent item" do
Expand Down Expand Up @@ -136,10 +134,8 @@ def setup
assert_equal CheckArchivedFlags::FlagCodes::SPAM, result['archived']
result = $repository.find(get_es_id(pm1_s))
assert_equal CheckArchivedFlags::FlagCodes::NONE, result['archived']
assert_equal p.id, result['project_id']
result = $repository.find(get_es_id(pm2_s))
assert_equal CheckArchivedFlags::FlagCodes::NONE, result['archived']
assert_equal p.id, result['project_id']
end

test "should complete media if there are pending tasks" do
Expand Down
Loading