asari 0.10.0 → 0.10.1
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.
- checksums.yaml +4 -4
- data/README.md +17 -2
- data/lib/asari.rb +7 -3
- data/lib/asari/geography.rb +5 -5
- data/lib/asari/version.rb +1 -1
- data/spec/geography_spec.rb +7 -7
- data/spec/search_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c3b4f8b5b8bfcf0c57a73a1166fc8c4937d1b9a
|
4
|
+
data.tar.gz: ce62113fd651f0b4a0d904a3a9b977de3fdf6b09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 230b8c490d07f061b1a94decdc0a38c82b7155209312ac85fe15e0402bf9b5ea96ab4242b87108978258bec18d9f0e9cb3b8f115cb92d4d04055263e742a372c
|
7
|
+
data.tar.gz: 748909669f060872abe47f4cc54b7c50d8080c76d08c13496e89829051931fa64d8b2fec859ce1d8b76fe7b0319c6a43ded3f8166420414df6628f8e2b9657ec
|
data/README.md
CHANGED
@@ -28,12 +28,27 @@ Amazon Cloud Search will give you a Search Endpoint and Document Endpoint. When
|
|
28
28
|
#### Boolean Query Usage
|
29
29
|
|
30
30
|
asari.search(filter: { and: { title: "donut", type: "cruller" }})
|
31
|
-
asari.search("boston creme", filter: { and: { title: "donut", or: { type: "cruller",
|
32
|
-
type: "twist" }}}) # Full text search and nested boolean logic
|
31
|
+
asari.search("boston creme", filter: { and: { title: "donut", or: { type: "cruller", type: "twist" }}}) # Full text search and nested boolean logic
|
33
32
|
|
34
33
|
For more information on how to use Cloudsearch boolean queries, [see the
|
35
34
|
documentation.](http://docs.aws.amazon.com/cloudsearch/latest/developerguide/booleansearch.html)
|
36
35
|
|
36
|
+
### Geospatial Query Usage
|
37
|
+
|
38
|
+
While Cloudsearch does not natively support location search, you can implement rudimentary location search by representing latitude and longitude as integers in your search domain. Asari has a Geography module you can use to simplify the conversion of latitude and longitude to cartesian coordinates as well as the generation of a coordinate box to search within. Asari's Boolean Query syntax can then be used to search within the area. Note that because Cloudsearch only supports 32-bit unsigned integers, it is only possible to store latitude and longitude to two place values. This means very precise search isn't possible using Asari and Cloudsearch.
|
39
|
+
|
40
|
+
coordinates = Asari::Geography.degrees_to_int(lat: 45.52, lng: 122.68)
|
41
|
+
#=> { lat: 2506271416, lng: 111298648 }
|
42
|
+
asari.add_item("1", { name: "Tommy Morgan", lat: coordinates[:lat], lng: coordinates[:lng] })
|
43
|
+
#=> nil
|
44
|
+
coordinate_box = Asari::Geography.coordinate_box(lat: 45.2, lng: 122.85, meters: 7500)
|
45
|
+
#=> { lat: 2505521415..2507021417, lng: 111263231..111334065 }
|
46
|
+
asari.search("tommy", filter: { and: coordinate_box }
|
47
|
+
#=> ["1"] = a list of document IDs
|
48
|
+
|
49
|
+
For more information on how to use Cloudsearch for location search, [see the
|
50
|
+
documentation.](http://docs.aws.amazon.com/cloudsearch/latest/developerguide/geosearch.html)
|
51
|
+
|
37
52
|
#### Sandbox Mode
|
38
53
|
|
39
54
|
Because there is no "local" version of CloudSearch, and search instances can be
|
data/lib/asari.rb
CHANGED
@@ -89,13 +89,13 @@ class Asari
|
|
89
89
|
begin
|
90
90
|
response = HTTParty.get(url)
|
91
91
|
rescue Exception => e
|
92
|
-
ae = Asari::SearchException.new("#{e.class}: #{e.message}")
|
92
|
+
ae = Asari::SearchException.new("#{e.class}: #{e.message} (#{url})")
|
93
93
|
ae.set_backtrace e.backtrace
|
94
94
|
raise ae
|
95
95
|
end
|
96
96
|
|
97
97
|
unless response.response.code == "200"
|
98
|
-
raise Asari::SearchException.new("#{response.response.code}: #{response.response.msg}")
|
98
|
+
raise Asari::SearchException.new("#{response.response.code}: #{response.response.msg} (#{url})")
|
99
99
|
end
|
100
100
|
|
101
101
|
Asari::Collection.new(response, page_size)
|
@@ -202,7 +202,11 @@ class Asari
|
|
202
202
|
sub_query = reduce.call(value)
|
203
203
|
memo += "(#{key}#{sub_query})" unless sub_query.empty?
|
204
204
|
else
|
205
|
-
|
205
|
+
if value.is_a?(Range) || value.is_a?(Integer)
|
206
|
+
memo += " #{key}:#{value}"
|
207
|
+
else
|
208
|
+
memo += " #{key}:'#{value}'" unless value.to_s.empty?
|
209
|
+
end
|
206
210
|
end
|
207
211
|
memo
|
208
212
|
end
|
data/lib/asari/geography.rb
CHANGED
@@ -10,7 +10,7 @@ class Asari
|
|
10
10
|
|
11
11
|
class << self
|
12
12
|
|
13
|
-
# Public: Converts coordinates to unsigned integers that store up to
|
13
|
+
# Public: Converts coordinates to unsigned integers that store up to two
|
14
14
|
# place values.
|
15
15
|
#
|
16
16
|
# options - the options hash requires:
|
@@ -87,21 +87,21 @@ class Asari
|
|
87
87
|
|
88
88
|
private
|
89
89
|
def latitude_to_int(degrees)
|
90
|
-
((degrees + 180) * METERS_PER_DEGREE_OF_LATITUDE *
|
90
|
+
((degrees + 180) * METERS_PER_DEGREE_OF_LATITUDE * 100).round
|
91
91
|
end
|
92
92
|
|
93
93
|
def latitude_to_degrees(int)
|
94
|
-
((int / METERS_PER_DEGREE_OF_LATITUDE /
|
94
|
+
((int / METERS_PER_DEGREE_OF_LATITUDE / 100.0) - 180).round(3)
|
95
95
|
end
|
96
96
|
|
97
97
|
def longitude_to_int(degrees, latitude)
|
98
98
|
meters = meters_per_degree_of_longitude(latitude)
|
99
|
-
((degrees + 180) * meters *
|
99
|
+
((degrees + 180) * meters * 100).round
|
100
100
|
end
|
101
101
|
|
102
102
|
def longitude_to_degrees(int, latitude_in_degrees)
|
103
103
|
meters = meters_per_degree_of_longitude(latitude_in_degrees)
|
104
|
-
((int / meters /
|
104
|
+
((int / meters / 100.0) - 180).round(3)
|
105
105
|
end
|
106
106
|
|
107
107
|
def meters_per_degree_of_longitude(latitude)
|
data/lib/asari/version.rb
CHANGED
data/spec/geography_spec.rb
CHANGED
@@ -6,25 +6,25 @@ describe Asari::Geography do
|
|
6
6
|
|
7
7
|
describe "#degrees_to_int" do
|
8
8
|
it "converts standard lat and lng to integers" do
|
9
|
-
result = convert.degrees_to_int(lat: 45.52, lng: 122.
|
10
|
-
expect(result).to eq({ lat:
|
9
|
+
result = convert.degrees_to_int(lat: 45.52, lng: 122.68)
|
10
|
+
expect(result).to eq({ lat: 2506271416, lng: 111298648 })
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "#int_to_degrees" do
|
15
15
|
it "converts back successfully" do
|
16
|
-
integers = convert.degrees_to_int(lat: -45.52, lng: 122.
|
16
|
+
integers = convert.degrees_to_int(lat: -45.52, lng: 122.68)
|
17
17
|
result = convert.int_to_degrees(integers)
|
18
|
-
expect(result).to eq({ lat: -45.52, lng: 122.
|
18
|
+
expect(result).to eq({ lat: -45.52, lng: 122.68 })
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
describe "#coordinate_box" do
|
23
|
-
it "creates a range from a coordinate and a distance in
|
23
|
+
it "creates a range from a coordinate and a distance in meters" do
|
24
24
|
result = convert.coordinate_box(lat: 45.52, lng: 122.682, meters: 5000)
|
25
25
|
expect(result).to eq({
|
26
|
-
lat:
|
27
|
-
lng:
|
26
|
+
lat: 2505771415..2506771417,
|
27
|
+
lng: 111275772..111322995
|
28
28
|
})
|
29
29
|
end
|
30
30
|
end
|
data/spec/search_spec.rb
CHANGED
@@ -143,4 +143,11 @@ describe Asari do
|
|
143
143
|
})
|
144
144
|
end
|
145
145
|
end
|
146
|
+
|
147
|
+
describe "geography searching" do
|
148
|
+
it "builds a proper query string" do
|
149
|
+
HTTParty.should_receive(:get).with("http://search-testdomain.us-east-1.cloudsearch.amazonaws.com/2011-02-01/search?q=&bq=%28and+lat%3A2505771415..2506771417+lng%3A111275735..111322958%29&size=10")
|
150
|
+
@asari.search filter: { and: Asari::Geography.coordinate_box(meters: 5000, lat: 45.52, lng: 122.6819) }
|
151
|
+
end
|
152
|
+
end
|
146
153
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asari
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tommy Morgan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|