Module: Card::Set::Abstract::Search::Views::JsonFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
platypus/tmp/set/gem-defaults/mod009-search/abstract/0_search/views.rb

Constant Summary collapse

AUTOCOMPLETE_LIMIT =

number of name suggestions for autocomplete text fields

8

Instance Method Summary collapse

Instance Method Details

#complete_cqlObject



85
86
87
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/0_search/views.rb', line 85

def complete_cql
  term_param.present? ? { complete: term_param } : {}
end

#complete_or_match_search(limit: AUTOCOMPLETE_LIMIT, start_only: false, additional_cql: {}) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/0_search/views.rb', line 61

def complete_or_match_search limit: AUTOCOMPLETE_LIMIT, start_only: false,
                             additional_cql: {}
  starts_with = complete_search limit: limit, additional_cql: additional_cql
  return starts_with if start_only

  remaining_slots = limit - starts_with.size
  return starts_with if remaining_slots.zero?

  starts_with + match_search(not_names: starts_with, limit: remaining_slots,
                             additional_cql: additional_cql)
end

#complete_search(limit: AUTOCOMPLETE_LIMIT, additional_cql: {}) ⇒ Object



73
74
75
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/0_search/views.rb', line 73

def complete_search limit: AUTOCOMPLETE_LIMIT, additional_cql: {}
  card.search name_cql(limit).merge(complete_cql).merge(additional_cql)
end

#match_cql(not_names) ⇒ Object



89
90
91
92
93
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/0_search/views.rb', line 89

def match_cql not_names
  cql = { name_match: term_param }
  cql[:name] = ["not in"] + not_names if not_names.any?
  cql
end

#match_search(limit: AUTOCOMPLETE_LIMIT, not_names: [], additional_cql: {}) ⇒ Object



77
78
79
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/0_search/views.rb', line 77

def match_search limit: AUTOCOMPLETE_LIMIT, not_names: [], additional_cql: {}
  card.search name_cql(limit).merge(match_cql(not_names)).merge(additional_cql)
end

#name_cql(limit) ⇒ Object



81
82
83
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/0_search/views.rb', line 81

def name_cql limit
  { limit: limit, sort_by: "name", return: "name" }
end

#view: moleculeObject

NOCACHE because paging_urls is uncacheable hash and thus not safe to merge



48
49
50
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/0_search/views.rb', line 48

view :molecule, cache: :never do
  molecule.merge render_paging_urls
end

#view: name_completeObject

TODO: design better autocomplete API



53
54
55
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/0_search/views.rb', line 53

view :name_complete, cache: :never do
  complete_search limit: AUTOCOMPLETE_LIMIT
end

#view: name_matchObject



57
58
59
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/0_search/views.rb', line 57

view :name_match, cache: :never do
  complete_or_match_search limit: AUTOCOMPLETE_LIMIT
end