<commit_before>Types::WorkType = GraphQL::ObjectType.define do
  name "Work"

  field :id, !types.ID
  field :english_title, types.String
  field :form, types.String
  field :original_title, !types.String
  field :slug, !types.String
  field :structure, types.String
  field :urn, types.String
  field :text_nodes,
        function: Functions::Pagination.new(children: :text_nodes, type: types[Types::TextNodeType])
  field :text_nodes_by_location, types[Types::TextNodeType] do
    description "Find TextNodes using the location array"

    argument :leading_nodes,
             types.Int,
             "Number of nodes before given location (limit: 30)",
             default_value: 10,
             prepare: -> (n, ctx) { [n, 30].min }
    argument :location, !types[!types.Int]
    argument :trailing_nodes,
             types.Int,
             "Number of nodes before given location (limit: 30)",
             default_value: 10,
             prepare: -> (n, ctx) { [n, 30].min }

    resolve -> (obj, args, ctx) do
      obj.text_nodes.where(
        "location[array_length(location, 1)] <= ?
         and location[array_length(location, 1)] >= ?",
        args[:location][args[:location].length - 1] + args[:trailing_nodes],
        args[:location][args[:location].length - 1] - args[:leading_nodes] 
      ).order(index: :asc)
    end
  end
end<commit_msg>Update querying text_nodes by location<commit_after>Types::WorkType = GraphQL::ObjectType.define do
  name "Work"

  field :id, !types.ID
  field :english_title, types.String
  field :form, types.String
  field :original_title, !types.String
  field :slug, !types.String
  field :structure, types.String
  field :urn, types.String
  field :text_nodes,
        function: Functions::Pagination.new(children: :text_nodes, type: types[Types::TextNodeType])
  field :text_nodes_by_location, types[Types::TextNodeType] do
    description "Find TextNodes using the location array"

    argument :leading_nodes,
             types.Int,
             "Number of nodes before given location (limit: 30)",
             default_value: 10,
             prepare: -> (n, ctx) { [n, 30].min }
    argument :location, !types[!types.Int]
    argument :trailing_nodes,
             types.Int,
             "Number of nodes before given location (limit: 30)",
             default_value: 10,
             prepare: -> (n, ctx) { [n, 30].min }

    resolve -> (obj, args, ctx) do
      obj.text_nodes.where(
        "(index >= (
               select index - :leading_nodes from text_nodes
               where work_id = :work_id and location = ARRAY[:location]
        ) and index < (
              select index from text_nodes
              where work_id = :work_id and location = ARRAY[:location]
        )) or (index <= (
               select index + :trailing_nodes from text_nodes
               where work_id = :work_id and location = ARRAY[:location]
        ) and index >= (
              select index from text_nodes
              where work_id = :work_id and location = ARRAY[:location]
        ))",
        leading_nodes: args[:leading_nodes],
        location: args[:location],
        trailing_nodes: args[:trailing_nodes],
        work_id: obj.id
      ).order(index: :asc)
    end
  end
end
{'fraction_non_alphanumeric': 0.11487526947951955, 'fraction_numerical': 0.008623344625808438, 'mean_word_length': 2.5304347826086957, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 12, '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': '6587792', 'n_tokens_mistral': 972, 'n_tokens_neox': 939, 'n_words': 259}