Class: Summon::Query

Inherits:
Schema show all
Defined in:
lib/summon/schema/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Schema

inherited

Instance Attribute Details

#facet_fieldsObject (readonly)

Returns the value of attribute facet_fields.



12
13
14
# File 'lib/summon/schema/query.rb', line 12

def facet_fields
  @facet_fields
end

#facet_value_filtersObject (readonly)

Returns the value of attribute facet_value_filters.



7
8
9
# File 'lib/summon/schema/query.rb', line 7

def facet_value_filters
  @facet_value_filters
end

#facet_value_group_filtersObject (readonly)

Returns the value of attribute facet_value_group_filters.



8
9
10
# File 'lib/summon/schema/query.rb', line 8

def facet_value_group_filters
  @facet_value_group_filters
end

#holdings_only_enabled?Object (readonly)

Returns the value of attribute holdings_only_enabled?.



15
16
17
# File 'lib/summon/schema/query.rb', line 15

def holdings_only_enabled?
  @holdings_only_enabled?
end

#page_numberObject (readonly)

Returns the value of attribute page_number.



3
4
5
# File 'lib/summon/schema/query.rb', line 3

def page_number
  @page_number
end

#page_sizeObject (readonly)

Returns the value of attribute page_size.



4
5
6
# File 'lib/summon/schema/query.rb', line 4

def page_size
  @page_size
end

#paramsObject (readonly)

Returns the value of attribute params.



14
15
16
# File 'lib/summon/schema/query.rb', line 14

def params
  @params
end

#query_stringObject (readonly)

Returns the value of attribute query_string.



6
7
8
# File 'lib/summon/schema/query.rb', line 6

def query_string
  @query_string
end

#range_filtersObject (readonly)

Returns the value of attribute range_filters.



11
12
13
# File 'lib/summon/schema/query.rb', line 11

def range_filters
  @range_filters
end

#search_termsObject (readonly)

Returns the value of attribute search_terms.



5
6
7
# File 'lib/summon/schema/query.rb', line 5

def search_terms
  @search_terms
end

#sortsObject (readonly)

Returns the value of attribute sorts.



13
14
15
# File 'lib/summon/schema/query.rb', line 13

def sorts
  @sorts
end

#text_filtersObject (readonly)

Returns the value of attribute text_filters.



10
11
12
# File 'lib/summon/schema/query.rb', line 10

def text_filters
  @text_filters
end

#text_queriesObject (readonly)

Returns the value of attribute text_queries.



9
10
11
# File 'lib/summon/schema/query.rb', line 9

def text_queries
  @text_queries
end

Instance Method Details

#date_filterObject



35
36
37
38
39
# File 'lib/summon/schema/query.rb', line 35

def date_filter
  range_filters.find {|f| f.field_name == "PublicationDate"}.tap do |this|
    yield this if this && block_given?
  end
end

#date_maxObject



28
29
30
31
32
33
# File 'lib/summon/schema/query.rb', line 28

def date_max
  date_filter do |f|    
    val = f.range.max_value
    return val == "*" ? nil : val.to_i
  end
end

#date_minObject



21
22
23
24
25
26
# File 'lib/summon/schema/query.rb', line 21

def date_min
  date_filter do |f|
    val = f.range.min_value
    return val == "*" ? nil : val.to_i
  end
end

#sortObject



17
18
19
# File 'lib/summon/schema/query.rb', line 17

def sort
  @sorts.first
end

#to_hashObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/summon/schema/query.rb', line 41

def to_hash    
  # {}.tap do |params|
  #   for param in query_string.split("&") do
  #     name, value = param.split("=")
  #     next if value.nil?
  #     name = CGI.une
  #   end
  # end
  
  return {} if query_string.nil? || query_string == ""
  params = query_string.split("&").inject({}) do |params, param|
    name, value = param.split("=")
    next params if value.nil?
    name = CGI.unescape(name)
    value = CGI.unescape(value)
    params.tap do
      case params[name]
        when nil
          params[name] = value
        when String
          params[name] = [params[name], value]
        else
          params[name] << value
      end
    end
  end
end