diff --git a/app/models/bot/alegre.rb b/app/models/bot/alegre.rb index b7e4488040..6eb0f5f2c4 100644 --- a/app/models/bot/alegre.rb +++ b/app/models/bot/alegre.rb @@ -41,7 +41,7 @@ def similar_items_ids_and_scores(team_ids, thresholds = {}) ALL_TEXT_SIMILARITY_FIELDS.each do |field| text = self.send(field) next if text.blank? - threads << Thread.new { ids_and_scores.merge!(Bot::Alegre.get_similar_texts(team_ids, text, Bot::Alegre::ALL_TEXT_SIMILARITY_FIELDS, thresholds[:text]).to_h) } + threads << Thread.new { ids_and_scores.merge!(Bot::Alegre.get_items_from_similar_text(team_ids, text, Bot::Alegre::ALL_TEXT_SIMILARITY_FIELDS, thresholds[:text]).to_h) } end threads.map(&:join) end @@ -206,7 +206,7 @@ def self.get_items_from_similar_text(team_id, text, fields = nil, threshold = ni threshold ||= self.get_threshold_for_query('text', nil, true) models ||= [self.matching_model_to_use(team_ids)].flatten Hash[self.get_similar_items_from_api( - '/text/similarity/search/', + '/similarity/sync/text', self.similar_texts_from_api_conditions(text, models, fuzzy, team_ids, fields, threshold), threshold ).collect{|k,v| [k, v.merge(model: v[:model]||Bot::Alegre.default_matching_model)]}] @@ -719,8 +719,4 @@ def self.is_text_too_short?(pm, length_threshold) is_short end - class < 0.9, pm.id => 0.8 }) + Bot::Alegre.stubs(:get_items_from_similar_text).returns({ pm2.id => 0.9, pm.id => 0.8 }) query = 'query { project_media(ids: "' + [pm.id, p.id, t.id].join(',') + '") { similar_items(first: 10000) { edges { node { dbid, claim_description { id, fact_check { id } } } } } } }' post :create, params: { query: query, team: t.slug } assert_response :success assert_equal pm2.id, JSON.parse(@response.body)['data']['project_media']['similar_items']['edges'][0]['node']['dbid'] - Bot::Alegre.unstub(:get_similar_texts) + Bot::Alegre.unstub(:get_items_from_similar_text) end test "should create and update flags and content warning" do