def query_message(search, index, comments = '')
      message = Message.new

      # Mode, Limits
      message.append_ints @offset, @limit, MatchModes[@match_mode]

      # Ranking
      message.append_int RankModes[@rank_mode]
      message.append_string @rank_expr if @rank_mode == :expr

      # Sort Mode
      message.append_int SortModes[@sort_mode]
      message.append_string @sort_by

      # Query
      message.append_string search

      # Weights
      message.append_int @weights.length
      message.append_ints *@weights

      # Index
      message.append_string index

      # ID Range
      message.append_int 1
      message.append_64bit_ints @id_range.first, @id_range.last

      # Filters
      message.append_int @filters.length
      @filters.each { |filter| message.append filter.query_message }

      # Grouping
      message.append_int GroupFunctions[@group_function]
      message.append_string @group_by
      message.append_int @max_matches
      message.append_string @group_clause
      message.append_ints @cut_off, @retry_count, @retry_delay
      message.append_string @group_distinct

      # Anchor Point
      if @anchor.empty?
        message.append_int 0
      else
        message.append_int 1
        message.append_string @anchor[:latitude_attribute]
        message.append_string @anchor[:longitude_attribute]
        message.append_floats @anchor[:latitude], @anchor[:longitude]
      end

      # Per Index Weights
      message.append_int @index_weights.length
      @index_weights.each do |key,val|
        message.append_string key.to_s
        message.append_int val
      end

      # Max Query Time
      message.append_int @max_query_time

      # Per Field Weights
      message.append_int @field_weights.length
      @field_weights.each do |key,val|
        message.append_string key.to_s
        message.append_int val
      end

      message.append_string comments

      return message.to_s if Versions[:search] < 0x116

      # Overrides
      message.append_int @overrides.length
      @overrides.each do |key,val|
        message.append_string key.to_s
        message.append_int AttributeTypes[val[:type]]
        message.append_int val[:values].length
        val[:values].each do |id,map|
          message.append_64bit_int id
          method = case val[:type]
          when :float
            :append_float
          when :bigint
            :append_64bit_int
          else
            :append_int
          end
          message.send method, map
        end
      end

      message.append_string @select

      message.to_s
    end
def query_message(search, index, comments = '')
      message = Message.new

      # Mode, Limits
      message.append_ints @offset, @limit, MatchModes[@match_mode]

      # Ranking
      message.append_int RankModes[@rank_mode]
      message.append_string @rank_expr if @rank_mode == :expr

      # Sort Mode
      message.append_int SortModes[@sort_mode]
      message.append_string @sort_by

      # Query
      message.append_string search

      # Weights
      message.append_int @weights.length
      message.append_ints *@weights

      # Index
      message.append_string index

      # ID Range
      message.append_int 1
      message.append_64bit_ints @id_range.first, @id_range.last

      # Filters
      message.append_int @filters.length
      @filters.each { |filter| message.append filter.query_message }

      # Grouping
      message.append_int GroupFunctions[@group_function]
      message.append_string @group_by
      message.append_int @max_matches
      message.append_string @group_clause
      message.append_ints @cut_off, @retry_count, @retry_delay
      message.append_string @group_distinct

      # Anchor Point
      if @anchor.empty?
        message.append_int 0
      else
        message.append_int 1
        message.append_string @anchor[:latitude_attribute]
        message.append_string @anchor[:longitude_attribute]
        message.append_floats @anchor[:latitude], @anchor[:longitude]
      end

      # Per Index Weights
      message.append_int @index_weights.length
      @index_weights.each do |key,val|
        message.append_string key.to_s
        message.append_int val
      end

      # Max Query Time
      message.append_int @max_query_time

      # Per Field Weights
      message.append_int @field_weights.length
      @field_weights.each do |key,val|
        message.append_string key.to_s
        message.append_int val
      end

      message.append_string comments

      return message.to_s if Versions[:search] < 0x116

      # Overrides
      message.append_int @overrides.length
      @overrides.each do |key,val|
        message.append_string key.to_s
        message.append_int AttributeTypes[val[:type]]
        message.append_int val[:values].length
        val[:values].each do |id,map|
          message.append_64bit_int id
          method = case val[:type]
          when :float
            :append_float
          when :bigint
            :append_64bit_int
          else
            :append_int
          end
          message.send method, map
        end
      end

      message.append_string @select

      message.to_s
    end
Generation of the message to send to Sphinx for a search.