<commit_before>require 'elastic_record/relation/value_methods'
require 'elastic_record/relation/admin'
require 'elastic_record/relation/batches'
require 'elastic_record/relation/delegation'
require 'elastic_record/relation/finder_methods'
require 'elastic_record/relation/merging'
require 'elastic_record/relation/none'
require 'elastic_record/relation/search_methods'

module ElasticRecord
  class Relation
    include Admin, Batches, Delegation, FinderMethods, Merging, SearchMethods

    attr_reader :klass, :values

    def initialize(klass)
      @klass = klass
      @values = {}
    end

    def count
      search_results['hits']['total']
    end

    def aggregations
      search_results['aggregations']
    end

    def explain(id)
      klass.elastic_index.explain(id, as_elastic)
    end

    def initialize_copy(other)
      @values = @values.dup
      reset
    end

    def to_a
      @records ||= load_hits(to_ids)
    end

    def to_ids
      search_hits.map { |hit| hit['_id'] }
    end

    def delete_all
      find_ids_in_batches { |ids| klass.delete(ids) }
      klass.elastic_index.delete_by_query(as_elastic)
    end

    def ==(other)
      to_a == other
    end

    def inspect
      to_a.inspect
    end

    def scoping
      previous, klass.current_elastic_search = klass.current_elastic_search, self
      yield
    ensure
      klass.current_elastic_search = previous
    end

    private
      def reset
        @search_results = @records = nil
      end

      def search_hits
        search_results['hits']['hits']
      end

      def search_results
        @search_results ||= begin
          options = search_type_value ? {search_type: search_type_value} : {}
          klass.elastic_index.search(as_elastic, options)
        end
      end

      def load_hits(ids)
        scope = select_values.any? ? klass.select(select_values) : klass
        if defined?(ActiveRecord::Base) && klass < ActiveRecord::Base
          case klass.connection.adapter_name
          when /Mysql/
            scope = scope.order("FIELD(#{connection.quote_column_name(primary_key)}, #{ids.join(',')})")
          when /Pos/
            scope = scope.order(ids.map { |id| "ID=#{connection.quote(id)} DESC" }.join(','))
          end
        end
        scope.find(ids)
      end
  end
end
<commit_msg>Request no fields. This prevents the source from being returned<commit_after>require 'elastic_record/relation/value_methods'
require 'elastic_record/relation/admin'
require 'elastic_record/relation/batches'
require 'elastic_record/relation/delegation'
require 'elastic_record/relation/finder_methods'
require 'elastic_record/relation/merging'
require 'elastic_record/relation/none'
require 'elastic_record/relation/search_methods'

module ElasticRecord
  class Relation
    include Admin, Batches, Delegation, FinderMethods, Merging, SearchMethods

    attr_reader :klass, :values

    def initialize(klass)
      @klass = klass
      @values = {}
    end

    def count
      search_results['hits']['total']
    end

    def aggregations
      search_results['aggregations']
    end

    def explain(id)
      klass.elastic_index.explain(id, as_elastic)
    end

    def initialize_copy(other)
      @values = @values.dup
      reset
    end

    def to_a
      @records ||= load_hits(to_ids)
    end

    def to_ids
      search_hits.map { |hit| hit['_id'] }
    end

    def delete_all
      find_ids_in_batches { |ids| klass.delete(ids) }
      klass.elastic_index.delete_by_query(as_elastic)
    end

    def ==(other)
      to_a == other
    end

    def inspect
      to_a.inspect
    end

    def scoping
      previous, klass.current_elastic_search = klass.current_elastic_search, self
      yield
    ensure
      klass.current_elastic_search = previous
    end

    private
      def reset
        @search_results = @records = nil
      end

      def search_hits
        search_results['hits']['hits']
      end

      def search_results
        @search_results ||= begin
          options = search_type_value ? {search_type: search_type_value} : {}
          klass.elastic_index.search(as_elastic, options.update(fields: ''))
        end
      end

      def load_hits(ids)
        scope = select_values.any? ? klass.select(select_values) : klass
        if defined?(ActiveRecord::Base) && klass < ActiveRecord::Base
          case klass.connection.adapter_name
          when /Mysql/
            scope = scope.order("FIELD(#{connection.quote_column_name(primary_key)}, #{ids.join(',')})")
          when /Pos/
            scope = scope.order(ids.map { |id| "ID=#{connection.quote(id)} DESC" }.join(','))
          end
        end
        scope.find(ids)
      end
  end
end

{'fraction_non_alphanumeric': 0.09581474399830041, 'fraction_numerical': 0.0, 'mean_word_length': 2.6638132295719843, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '902047', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1442, 'n_words': 303}