cheap_skate 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cheap_skate/application.rb +2 -0
- data/lib/cheap_skate/models.rb +30 -2
- metadata +2 -2
@@ -80,6 +80,7 @@ END
|
|
80
80
|
parm = CGI.parse(qry)
|
81
81
|
qt = (params['qt'] || "standard")
|
82
82
|
query = settings.index.send("parse_#{qt}_query".to_sym, parm)
|
83
|
+
|
83
84
|
|
84
85
|
opts = {}
|
85
86
|
opts[:offset] = (params["start"] || 0).to_i
|
@@ -95,6 +96,7 @@ END
|
|
95
96
|
query.parse_facet_query(parm)
|
96
97
|
end
|
97
98
|
results = settings.index.search(query, opts)
|
99
|
+
results.nl_format = params['json.nl']||'flat'
|
98
100
|
results
|
99
101
|
end
|
100
102
|
|
data/lib/cheap_skate/models.rb
CHANGED
@@ -26,7 +26,7 @@ module CheapSkate
|
|
26
26
|
end
|
27
27
|
|
28
28
|
class ResultSet
|
29
|
-
attr_accessor :total, :docs, :query, :limit, :offset, :facets, :query_time
|
29
|
+
attr_accessor :total, :docs, :query, :limit, :offset, :facets, :query_time, :nl_format
|
30
30
|
def <<(obj)
|
31
31
|
@docs ||=[]
|
32
32
|
@docs << obj
|
@@ -94,12 +94,40 @@ module CheapSkate
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def add_facets_to_results(query)
|
97
|
+
|
97
98
|
@facet_fields = query.facet_fields
|
98
99
|
@facet_limit = query.facet_limit
|
99
100
|
@facet_queries = query.facet_queries
|
100
101
|
@facet_offset = query.facet_offset
|
101
102
|
end
|
102
103
|
|
104
|
+
def format_facets
|
105
|
+
case self.nl_format
|
106
|
+
when "flat" then flatten_facet_array
|
107
|
+
when "map" then map_facet_array
|
108
|
+
else @facet_fields
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def flatten_facet_array
|
113
|
+
flat_arr = {}
|
114
|
+
@facet_fields.each_pair do |k,v|
|
115
|
+
flat_arr[k] = v.flatten
|
116
|
+
end
|
117
|
+
flat_arr
|
118
|
+
end
|
119
|
+
|
120
|
+
def map_facet_array
|
121
|
+
map_arr = {}
|
122
|
+
@facet_fields.each_pair do |k,v|
|
123
|
+
map_arr[k] ||= {}
|
124
|
+
v.flatten.each_cons(2) do |key, val|
|
125
|
+
map_arr[k][key] = val
|
126
|
+
end
|
127
|
+
end
|
128
|
+
map_arr
|
129
|
+
end
|
130
|
+
|
103
131
|
def parse_facet_query(params)
|
104
132
|
[*params['facet.query']].each do |q|
|
105
133
|
next unless q
|
@@ -131,7 +159,7 @@ module CheapSkate
|
|
131
159
|
p["facet.offset"] = @offset
|
132
160
|
p["facet.query"] = @query
|
133
161
|
@total = 400;
|
134
|
-
r["facet_counts"] = {"facet_fields"
|
162
|
+
r["facet_counts"] = {"facet_fields"=>format_facets, "facet_queries"=>[]}
|
135
163
|
if @facet_queries
|
136
164
|
@facet_queries.each do | fq |
|
137
165
|
r["facet_counts"]["facet_queries"] << [fq[:query_string], fq[:results]]
|