primedia-endeca 0.9.18 → 0.9.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/endeca.gemspec +1 -1
- data/lib/core_ext.rb +8 -0
- data/lib/endeca.rb +1 -1
- data/lib/endeca/map.rb +4 -4
- data/lib/endeca/transformer.rb +2 -1
- data/spec/endeca/document_spec.rb +8 -0
- data/spec/endeca/map_spec.rb +20 -14
- metadata +1 -1
data/endeca.gemspec
CHANGED
data/lib/core_ext.rb
CHANGED
data/lib/endeca.rb
CHANGED
data/lib/endeca/map.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Endeca
|
2
2
|
class Map
|
3
|
-
def initialize(old_key
|
4
|
-
@old_key = old_key
|
5
|
-
@new_key = new_key
|
3
|
+
def initialize(old_key, new_key=nil)
|
4
|
+
@old_key = old_key.to_sym
|
5
|
+
@new_key = new_key || @old_key
|
6
6
|
boolean
|
7
7
|
end
|
8
8
|
|
@@ -75,7 +75,7 @@ module Endeca
|
|
75
75
|
|
76
76
|
# Perform the mapping as defined for the current_query
|
77
77
|
def perform(current_query)
|
78
|
-
@current_query = current_query.
|
78
|
+
@current_query = current_query.symbolize_keys
|
79
79
|
|
80
80
|
perform_transformation
|
81
81
|
perform_map
|
data/lib/endeca/transformer.rb
CHANGED
@@ -25,11 +25,12 @@ module Endeca
|
|
25
25
|
# Use the mappings hash to replace domain level query query_options with
|
26
26
|
# their Endeca equivalent.
|
27
27
|
def transform_query_options(query_options)
|
28
|
-
query = query_options.
|
28
|
+
query = query_options.symbolize_keys
|
29
29
|
query.each do |key, value|
|
30
30
|
if mappings[key]
|
31
31
|
new_options = mappings[key].perform(query_options)
|
32
32
|
query_options.delete(key)
|
33
|
+
query_options.delete(key.to_s)
|
33
34
|
query_options.update(new_options)
|
34
35
|
end
|
35
36
|
end
|
@@ -241,6 +241,14 @@ describe Endeca::Document do
|
|
241
241
|
after do
|
242
242
|
Endeca::Document.mappings = {}
|
243
243
|
end
|
244
|
+
|
245
|
+
describe "when the key to be mapped is a string" do
|
246
|
+
it "maps correctly" do
|
247
|
+
Endeca::Document.map(:apartments => :showapartments)
|
248
|
+
Endeca::Document.transform_query_options("apartments" => true).
|
249
|
+
should == {:showapartments => 1}
|
250
|
+
end
|
251
|
+
end
|
244
252
|
|
245
253
|
describe "when there is no mapping for the given key" do
|
246
254
|
it "returns the query options without modification" do
|
data/spec/endeca/map_spec.rb
CHANGED
@@ -48,21 +48,27 @@ describe Endeca::Map do
|
|
48
48
|
|
49
49
|
describe "#perform_into" do
|
50
50
|
describe "with an enclosing string" do
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
it "wraps the parameter" do
|
52
|
+
map = Endeca::Map.new(:foo, :bar)
|
53
|
+
map.into(:bizz).enclose(:AND)
|
54
|
+
map.perform(:foo => :quux).should == {:bizz => 'AND(bar:quux)'}
|
55
|
+
end
|
54
56
|
end
|
55
57
|
|
56
58
|
describe "with replace" do
|
57
|
-
|
58
|
-
|
59
|
-
|
59
|
+
it "replaces the existing parameter" do
|
60
|
+
map = Endeca::Map.new(:foo, :bar)
|
61
|
+
map.into(:bizz).replace!
|
62
|
+
map.perform(:foo => :quux, :bizz => :foobar).should == {:bizz => 'bar:quux'}
|
63
|
+
end
|
60
64
|
end
|
61
65
|
|
62
66
|
describe "with enclose and replace" do
|
63
|
-
|
64
|
-
|
65
|
-
|
67
|
+
it "wraps the parameter and replaces the existing parameter" do
|
68
|
+
map = Endeca::Map.new(:foo, :bar)
|
69
|
+
map.into(:bizz).enclose(:AND).replace!
|
70
|
+
map.perform(:foo => :quux, :bizz => :foobar).should == {:bizz => 'AND(bar:quux)'}
|
71
|
+
end
|
66
72
|
end
|
67
73
|
end
|
68
74
|
|
@@ -96,11 +102,11 @@ describe Endeca::Map do
|
|
96
102
|
|
97
103
|
describe "#transform" do
|
98
104
|
it "should execute the transformation block on the query"
|
99
|
-
|
100
|
-
|
101
|
-
|
105
|
+
map = Endeca::Map.new(:field_list)
|
106
|
+
map.into(:F).transform do |fields_array|
|
107
|
+
fields_array.collect{|field| "#{field.to_s}:1"}.join('|')
|
108
|
+
map.perform(:field_list => [:first_name, :last_name, :email]).
|
109
|
+
should == {:F => "first_name:1|last_name:1|email:1"}
|
102
110
|
end
|
103
|
-
map.perform(:field_list => [:first_name, :last_name, :email]).
|
104
|
-
should == {:F => "first_name:1|last_name:1|email:1"}
|
105
111
|
end
|
106
112
|
end
|