Sha256: 7329f480667e9fa8647d9c2ed8dcca9be64ebfd4e485a18fbc0940738467c5dc

Contents?: true

Size: 962 Bytes

Versions: 16

Compression:

Stored size: 962 Bytes

Contents

module Sunspot
  module Query
    # 
    # The SortComposite class encapsulates an ordered collection of Sort
    # objects. It's necessary to keep this as a separate class as Solr takes
    # the sort as a single parameter, so adding sorts as regular components
    # would not merge correctly in the #to_params method.
    #
    class SortComposite #:nodoc:
      def initialize
        @sorts = []
      end

      # 
      # Add a sort to the composite
      #
      def <<(sort)
        @sorts << sort
      end

      #
      # Check sort presence
      #
      def include?(sort)
        @sorts.any? { |s| s.to_param.include?(sort) }
      end

      # 
      # Combine the sorts into a single param by joining them
      #
      def to_params(prefix = "")
        unless @sorts.empty?
          key = "#{prefix}sort".to_sym
          { key => @sorts.map { |sort| sort.to_param } * ', ' }
        else
          {}
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
sunspot-2.7.1 lib/sunspot/query/sort_composite.rb
sunspot-2.7.0 lib/sunspot/query/sort_composite.rb
sunspot-2.6.0 lib/sunspot/query/sort_composite.rb
sunspot-2.5.0 lib/sunspot/query/sort_composite.rb
sunspot-2.4.0 lib/sunspot/query/sort_composite.rb
sunspot-2.3.0 lib/sunspot/query/sort_composite.rb
sunspot-2.2.8 lib/sunspot/query/sort_composite.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sunspot-2.2.7/lib/sunspot/query/sort_composite.rb
sunspot-2.2.7 lib/sunspot/query/sort_composite.rb
sunspot-2.2.6 lib/sunspot/query/sort_composite.rb
sunspot-2.2.5 lib/sunspot/query/sort_composite.rb
sunspot-2.2.4 lib/sunspot/query/sort_composite.rb
sunspot-2.2.3 lib/sunspot/query/sort_composite.rb
sunspot-2.2.2 lib/sunspot/query/sort_composite.rb
sunspot-2.2.1 lib/sunspot/query/sort_composite.rb
sunspot-2.2.0 lib/sunspot/query/sort_composite.rb