Skip to content

Commit

Permalink
Revert "Use different query normalization settings for different BSPs…
Browse files Browse the repository at this point in the history
… (CAPI/Smooch-Zendesk)" (#2002)

This reverts commit 9a1dfec.
  • Loading branch information
melsawy authored Aug 21, 2024
1 parent 9a1dfec commit 8b36ea4
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 19 deletions.
7 changes: 1 addition & 6 deletions app/models/concerns/smooch_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

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'].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

Expand Down
2 changes: 0 additions & 2 deletions test/models/bot/smooch_3_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions test/models/bot/smooch_4_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions test/models/bot/smooch_5_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions test/models/bot/smooch_7_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 8b36ea4

Please sign in to comment.