Module: Card::Set::Abstract::CqlSearch

Extended by:
Card::Set
Defined in:
card/tmpsets/set/mod035-card-mod-search/abstract/06_cql_search.rb,
card/tmpsets/set/mod036-card-mod-search/abstract/06_cql_search.rb

Overview

Set: Abstract (CqlSearch)

Defined Under Namespace

Modules: Format, HtmlFormat

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore

Methods included from Card::Set::AdvancedApi

#attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject



7
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/06_cql_search.rb', line 7

def self.source_location; "/Users/ethan/dev/decko/gem/card-mod-search/set/abstract/06_cql_search.rb"; end

Instance Method Details

#cache_query?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/06_cql_search.rb', line 32

def cache_query?
  true
end

#cql_contentObject

override this to define search



15
16
17
18
19
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/06_cql_search.rb', line 15

def cql_content
  query = content
  query = query.is_a?(Hash) ? query : parse_json_cql(query)
  query.symbolize_keys
end

#cql_hashObject



10
11
12
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/06_cql_search.rb', line 10

def cql_hash
  cache_query? ? (@cql_hash ||= cql_content) : cql_content
end

#empty_query_error!Object

Raises:



43
44
45
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/06_cql_search.rb', line 43

def empty_query_error!
  raise Error::BadQuery, "can't run search with empty content"
end

#fetch_query(args = {}) ⇒ Object



64
65
66
67
68
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/06_cql_search.rb', line 64

def fetch_query args={}
  @query = nil unless cache_query?
  @query ||= {}
  @query[args.to_s] ||= query(args.clone) # cache query
end

#item_typeObject



21
22
23
24
25
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/06_cql_search.rb', line 21

def item_type
  type = cql_hash[:type]
  return if type.is_a?(Array) || type.is_a?(Hash)
  type
end

#parse_json_cql(query) ⇒ Object



36
37
38
39
40
41
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/06_cql_search.rb', line 36

def parse_json_cql query
  empty_query_error! if query.empty?
  JSON.parse query
rescue JSON::ParserError
  raise Error::BadQuery, "Invalid JSON search query: #{query}"
end

#query(args = {}) ⇒ Object



70
71
72
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/06_cql_search.rb', line 70

def query args={}
  Query.new standardized_query_args(args), name
end

#search(args = {}) ⇒ Object

These search methods are shared by card and format



48
49
50
51
52
53
54
55
56
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/06_cql_search.rb', line 48

def search args={}
  with_skipping args do
    query = fetch_query(args)
    # forces explicit limiting
    # can be 0 or less to force no limit
    raise "OH NO.. no limit" unless query.mods[:limit]
    query.run
  end
end

#skip_search?Boolean

for override, eg when required subqueries are known to be missing

Returns:

  • (Boolean)


28
29
30
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/06_cql_search.rb', line 28

def skip_search?
  false
end

#standardized_query_args(args) ⇒ Object



74
75
76
77
78
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/06_cql_search.rb', line 74

def standardized_query_args args
  args = cql_hash.merge args.symbolize_keys
  args[:context] ||= name
  args
end

#with_skipping(args) ⇒ Object



58
59
60
61
62
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/06_cql_search.rb', line 58

def with_skipping args
  return yield unless skip_search?

  args[:return] == :count ? 0 : []
end