Skip to content

Commit

Permalink
CV2-4085: Remove the hardcoded minimum number of words to run a full …
Browse files Browse the repository at this point in the history
…similarity search (#1755)

* Remove the hardcoded minimum number of words to run
a full similarity search
* update and fix tests
  • Loading branch information
computermacgyver authored and caiosba committed Dec 8, 2023
1 parent 1bbada2 commit df9389e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/models/bot/alegre.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ def self.get_number_of_words(text)

def self.get_items_from_similar_text(team_id, text, fields = nil, threshold = nil, models = nil, fuzzy = false)
team_ids = [team_id].flatten
if text.blank? || self.get_number_of_words(text) < 3
Rails.logger.info("[Alegre Bot] get_items_from_similar_text returning early due to blank/short text #{text}")
if text.blank?
Rails.logger.info("[Alegre Bot] get_items_from_similar_text returning early due to blank text #{text}")
return {}
end
fields ||= ALL_TEXT_SIMILARITY_FIELDS
Expand Down
11 changes: 6 additions & 5 deletions test/models/bot/alegre_2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,8 @@ def teardown
TeamBotInstallation.unstub(:find_by_team_id_and_user_id)
end

test "should not get similar texts for texts with up to 2 words" do
assert_equal({}, Bot::Alegre.get_items_from_similar_text(random_number, 'Foo bar'))
test "should not get similar texts for blank string" do
assert_equal({}, Bot::Alegre.get_items_from_similar_text(random_number, ''))
end

test "should match rule by extracted text" do
Expand Down Expand Up @@ -620,10 +620,11 @@ def teardown
"sha256" => "1782b1d1993fcd9f6fd8155adc6009a9693a8da7bb96d20270c4bc8a30c97570",
"phash" => 17399941807326929,
"url" => "https:\/\/www.gstatic.com\/webp\/gallery3\/1.png",
"context" => [{
"context" => {
"team_id" => pm2.team.id.to_s,
"project_media_id" => pm2.id.to_s
}],
"project_media_id" => pm2.id.to_s,
"field" => "title"
},
},
"_score" => 0.9
}
Expand Down

0 comments on commit df9389e

Please sign in to comment.