cloud_search 0.1.4 → 0.1.5
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 +16 -0
- data/lib/cloud_search/searcher.rb +6 -0
- data/lib/cloud_search/version.rb +1 -1
- data/spec/cloud_search/searcher_spec.rb +10 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -66,6 +66,22 @@ resp = searcher.with_fields(:actor, :director, :title, :year, :text_relevanc
|
|
66
66
|
.search
|
67
67
|
```
|
68
68
|
|
69
|
+
### You can sort the result using a rank expression (previously created on your CloudSearch domain)
|
70
|
+
``` ruby
|
71
|
+
searcher = CloudSearch::Searcher.new
|
72
|
+
resp = searcher.with_fields(:actor, :director, :title, :year, :text_relevance)
|
73
|
+
.with_query("matrix")
|
74
|
+
.ranked_with("my_rank_expression")
|
75
|
+
```
|
76
|
+
|
77
|
+
If you want to rank using descending order, just prepend the expression name with a '-' sign:
|
78
|
+
|
79
|
+
``` ruby
|
80
|
+
resp = searcher.with_fields(:actor, :director, :title, :year, :text_relevance)
|
81
|
+
.with_query("matrix")
|
82
|
+
.ranked_with("-my_rank_expression")
|
83
|
+
```
|
84
|
+
|
69
85
|
## Results
|
70
86
|
``` ruby
|
71
87
|
resp.results.each do |result|
|
@@ -39,6 +39,11 @@ module CloudSearch
|
|
39
39
|
self
|
40
40
|
end
|
41
41
|
|
42
|
+
def ranked_by(rank_expression)
|
43
|
+
@rank = rank_expression
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
42
47
|
def query
|
43
48
|
return '' unless @query
|
44
49
|
URI.escape(@query).gsub('&', '%26')
|
@@ -84,6 +89,7 @@ module CloudSearch
|
|
84
89
|
u.concat("&return-fields=#{URI.escape(@fields.join(","))}") if @fields && @fields.any?
|
85
90
|
u.concat("&#{filter_expression}") if @filters.any?
|
86
91
|
u.concat("&#{weighted_fields_expression}") if @weights and !@weights.empty?
|
92
|
+
u.concat("&rank=#{@rank}") if @rank
|
87
93
|
end
|
88
94
|
end
|
89
95
|
|
data/lib/cloud_search/version.rb
CHANGED
@@ -41,6 +41,16 @@ describe CloudSearch::Searcher do
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
describe "#ranked_by" do
|
45
|
+
it "returns the instance" do
|
46
|
+
subject.ranked_by("foobar").should == subject
|
47
|
+
end
|
48
|
+
|
49
|
+
it "sets the rank expression in the searcher object" do
|
50
|
+
subject.ranked_by("foobar").url.should == "#{url_prefix}q=&size=10&start=0&rank=foobar"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
44
54
|
describe "#with_weights" do
|
45
55
|
before do
|
46
56
|
subject.with_query("star").with_weights(:title => 3, :description => 1, :default_weight => 0.5)
|
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.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pry
|
@@ -177,7 +177,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
177
177
|
version: '0'
|
178
178
|
segments:
|
179
179
|
- 0
|
180
|
-
hash:
|
180
|
+
hash: -2976671119341465962
|
181
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
182
|
none: false
|
183
183
|
requirements:
|
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
186
|
version: '0'
|
187
187
|
segments:
|
188
188
|
- 0
|
189
|
-
hash:
|
189
|
+
hash: -2976671119341465962
|
190
190
|
requirements: []
|
191
191
|
rubyforge_project:
|
192
192
|
rubygems_version: 1.8.24
|