<commit_before>defmodule Pan.SearchFrontendController do
  use Pan.Web, :controller
  require Logger

  def new(conn, params) do
    size = 10
    from = unless params["page"] in ["", nil] do
             (String.to_integer(params["page"]) - 1) * size
           else
             0
           end

    page = round((from + 10) / size)

    query = [index: "/panoptikum_" <> Application.get_env(:pan, :environment),
             search: [size: size, from: from,
               query: [
                 function_score: [
                   query: [match: [_all: [query: params["search"]["searchstring"]]]],
                   boost_mode: "multiply",
                   functions: [
                     %{filter: [term: ["_type": "categories"]], weight: 0},
                     %{filter: [term: ["_type": "podcasts"]], weight: 1},
                     %{filter: [term: ["_type": "personas"]], weight: 0},
                     %{filter: [term: ["_type": "episodes"]], weight: 0},
                     %{filter: [term: ["_type": "users"]], weight: 0}]]]]]

    case Tirexs.Query.create_resource(query) do
      {:ok, 200, %{hits: hits, took: took}} ->
        total = Enum.min([hits.total, 10000])
        render(conn, "new.html", searchstring: params["search"]["searchstring"],
                                 hits: hits, took: took, from: from, size: size, page: page,
                                 total: total)
      {:error, 500, %{error: %{caused_by: %{reason: reason}}}} ->
        render(conn, "error.html")
        raise reason
    end
  end
end<commit_msg>inspect query<commit_after>defmodule Pan.SearchFrontendController do
  use Pan.Web, :controller
  require Logger

  def new(conn, params) do
    size = 10
    from = unless params["page"] in ["", nil] do
             (String.to_integer(params["page"]) - 1) * size
           else
             0
           end

    page = round((from + 10) / size)

    query = [index: "/panoptikum_" <> Application.get_env(:pan, :environment),
             search: [size: size, from: from,
               query: [
                 function_score: [
                   query: [match: [_all: [query: params["search"]["searchstring"]]]],
                   boost_mode: "multiply",
                   functions: [
                     %{filter: [term: ["_type": "categories"]], weight: 0},
                     %{filter: [term: ["_type": "podcasts"]], weight: 1},
                     %{filter: [term: ["_type": "personas"]], weight: 0},
                     %{filter: [term: ["_type": "episodes"]], weight: 0},
                     %{filter: [term: ["_type": "users"]], weight: 0}]]]]]
    IO.inspect query

    case Tirexs.Query.create_resource(query) do
      {:ok, 200, %{hits: hits, took: took}} ->
        total = Enum.min([hits.total, 10000])
        render(conn, "new.html", searchstring: params["search"]["searchstring"],
                                 hits: hits, took: took, from: from, size: size, page: page,
                                 total: total)
      {:error, 500, %{error: %{caused_by: %{reason: reason}}}} ->
        render(conn, "error.html")
        raise reason
    end
  end
end
{'fraction_non_alphanumeric': 0.1623931623931624, 'fraction_numerical': 0.013928458372902817, 'mean_word_length': 1.839173405211141, 'pattern_counts': {'":': 10, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3511970', 'n_tokens_mistral': 988, 'n_tokens_neox': 911, 'n_words': 244}