Skip to content

Commit

Permalink
Search for similar items only if show_similar flag is explicitly pa…
Browse files Browse the repository at this point in the history
…ssed (#2124)

* Search for similar items only if `show_similar` flag is explicitly passed.

Fixes: CV2-5608.
  • Loading branch information
caiosba committed Nov 10, 2024
1 parent 1169cb1 commit a36e416
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/check_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ def medias_query
core_conditions << { terms: { get_search_field => @options['project_media_ids'] } } unless @options['project_media_ids'].blank?
core_conditions << { terms: { team_id: [@options['team_id']].flatten } } if @options['team_id'].is_a?(Array)
core_conditions << { terms: { archived: @options['archived'] } }
core_conditions << { term: { sources_count: 0 } } unless @options['show_similar']
custom_conditions << { terms: { read: @options['read'].map(&:to_i) } } if @options.has_key?('read')
custom_conditions << { terms: { cluster_teams: @options['cluster_teams'] } } if @options.has_key?('cluster_teams')
custom_conditions << { terms: { unmatched: @options['unmatched'] } } if @options.has_key?('unmatched')
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/elastic_search_5_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def setup
sleep 2
result = CheckSearch.new({}.to_json, nil, t.id)
assert_equal [parent.id], result.medias.map(&:id).sort
result = CheckSearch.new({show_similar: true}.to_json, nil, t.id)
result = CheckSearch.new({ show_similar: true }.to_json, nil, t.id)
assert_equal [parent.id, child_1.id, child_2.id], result.medias.map(&:id).sort
result = CheckSearch.new({ keyword: 'child_media' }.to_json, nil, t.id)
assert_equal [parent.id], result.medias.map(&:id)
assert_equal [], result.medias.map(&:id)
result = CheckSearch.new({ keyword: 'child_media', show_similar: true }.to_json, nil, t.id)
assert_equal [child_1.id, child_2.id], result.medias.map(&:id).sort
end
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/graphql_controller_2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def setup
assert_response :success
assert_equal 4, JSON.parse(@response.body)['data']['search']['number_of_results']

query = 'query CheckSearch { search(query: "{\"keyword\":\"Foo\",\"show_similar\":false}") { number_of_results } }'
query = 'query CheckSearch { search(query: "{\"keyword\":\"Foo\",\"show_similar\":true}") { number_of_results } }'
post :create, params: { query: query, team: 'team' }
assert_response :success
assert_equal 2, JSON.parse(@response.body)['data']['search']['number_of_results']
Expand Down

0 comments on commit a36e416

Please sign in to comment.