diff --git a/app/models/article.rb b/app/models/article.rb index a764c395c..a00eef547 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -427,11 +427,6 @@ class Article < ApplicationRecord spaminess_rating: BlackBox.calculate_spaminess(self)) end - def search_score - calculated_score = hotness_score.to_i + ((comments_count * 3).to_i + positive_reactions_count.to_i * 300 * user.reputation_modifier * score.to_i) - calculated_score.to_i - end - private def delete_related_objects @@ -439,6 +434,11 @@ class Article < ApplicationRecord Search::RemoveFromIndexWorker.new.perform("ordered_articles_#{Rails.env}", index_id) end + def search_score + calculated_score = hotness_score.to_i + ((comments_count * 3).to_i + positive_reactions_count.to_i * 300 * user.reputation_modifier * score.to_i) + calculated_score.to_i + end + def tag_keywords_for_search tags.pluck(:keywords_for_search).join end diff --git a/app/serializers/search/article_serializer.rb b/app/serializers/search/article_serializer.rb index 63517b055..8212da36f 100644 --- a/app/serializers/search/article_serializer.rb +++ b/app/serializers/search/article_serializer.rb @@ -8,7 +8,7 @@ module Search :comments_count, :experience_level_rating, :experience_level_rating_distribution, :featured, :featured_number, :hotness_score, :language, :main_image, :path, :positive_reactions_count, :published, - :published_at, :reactions_count, :reading_time, :search_score, :score, :title + :published_at, :reactions_count, :reading_time, :score, :title # video_duration_in_minutes in Elasticsearch is mapped as an integer # however, it really is a string in the format 00:00 which is why we diff --git a/spec/serializers/search/article_serializer_spec.rb b/spec/serializers/search/article_serializer_spec.rb index ac1730822..6dc3ae8ac 100644 --- a/spec/serializers/search/article_serializer_spec.rb +++ b/spec/serializers/search/article_serializer_spec.rb @@ -12,7 +12,7 @@ RSpec.describe Search::ArticleSerializer do expect(data_hash[:user]).to eq(user_data) expect(data_hash.dig(:organization, :id)).to eq(organization.id) expect(data_hash.dig(:flare_tag_hash, :name)).to eq(tag.name) - expect(data_hash.keys).to include(:id, :body_text, :hotness_score, :search_score) + expect(data_hash.keys).to include(:id, :body_text, :hotness_score) end it "creates valid json for Elasticsearch", elasticsearch: true do