From cd5d9e3a842d30b7f0657c0807287889a933c1c8 Mon Sep 17 00:00:00 2001 From: Mohamed El-Sawy Date: Tue, 17 Dec 2024 15:12:05 +0200 Subject: [PATCH] CV2-5779: use same sort for explainer (#2156) --- app/models/explainer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/explainer.rb b/app/models/explainer.rb index feee0df35..b26f247eb 100644 --- a/app/models/explainer.rb +++ b/app/models/explainer.rb @@ -117,7 +117,7 @@ def self.search_by_similarity(text, language, team_id, limit) context: context } response = Bot::Alegre.query_sync_with_params(params, "text") - results = response['result'].to_a.sort_by{ |result| result['_score'] } + results = response['result'].to_a.sort_by{ |result| [result['model'] != Bot::Alegre::ELASTICSEARCH_MODEL ? 1 : 0, result['_score']] }.reverse explainer_ids = results.collect{ |result| result.dig('context', 'explainer_id').to_i }.uniq.first(limit) explainer_ids.empty? ? Explainer.none : Explainer.where(team_id: team_id, id: explainer_ids) end