Sha256: 0bc892e01d5a8505519dc089d5d62a94623a21679d1ec88783e820226ec26b7e

Contents?: true

Size: 1.33 KB

Versions: 22

Compression:

Stored size: 1.33 KB

Contents

class Card
  module Query
    class CardQuery
      # Implements the match attributes that match always against content and/or name.
      # Currently that's different from the match operator that can be restricted to
      # names or content.
      # Example: { match: "name or content" } vs. { name: ["match", "a name"] }
      # TODO: unify handling for both using full text indexing
      module MatchAttributes
        # match term anywhere in name or content
        def match val
          return unless val.present?

          subconds = %i[name content].map do |field|
            Value.new([:match, val], self).to_sql field
          end
          add_condition or_join(subconds)
        end

        # match names beginning with term
        def complete val
          val = val.to_name
          if val.compound?
            interpret left: val.left
            interpret right: { complete: val.right } if val.right.present?
          else
            add_condition "#{table_alias}.key LIKE '#{val.to_name.key}%'"
          end
        end

        # match term anywhere in name
        # DEPRECATE - move handling to name: ["match", val]
        def name_match val
          interpret name: [:match, val]
        end

        private

        def or_join conditions
          "(#{Array(conditions).join ' OR '})"
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
card-1.107.0 lib/card/query/card_query/match_attributes.rb
card-1.106.0 lib/card/query/card_query/match_attributes.rb
card-1.105.6 lib/card/query/card_query/match_attributes.rb
card-1.105.5 lib/card/query/card_query/match_attributes.rb
card-1.105.4 lib/card/query/card_query/match_attributes.rb
card-1.105.3 lib/card/query/card_query/match_attributes.rb
card-1.105.2.pre1 lib/card/query/card_query/match_attributes.rb
card-1.105.2 lib/card/query/card_query/match_attributes.rb
card-1.105.1 lib/card/query/card_query/match_attributes.rb
card-1.105.0 lib/card/query/card_query/match_attributes.rb
card-1.104.2 lib/card/query/card_query/match_attributes.rb
card-1.104.1 lib/card/query/card_query/match_attributes.rb
card-1.104.0 lib/card/query/card_query/match_attributes.rb
card-1.103.4 lib/card/query/card_query/match_attributes.rb
card-1.103.3 lib/card/query/card_query/match_attributes.rb
card-1.103.2 lib/card/query/card_query/match_attributes.rb
card-1.103.1 lib/card/query/card_query/match_attributes.rb
card-1.103.0 lib/card/query/card_query/match_attributes.rb
card-1.101.7 lib/card/query/card_query/match_attributes.rb
card-1.102.0 lib/card/query/card_query/match_attributes.rb