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

Extended by:
Card::Set::AbstractFormat
Defined in:
card/tmpsets/set/mod035-card-mod-search/abstract/05_search/views.rb,
card/tmpsets/set/mod036-card-mod-search/abstract/05_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



80
81
82
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/05_search/views.rb', line 80

def complete_cql
  { complete: term_param }
end

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



59
60
61
62
63
64
65
66
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/05_search/views.rb', line 59

def complete_or_match_search limit: AUTOCOMPLETE_LIMIT, start_only: false
  starts_with = complete_search limit: limit
  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)
end

#complete_search(limit: AUTOCOMPLETE_LIMIT) ⇒ Object



68
69
70
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/05_search/views.rb', line 68

def complete_search limit: AUTOCOMPLETE_LIMIT
  card.search name_cql(limit).merge(complete_cql)
end

#item_cardsObject



41
42
43
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/05_search/views.rb', line 41

def item_cards
  search_with_params
end

#match_cql(not_names) ⇒ Object



84
85
86
87
88
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/05_search/views.rb', line 84

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: []) ⇒ Object



72
73
74
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/05_search/views.rb', line 72

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

#name_cql(limit) ⇒ Object



76
77
78
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/05_search/views.rb', line 76

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

#term_paramObject



90
91
92
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/05_search/views.rb', line 90

def term_param
  params[:term]
end

#view: moleculeObject

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



46
47
48
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/05_search/views.rb', line 46

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

#view: name_completeObject

TODO: design better autocomplete API



51
52
53
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/05_search/views.rb', line 51

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

#view: name_matchObject



55
56
57
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/05_search/views.rb', line 55

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