cloud_search 0.0.8 → 0.0.9

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/README.md CHANGED
@@ -51,7 +51,8 @@ resp = searcher.with_fields(:actor, :director, :title, :year, :text_relevanc
51
51
  ``` ruby
52
52
  searcher = CloudSearch::Searcher.new
53
53
  resp = searcher.with_fields(:actor, :director, :title, :year, :text_relevance)
54
- .with_boolean_query("year:2000")
54
+ .as_boolean_query
55
+ .with_query("year:2000")
55
56
  .search
56
57
  ```
57
58
 
@@ -6,6 +6,7 @@ module CloudSearch
6
6
 
7
7
  def initialize
8
8
  @response = SearchResponse.new
9
+ @filters = []
9
10
  end
10
11
 
11
12
  def search
@@ -21,9 +22,13 @@ module CloudSearch
21
22
  self
22
23
  end
23
24
 
24
- def with_boolean_query(query)
25
+ def with_filter(filter)
26
+ @filters << filter
27
+ self
28
+ end
29
+
30
+ def as_boolean_query
25
31
  @boolean = true
26
- with_query query
27
32
  self
28
33
  end
29
34
 
@@ -70,6 +75,7 @@ module CloudSearch
70
75
  "#{CloudSearch.config.search_url}/search".tap do |u|
71
76
  u.concat("?#{query_parameter}=#{query}&size=#{items_per_page}&start=#{start}")
72
77
  u.concat("&return-fields=#{URI.escape(@fields.join(","))}") if @fields && @fields.any?
78
+ u.concat("&#{filter_expression}") if @filters.any?
73
79
  end
74
80
  end
75
81
 
@@ -78,6 +84,10 @@ module CloudSearch
78
84
  def query_parameter
79
85
  boolean_query? ? "bq" : "q"
80
86
  end
87
+
88
+ def filter_expression
89
+ @filters.join("&")
90
+ end
81
91
  end
82
92
  end
83
93
 
@@ -1,3 +1,3 @@
1
1
  module CloudSearch
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -27,25 +27,33 @@ describe CloudSearch::Searcher do
27
27
  subject.with_query("foo")
28
28
  subject.query.should == "foo"
29
29
  end
30
+
31
+ it "returns cloud search url with foo query" do
32
+ subject.with_query("foo").url.should == "#{url_prefix}q=foo&size=10&start=0"
33
+ end
34
+
35
+ it "returns cloud search url with foo query" do
36
+ subject.with_query("f&oo").url.should == "#{url_prefix}q=f%26oo&size=10&start=0"
37
+ end
38
+
39
+ it "returns cloud search url with foo* query" do
40
+ subject.with_query("foo*").url.should == "#{url_prefix}q=foo*&size=10&start=0"
41
+ end
30
42
  end
31
43
 
32
- describe "#with_boolean_query" do
44
+ describe "#as_boolean_query" do
33
45
  it "sets the query mode to 'boolean'" do
34
- subject.with_boolean_query("year:2000")
46
+ subject.as_boolean_query
35
47
  subject.should be_boolean_query
36
48
  end
37
49
 
38
50
  it "returns the searcher instance" do
39
- subject.with_boolean_query("year:2000").should == subject
40
- end
41
-
42
- it "sets the query term" do
43
- subject.with_boolean_query("year:2000")
44
- subject.query.should == "year:2000"
51
+ subject.as_boolean_query.should == subject
45
52
  end
46
53
 
47
54
  it "uses 'bq' to specify the query in the URL" do
48
- subject.with_boolean_query("year:2000")
55
+ subject.as_boolean_query
56
+ subject.with_query("year:2000")
49
57
  subject.url.should == "#{url_prefix}bq=year:2000&size=10&start=0"
50
58
  end
51
59
  end
@@ -58,6 +66,10 @@ describe CloudSearch::Searcher do
58
66
  it "setup more thane one value" do
59
67
  subject.with_fields(:foo, :bar, :foobar)
60
68
  end
69
+
70
+ it "returns cloud search url with foo and bar fields" do
71
+ subject.with_fields(:foo, :bar).url.should == "#{url_prefix}q=&size=10&start=0&return-fields=foo,bar"
72
+ end
61
73
  end
62
74
 
63
75
  describe "#items_per_page" do
@@ -80,6 +92,10 @@ describe CloudSearch::Searcher do
80
92
  subject.with_items_per_page(100)
81
93
  subject.items_per_page.should == 100
82
94
  end
95
+
96
+ it "returns cloud search url with size equals 20" do
97
+ subject.with_items_per_page(20).url.should == "#{url_prefix}q=&size=20&start=0"
98
+ end
83
99
  end
84
100
 
85
101
  describe "#page_number" do
@@ -110,6 +126,22 @@ describe CloudSearch::Searcher do
110
126
  subject.at_page(-1)
111
127
  subject.page_number.should == 1
112
128
  end
129
+
130
+ it "returns cloud search url with start at 11" do
131
+ subject.at_page(2).url.should == "#{url_prefix}q=&size=10&start=11"
132
+ end
133
+ end
134
+
135
+ describe "#with_filter" do
136
+ it "adds the filter to the query" do
137
+ subject.with_query("foo").with_filter("t-product_active=1")
138
+ subject.url.should == "#{url_prefix}q=foo&size=10&start=0&t-product_active=1"
139
+ end
140
+
141
+ it "can be used to add several filter expressions to the query" do
142
+ subject.with_query("foo").with_filter("t-product_active=1").with_filter("t-brand_active=1")
143
+ subject.url.should == "#{url_prefix}q=foo&size=10&start=0&t-product_active=1&t-brand_active=1"
144
+ end
113
145
  end
114
146
 
115
147
  describe "#start" do
@@ -127,30 +159,6 @@ describe CloudSearch::Searcher do
127
159
  it "returns default cloud search url" do
128
160
  subject.url.should == "#{url_prefix}q=&size=10&start=0"
129
161
  end
130
-
131
- it "returns cloud search url with foo query" do
132
- subject.with_query("foo").url.should == "#{url_prefix}q=foo&size=10&start=0"
133
- end
134
-
135
- it "returns cloud search url with foo query" do
136
- subject.with_query("f&oo").url.should == "#{url_prefix}q=f%26oo&size=10&start=0"
137
- end
138
-
139
- it "returns cloud search url with foo* query" do
140
- subject.with_query("foo*").url.should == "#{url_prefix}q=foo*&size=10&start=0"
141
- end
142
-
143
- it "returns cloud search url with size equals 20" do
144
- subject.with_items_per_page(20).url.should == "#{url_prefix}q=&size=20&start=0"
145
- end
146
-
147
- it "returns cloud search url with start at 19" do
148
- subject.at_page(2).url.should == "#{url_prefix}q=&size=10&start=11"
149
- end
150
-
151
- it "returns cloud search url with foo and bar fields" do
152
- subject.with_fields(:foo, :bar).url.should == "#{url_prefix}q=&size=10&start=0&return-fields=foo,bar"
153
- end
154
162
  end
155
163
 
156
164
  describe "#search" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: