<commit_before>module Ace
  module Spades
    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods

      def ace_of_spades(config = {})

        cattr_accessor :aces_high_server
        cattr_accessor :searchable_block
        
        self.aces_high_server = DRbObject.new_with_uri(config[:server_address])
        
        class << self

          def searchable(options = {}, &block)

            self.searchable_block = block

            after_save :perform_index_tasks
           
            after_destroy :remove_from_index
      
          end

          def search(query)
            result = self.aces_high_server.search( query )
          end    
          
        end

        include InstanceMethods
      end
    end

    module InstanceMethods

      def text(*fields)
        @index_fields = [] if @index_fields.nil?
        index_data = {id: (self.send(:id)).to_s}
        fields.each do |field|
          @index_fields << field unless @index_fields.include? field
          index_data[field.to_s] = (self.send(field)).to_s 
        end         
        self.aces_high_server.index(index_data)
        self.aces_high_server.commit_to_index <commit_msg>code to tell index to store certain fields<commit_after>module Ace
  module Spades
    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods

      def ace_of_spades(config = {})

        cattr_accessor :aces_high_server
        cattr_accessor :searchable_block
        
        self.aces_high_server = DRbObject.new_with_uri(config[:server_address])
        
        class << self

          def searchable(options = {}, &block)

            self.searchable_block = block

            after_save :perform_index_tasks
           
            after_destroy :remove_from_index
      
          end

          def method_added(name)
            if name == :text
              fields = method(name).parameters.map(&:last)
              fields.each { |field| self.aces_high_server.store_field( field ) }
            end  
          end  

          def search(query)
            result = self.aces_high_server.search( query )
          end    
          
        end

        include InstanceMethods
      end
    end

    module InstanceMethods

      def text(*fields)
        @index_fields = [] if @index_fields.nil?
        index_data = {id: (self.send(:id)).to_s}
        fields.each do |field|
          @index_fields << field unless @index_fields.include? field
          index_data[field.to_s] = (self.send(field)).to_s 
        end         
        self.aces_high_server.index(index_data)
        self.aces_high_server.commit_to_index 
{'fraction_non_alphanumeric': 0.07425373134328359, 'fraction_numerical': 0.0, 'mean_word_length': 1.8280590717299579, 'pattern_counts': {'":': 0, '<': 11, '<?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': '3084802', 'n_tokens_mistral': 775, 'n_tokens_neox': 753, 'n_words': 150}