Module: Card::Query::CardQuery::MatchAttributes

Included in:
Card::Query::CardQuery
Defined in:
lib/card/query/card_query/match_attributes.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#complete(val) ⇒ Object

match names beginning with term



23
24
25
# File 'lib/card/query/card_query/match_attributes.rb', line 23

def complete val
  add_condition key_like("#{val.to_name.key}%", val =~ /\+/)
end

#match(val) ⇒ Object

match term anywhere in name or content



11
12
13
14
15
16
17
18
19
20
# File 'lib/card/query/card_query/match_attributes.rb', line 11

def match val
  val.gsub!(/[^#{Card::Name::OK4KEY_RE}]+/, " ")
  return nil if val.strip.empty?

  val.gsub!("*", '\\\\\\\\*')
  val_list = val.split(/\s+/).map do |v|
    name_or_content_match v
  end
  add_condition and_join(val_list)
end

#name_match(val) ⇒ Object

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



29
30
31
# File 'lib/card/query/card_query/match_attributes.rb', line 29

def name_match val
  add_condition name_like(val)
end