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

Use different normalization settings for different BSPs #1999

Closed
wants to merge 3 commits into from
Closed
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
7 changes: 6 additions & 1 deletion app/models/concerns/smooch_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ def get_search_results(uid, message, team_id, language)
end

def normalized_query_hash(type, query, team_ids, after, feed_id, language)
normalized_query = query.downcase.chomp.strip unless query.nil?
normalized_query = nil
if RequestStore.store[:smooch_bot_provider] == 'CAPI'
normalized_query = query.to_s.downcase.chomp.strip.truncate(4096)
elsif RequestStore.store[:smooch_bot_provider] == 'SMOOCH'
normalized_query = query.to_s.downcase.chomp.strip.truncate(1024)
end
Digest::MD5.hexdigest([type.to_s, normalized_query, [team_ids].flatten.join(','), after.to_s, feed_id.to_i, language.to_s].join(':'))
end

Expand Down
6 changes: 3 additions & 3 deletions test/controllers/graphql_controller_11_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ def teardown
post :create, params: { query: query }
assert_response :success
response = JSON.parse(@response.body)['data']['me']
data = response['accessible_teams']['edges']
data = response['accessible_teams']['edges'].collect{ |edge| edge['node']['dbid'] }.sort
assert_equal 2, data.size
assert_equal team1.id, data[0]['node']['dbid']
assert_equal team2.id, data[1]['node']['dbid']
assert_equal team1.id, data[0]
assert_equal team2.id, data[1]
assert_equal 2, response['accessible_teams_count']
end

Expand Down
2 changes: 2 additions & 0 deletions test/models/bot/smooch_3_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,11 @@ def teardown
'Segurança das urna',
'Seguranca das urnas'
].each do |query|
Rails.cache.clear
assert_equal [pm1.id], Bot::Smooch.search_for_similar_published_fact_checks('text', query, [t.id]).to_a.map(&:id)
end

Rails.cache.clear
assert_equal [], Bot::Smooch.search_for_similar_published_fact_checks('text', 'Segurando', [t.id]).to_a.map(&:id)
end

Expand Down
2 changes: 2 additions & 0 deletions test/models/bot/smooch_4_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,11 @@ def teardown

uid = random_string
query = Bot::Smooch.get_search_query(uid, {})
Rails.cache.clear
assert_equal [pm2], Bot::Smooch.get_search_results(uid, query, t.id, 'en')
Bot::Smooch.stubs(:bundle_list_of_messages).returns({ 'type' => 'text', 'text' => "Test #{url}" })
query = Bot::Smooch.get_search_query(uid, {})
Rails.cache.clear
assert_equal [pm1], Bot::Smooch.get_search_results(uid, query, t.id, 'en')

ProjectMedia.any_instance.unstub(:report_status)
Expand Down
4 changes: 4 additions & 0 deletions test/models/bot/smooch_5_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,19 @@ def teardown
with_current_user_and_team(u, t1) do

# Keyword search
Rails.cache.clear
assert_equal [pm1a, pm1f, pm2a].sort, Bot::Smooch.search_for_similar_published_fact_checks('text', 'Test', [t1.id, t2.id, t3.id, t4.id], nil, f1.id).to_a.sort

# Text similarity search
Rails.cache.clear
assert_equal [pm1a, pm1d, pm2a], Bot::Smooch.search_for_similar_published_fact_checks('text', 'This is a test', [t1.id, t2.id, t3.id, t4.id], nil, f1.id).to_a

# Media similarity search
Rails.cache.clear
assert_equal [pm1a, pm1d, pm2a], Bot::Smooch.search_for_similar_published_fact_checks('image', random_url, [t1.id, t2.id, t3.id, t4.id], nil, f1.id).to_a

# URL search
Rails.cache.clear
assert_equal [pm1g, pm2b].sort, Bot::Smooch.search_for_similar_published_fact_checks('text', "Test with URL: #{url}", [t1.id, t2.id, t3.id, t4.id], nil, f1.id).to_a.sort
end

Expand Down
2 changes: 2 additions & 0 deletions test/models/bot/smooch_7_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ def teardown
'ward', #Fuzzy match (non-emoji)
'🤣 ward', #Fuzzy match (non-emoji)
].each do |query|
Rails.cache.clear
assert_equal [pm.id], Bot::Smooch.search_for_similar_published_fact_checks('text', query, [t.id]).to_a.map(&:id)
end

Expand All @@ -397,6 +398,7 @@ def teardown
'🌞', #No match
'🤣 🌞' #No match (we only perform AND)
].each do |query|
Rails.cache.clear
assert_equal [], Bot::Smooch.search_for_similar_published_fact_checks('text', query, [t.id]).to_a.map(&:id)
end
end
Expand Down
Loading