<commit_before>defmodule Ello.Search.TrendingPost do

  def build_boosting_queries(query, trending) do
    query
    |> boost_recent(trending)
    |> boost_comment_count(trending)
    |> boost_repost_count(trending)
    |> boost_view_count(trending)
    |> boost_love_count(trending)
    |> update_score_mode(trending)
  end

  defp boost_recent(query, true) do
    weight = Application.get_env(:ello_search, :post_trending_recency_weight)
    scale = Application.get_env(:ello_search, :post_trending_recency_scale)
    offset = Application.get_env(:ello_search, :post_trending_recency_offset)
    recent_boost = %{gauss: %{created_at: %{scale: scale, offset: offset}}, weight: weight}
    update_in(query[:query][:function_score][:functions], &([recent_boost | &1]))
  end
  defp boost_recent(query, _), do: update_in(query[:sort], &(&1 = %{created_at: %{order: "desc"}}))

  defp boost_comment_count(query, true), do:
    update_in(query[:query][:function_score][:functions], &([%{field_value_factor: %{field: "comment_count", modifier: "log1p", factor: 0.3}} | &1]))
  defp boost_comment_count(query, _), do: query

  defp boost_repost_count(query, true), do:
    update_in(query[:query][:function_score][:functions], &([%{field_value_factor: %{field: "repost_count", modifier: "log1p", factor: 0.8}} | &1]))
  defp boost_repost_count(query, _), do: query

  defp boost_view_count(query, true), do:
    update_in(query[:query][:function_score][:functions], &([%{field_value_factor: %{field: "view_count", modifier: "log1p", factor: 0.00001}} | &1]))
  defp boost_view_count(query, _), do: query

  defp boost_love_count(query, true), do:
    update_in(query[:query][:function_score][:functions], &([%{field_value_factor: %{field: "love_count", modifier: "log1p", factor: 0.05}} | &1]))
  defp boost_love_count(query, _), do: query

  defp update_score_mode(query, true), do:
    update_in(query[:query][:function_score][:score_mode], &(&1 = "multiply"))
  defp update_score_mode(query, _), do: query

end<commit_msg>1 single repost has a bit to much power - trying a tweak<commit_after>defmodule Ello.Search.TrendingPost do

  def build_boosting_queries(query, trending) do
    query
    |> boost_recent(trending)
    |> boost_comment_count(trending)
    |> boost_repost_count(trending)
    |> boost_view_count(trending)
    |> boost_love_count(trending)
    |> update_score_mode(trending)
  end

  defp boost_recent(query, true) do
    weight = Application.get_env(:ello_search, :post_trending_recency_weight)
    scale = Application.get_env(:ello_search, :post_trending_recency_scale)
    offset = Application.get_env(:ello_search, :post_trending_recency_offset)
    recent_boost = %{gauss: %{created_at: %{scale: scale, offset: offset}}, weight: weight}
    update_in(query[:query][:function_score][:functions], &([recent_boost | &1]))
  end
  defp boost_recent(query, _), do: update_in(query[:sort], &(&1 = %{created_at: %{order: "desc"}}))

  defp boost_comment_count(query, true), do:
    update_in(query[:query][:function_score][:functions], &([%{field_value_factor: %{field: "comment_count", modifier: "log1p", factor: 0.5}} | &1]))
  defp boost_comment_count(query, _), do: query

  defp boost_repost_count(query, true), do:
    update_in(query[:query][:function_score][:functions], &([%{field_value_factor: %{field: "repost_count", modifier: "log1p", factor: 0.5}} | &1]))
  defp boost_repost_count(query, _), do: query

  defp boost_view_count(query, true), do:
    update_in(query[:query][:function_score][:functions], &([%{field_value_factor: %{field: "view_count", modifier: "log1p", factor: 0.00001}} | &1]))
  defp boost_view_count(query, _), do: query

  defp boost_love_count(query, true), do:
    update_in(query[:query][:function_score][:functions], &([%{field_value_factor: %{field: "love_count", modifier: "log1p", factor: 0.5}} | &1]))
  defp boost_love_count(query, _), do: query

  defp update_score_mode(query, true), do:
    update_in(query[:query][:function_score][:score_mode], &(&1 = "multiply"))
  defp update_score_mode(query, _), do: query

end
{'fraction_non_alphanumeric': 0.1625, 'fraction_numerical': 0.011764705882352941, 'mean_word_length': 6.4743589743589745, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2632588', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1451, 'n_words': 268}