From 5a57f5cd7a8ee98556073877c1c17bb55c4feaa8 Mon Sep 17 00:00:00 2001 From: Devin Gaffney Date: Thu, 5 Sep 2024 07:43:54 -0700 Subject: [PATCH] alias and rename per caio review --- app/lib/smooch_nlu.rb | 4 ++-- app/models/concerns/alegre_v2.rb | 5 +++-- app/models/explainer.rb | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/lib/smooch_nlu.rb b/app/lib/smooch_nlu.rb index e1b8b0d33..71ca744fe 100644 --- a/app/lib/smooch_nlu.rb +++ b/app/lib/smooch_nlu.rb @@ -44,7 +44,7 @@ def update_keywords(language, keywords, keyword, operation, doc_id, context) } if operation == 'add' && !keywords.include?(keyword) keywords << keyword - Bot::Alegre.get_sync_with_params(common_alegre_params.merge({ text: keyword, models: ALEGRE_MODELS_AND_THRESHOLDS.keys }), "text") + Bot::Alegre.index_sync_with_params(common_alegre_params.merge({ text: keyword, models: ALEGRE_MODELS_AND_THRESHOLDS.keys }), "text") elsif operation == 'remove' keywords -= [keyword] Bot::Alegre.request_delete_from_raw(common_alegre_params.merge({ quiet: true }), "text") @@ -87,7 +87,7 @@ def self.alegre_matches_from_message(message, language, context, alegre_result_k language: language, }.merge(context) } - response = Bot::Alegre.get_sync_with_params(params, "text") + response = Bot::Alegre.query_sync_with_params(params, "text") # One approach would be to take the option that has the most matches # Unfortunately this approach is influenced by the number of keywords per option diff --git a/app/models/concerns/alegre_v2.rb b/app/models/concerns/alegre_v2.rb index 46db6ea13..5f6306190 100644 --- a/app/models/concerns/alegre_v2.rb +++ b/app/models/concerns/alegre_v2.rb @@ -290,11 +290,11 @@ def index_async_with_params(params, type, suppress_search_response=true) request("post", async_path_for_type(type), params.merge(suppress_search_response: suppress_search_response)) end - def get_sync_with_params(params, type) + def query_sync_with_params(params, type) request("post", sync_path_for_type(type), params) end - def get_async_with_params(params, type) + def query_async_with_params(params, type) request("post", async_path_for_type(type), params) end @@ -576,4 +576,5 @@ def restrict_contexts(project_media, project_media_id_scores) }] end end + alias :index_sync_with_params, :query_sync_with_params end diff --git a/app/models/explainer.rb b/app/models/explainer.rb index 35b1bf288..50abca75b 100644 --- a/app/models/explainer.rb +++ b/app/models/explainer.rb @@ -116,7 +116,7 @@ def self.search_by_similarity(text, language, team_id) language: language } } - response = Bot::Alegre.get_async_with_params(params, "text") + response = Bot::Alegre.query_async_with_params(params, "text") results = response['result'].to_a.sort_by{ |result| result['_score'] } explainer_ids = results.collect{ |result| result.dig('_source', 'context', 'explainer_id').to_i }.uniq.first(3) explainer_ids.empty? ? Explainer.none : Explainer.where(team_id: team_id, id: explainer_ids)