module Card::Query::CardQuery::MatchAttributes

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

Public Instance Methods

complete(val) click to toggle source

match names beginning with term

# File lib/card/query/card_query/match_attributes.rb, line 21
def complete val
  val = val.to_name
  if val.compound?
    complete_compound val
  else
    add_condition "#{table_alias}.key LIKE '#{val.to_name.key}%'" if val.present?
    name_not_null
  end
end
match(val) click to toggle source

match term anywhere in name or content

# File lib/card/query/card_query/match_attributes.rb, line 11
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
name_match(val) click to toggle source

match term anywhere in name DEPRECATE - move handling to name: [“match”, val]

# File lib/card/query/card_query/match_attributes.rb, line 33
def name_match val
  interpret name: [:match, val] if val.present?
  name_not_null
end

Private Instance Methods

complete_compound(val) click to toggle source
# File lib/card/query/card_query/match_attributes.rb, line 40
def complete_compound val
  interpret left: val.left
  interpret right: { complete: val.right } if val.right.present?
end
name_not_null() click to toggle source
# File lib/card/query/card_query/match_attributes.rb, line 45
def name_not_null
  add_condition "#{table_alias}.key IS NOT NULL"
end
or_join(conditions) click to toggle source
# File lib/card/query/card_query/match_attributes.rb, line 49
def or_join conditions
  "(#{Array(conditions).join ' OR '})"
end