From 8b36ea44a4ac3c5f0d27fda2707c342d71284ee0 Mon Sep 17 00:00:00 2001 From: Mohamed El-Sawy Date: Wed, 21 Aug 2024 19:49:16 +0300 Subject: [PATCH] Revert "Use different query normalization settings for different BSPs (CAPI/Smooch-Zendesk)" (#2002) This reverts commit 9a1dfecc5e5c2a3a89e2b912d678bfbd5e51b194. --- app/models/concerns/smooch_search.rb | 7 +------ test/controllers/graphql_controller_11_test.rb | 6 +++--- test/models/bot/smooch_3_test.rb | 2 -- test/models/bot/smooch_4_test.rb | 2 -- test/models/bot/smooch_5_test.rb | 4 ---- test/models/bot/smooch_7_test.rb | 2 -- 6 files changed, 4 insertions(+), 19 deletions(-) diff --git a/app/models/concerns/smooch_search.rb b/app/models/concerns/smooch_search.rb index f4f63708a3..8c66f2c1c0 100644 --- a/app/models/concerns/smooch_search.rb +++ b/app/models/concerns/smooch_search.rb @@ -142,12 +142,7 @@ def get_search_results(uid, message, team_id, language) end def normalized_query_hash(type, query, team_ids, after, feed_id, language) - 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 + normalized_query = query.downcase.chomp.strip unless query.nil? Digest::MD5.hexdigest([type.to_s, normalized_query, [team_ids].flatten.join(','), after.to_s, feed_id.to_i, language.to_s].join(':')) end diff --git a/test/controllers/graphql_controller_11_test.rb b/test/controllers/graphql_controller_11_test.rb index 43995dc5f1..af6670ab50 100644 --- a/test/controllers/graphql_controller_11_test.rb +++ b/test/controllers/graphql_controller_11_test.rb @@ -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'].collect{ |edge| edge['node']['dbid'] }.sort + data = response['accessible_teams']['edges'] assert_equal 2, data.size - assert_equal team1.id, data[0] - assert_equal team2.id, data[1] + assert_equal team1.id, data[0]['node']['dbid'] + assert_equal team2.id, data[1]['node']['dbid'] assert_equal 2, response['accessible_teams_count'] end diff --git a/test/models/bot/smooch_3_test.rb b/test/models/bot/smooch_3_test.rb index 883b89b9e9..acef2b3e66 100644 --- a/test/models/bot/smooch_3_test.rb +++ b/test/models/bot/smooch_3_test.rb @@ -558,11 +558,9 @@ 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 diff --git a/test/models/bot/smooch_4_test.rb b/test/models/bot/smooch_4_test.rb index ff17eca751..34167fa5f6 100644 --- a/test/models/bot/smooch_4_test.rb +++ b/test/models/bot/smooch_4_test.rb @@ -671,11 +671,9 @@ 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) diff --git a/test/models/bot/smooch_5_test.rb b/test/models/bot/smooch_5_test.rb index befb70b9a7..0321dca79f 100644 --- a/test/models/bot/smooch_5_test.rb +++ b/test/models/bot/smooch_5_test.rb @@ -69,19 +69,15 @@ 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 diff --git a/test/models/bot/smooch_7_test.rb b/test/models/bot/smooch_7_test.rb index c4e4426866..4fd46ac40e 100644 --- a/test/models/bot/smooch_7_test.rb +++ b/test/models/bot/smooch_7_test.rb @@ -389,7 +389,6 @@ 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 @@ -398,7 +397,6 @@ 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