lib/card/query/attributes.rb in card-1.93.13 vs lib/card/query/attributes.rb in card-1.94.0

- old
+ new

@@ -25,22 +25,15 @@ # Implements the match attribute that matches always against content and name. # 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"] } def match val - cxn = connection val.gsub!(/[^#{Card::Name::OK4KEY_RE}]+/, " ") return nil if val.strip.empty? val_list = val.split(/\s+/).map do |v| - name_or_content = [ - "replace(#{table_alias}.name,'+',' ')", - "#{table_alias}.db_content" - ].map do |field| - %(#{field} #{cxn.match quote("[[:<:]]#{v}[[:>:]]")}) - end - or_join name_or_content + name_or_content_match v end add_condition and_join(val_list) end def name_match val @@ -63,9 +56,21 @@ Rails.logger.info "using DEPRECATED extension_type in WQL" interpret right_plus: AccountID end private + + def name_or_content_match val + cxn = connection + or_join( + [field_match("replace(#{table_alias}.name,'+',' ')", val, cxn), + field_match("#{table_alias}.db_content", val, cxn)] + ) + end + + def field_match field, val, cxn + %(#{field} #{cxn.match quote("[[:<:]]#{val}[[:>:]]")}) + end def name_like patterns, extra_cond="" likes = Array(patterns).map do |pat| "lower(#{table_alias}.name) LIKE lower(#{quote pat})"