waistband 0.8.5 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/LICENSE.txt +1 -1
- data/README.md +81 -63
- data/lib/waistband.rb +9 -8
- data/lib/waistband/configuration.rb +20 -9
- data/lib/waistband/errors.rb +9 -0
- data/lib/waistband/index.rb +177 -43
- data/lib/waistband/result.rb +21 -0
- data/lib/waistband/search_results.rb +53 -0
- data/lib/waistband/version.rb +1 -1
- data/spec/config/waistband/waistband.yml +6 -2
- data/spec/lib/configuration_spec.rb +17 -20
- data/spec/lib/index_spec.rb +75 -35
- data/spec/lib/result_spec.rb +41 -0
- data/spec/lib/search_results_spec.rb +124 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/index_helper.rb +3 -3
- data/waistband.gemspec +3 -5
- metadata +18 -24
- data/lib/waistband/connection.rb +0 -250
- data/lib/waistband/query.rb +0 -63
- data/lib/waistband/query_result.rb +0 -24
- data/lib/waistband/quick_error.rb +0 -9
- data/spec/lib/connection_spec.rb +0 -419
- data/spec/lib/query_result_spec.rb +0 -23
- data/spec/lib/query_spec.rb +0 -161
- data/spec/lib/stringified_array_spec.rb +0 -9
- data/spec/lib/stringified_hash_spec.rb +0 -27
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Waistband::QueryResult do
|
4
|
-
|
5
|
-
let(:hit) { {"_index"=>"search", "_type"=>"search", "_id"=>"task_14969", "_score"=>5.810753, "_source"=>{"id"=>14969, "name"=>"shopping"}} }
|
6
|
-
let(:result) { Waistband::QueryResult.new(hit) }
|
7
|
-
|
8
|
-
it "allows access to inner document" do
|
9
|
-
result.source.should eql hit['_source']
|
10
|
-
result._id.should eql 'task_14969'
|
11
|
-
result.score.should eql 5.810753
|
12
|
-
end
|
13
|
-
|
14
|
-
it "provides methods for source attributes" do
|
15
|
-
result.id.should eql 14969
|
16
|
-
result.name.should eql 'shopping'
|
17
|
-
end
|
18
|
-
|
19
|
-
it "returns nil if the method missing misses" do
|
20
|
-
result.something_else.should be_nil
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
data/spec/lib/query_spec.rb
DELETED
@@ -1,161 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Waistband::Query do
|
4
|
-
|
5
|
-
let(:index) { Waistband::Index.new('search') }
|
6
|
-
let(:geo_index) { Waistband::Index.new('geo') }
|
7
|
-
|
8
|
-
let(:query) { Waistband::Query.new(index) }
|
9
|
-
let(:geo_query) { Waistband::Query.new(geo_index) }
|
10
|
-
|
11
|
-
let(:attrs) do
|
12
|
-
{
|
13
|
-
'query' => {
|
14
|
-
'bool' => {
|
15
|
-
'must' => [
|
16
|
-
{
|
17
|
-
'multi_match' => {
|
18
|
-
'query' => "shopping ikea",
|
19
|
-
'fields' => ['name']
|
20
|
-
},
|
21
|
-
}
|
22
|
-
]
|
23
|
-
}
|
24
|
-
}
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
it "correclty forms a query hash" do
|
29
|
-
add_result!
|
30
|
-
query.prepare(attrs)
|
31
|
-
|
32
|
-
expect(query.instance_variable_get('@hash')).to eql(attrs)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "finds results for a query" do
|
36
|
-
add_result!
|
37
|
-
query.prepare(attrs)
|
38
|
-
json = query.send(:execute!)
|
39
|
-
|
40
|
-
json['hits'].should be_a Hash
|
41
|
-
json['hits']['total'].should > 0
|
42
|
-
json['hits']['hits'].size.should eql 2
|
43
|
-
|
44
|
-
hit = json['hits']['hits'].first
|
45
|
-
|
46
|
-
hit['_id'].should match(/^task_.*/)
|
47
|
-
hit['_source'].should be_a Hash
|
48
|
-
hit['_source']['id'].should eql 123123
|
49
|
-
hit['_source']['name'].should eql 'some shopping in ikea'
|
50
|
-
hit['_source']['user_id'].should eql 999
|
51
|
-
hit['_source']['description'].should eql 'i need you to pick up some stuff in ikea'
|
52
|
-
end
|
53
|
-
|
54
|
-
it "permits storing and fetching geo results" do
|
55
|
-
add_geo_results!
|
56
|
-
geo_query.prepare({
|
57
|
-
"query" => {
|
58
|
-
"filtered" => {
|
59
|
-
"query" => { "match_all" => {} },
|
60
|
-
"filter" => {
|
61
|
-
"geo_shape" => {
|
62
|
-
"work_area" => {
|
63
|
-
"relation" => "intersects",
|
64
|
-
"shape" => {
|
65
|
-
"type" => "Point",
|
66
|
-
"coordinates" => [-122.39455,37.7841]
|
67
|
-
}
|
68
|
-
}
|
69
|
-
}
|
70
|
-
}
|
71
|
-
}
|
72
|
-
}
|
73
|
-
})
|
74
|
-
|
75
|
-
json = geo_query.send(:execute!)
|
76
|
-
|
77
|
-
json['hits'].should be_a Hash
|
78
|
-
json['hits']['total'].should eql 3
|
79
|
-
json['hits']['hits'].size.should eql 3
|
80
|
-
|
81
|
-
geo_query.prepare({
|
82
|
-
"query" => {
|
83
|
-
"filtered" => {
|
84
|
-
"query" => { "match_all" => {} },
|
85
|
-
"filter" => {
|
86
|
-
"geo_shape" => {
|
87
|
-
"work_area" => {
|
88
|
-
"relation" => "intersects",
|
89
|
-
"shape" => {
|
90
|
-
"type" => "Point",
|
91
|
-
"coordinates" => [-122.3859222222222,37.78292222222222]
|
92
|
-
}
|
93
|
-
}
|
94
|
-
}
|
95
|
-
}
|
96
|
-
}
|
97
|
-
}
|
98
|
-
})
|
99
|
-
|
100
|
-
json = geo_query.send(:execute!)
|
101
|
-
|
102
|
-
json['hits'].should be_a Hash
|
103
|
-
json['hits']['total'].should eql 1
|
104
|
-
json['hits']['hits'].size.should eql 1
|
105
|
-
end
|
106
|
-
|
107
|
-
def add_result!
|
108
|
-
index.store!("task_123123", {id: 123123, name: 'some shopping in ikea', user_id: 999, description: 'i need you to pick up some stuff in ikea', internal: false})
|
109
|
-
index.store!("task_234234", {id: 234234, name: "some shopping in ikea and trader joe's", user_id: 987, description: 'pick me up some eggs', internal: true})
|
110
|
-
index.refresh
|
111
|
-
end
|
112
|
-
|
113
|
-
def add_geo_results!
|
114
|
-
geo_index.store!("rabbit_1", {
|
115
|
-
id: "rabbit_1",
|
116
|
-
work_area: {
|
117
|
-
type: 'polygon',
|
118
|
-
coordinates: [[
|
119
|
-
[-122.4119,37.78211],
|
120
|
-
[-122.39285,37.79649],
|
121
|
-
[-122.37997,37.78415],
|
122
|
-
[-122.39817,37.77248],
|
123
|
-
[-122.40932,37.77302],
|
124
|
-
[-122.4119,37.78211]
|
125
|
-
]]
|
126
|
-
}
|
127
|
-
})
|
128
|
-
|
129
|
-
geo_index.store!("rabbit_2", {
|
130
|
-
id: "rabbit_2",
|
131
|
-
work_area: {
|
132
|
-
type: 'polygon',
|
133
|
-
coordinates: [[
|
134
|
-
[-122.41087,37.78822],
|
135
|
-
[-122.43174,37.78578],
|
136
|
-
[-122.42816,37.75938],
|
137
|
-
[-122.38787,37.76882],
|
138
|
-
[-122.39199,37.78584],
|
139
|
-
[-122.41087,37.78822]
|
140
|
-
]]
|
141
|
-
}
|
142
|
-
})
|
143
|
-
|
144
|
-
geo_index.store!("rabbit_3", {
|
145
|
-
id: "rabbit_3",
|
146
|
-
work_area: {
|
147
|
-
type: 'polygon',
|
148
|
-
coordinates: [[
|
149
|
-
[-122.41997,37.79744],
|
150
|
-
[-122.39576,37.79975],
|
151
|
-
[-122.38461,37.78469],
|
152
|
-
[-122.40294,37.77738],
|
153
|
-
[-122.41997,37.79744]
|
154
|
-
]]
|
155
|
-
}
|
156
|
-
})
|
157
|
-
|
158
|
-
geo_index.refresh
|
159
|
-
end
|
160
|
-
|
161
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Waistband::StringifiedHash do
|
4
|
-
|
5
|
-
let(:hash) { Waistband::StringifiedHash.new }
|
6
|
-
|
7
|
-
it "stringifies everything in a hash" do
|
8
|
-
hash['name'] = :peter
|
9
|
-
hash['description'] = {'full' => 'ok'}
|
10
|
-
hash.stringify_all.should eql({'name' => 'peter', 'description' => "{\"full\"=>\"ok\"}"})
|
11
|
-
end
|
12
|
-
|
13
|
-
it "recurses" do
|
14
|
-
hash['name'] = :peter
|
15
|
-
hash['description'] = [1, 2, 3]
|
16
|
-
hash.stringify_all.should eql({'name' => 'peter', 'description' => "[1, 2, 3]"})
|
17
|
-
end
|
18
|
-
|
19
|
-
it "creates a stringified array from a hash" do
|
20
|
-
copy = Waistband::StringifiedHash.new_from({'name' => 'peter', 'description' => [1, 2, 3]})
|
21
|
-
copy.should be_a Waistband::StringifiedHash
|
22
|
-
copy['name'].should eql 'peter'
|
23
|
-
copy['description'].should eql [1, 2, 3]
|
24
|
-
copy.stringify_all.should eql({'name' => 'peter', 'description' => "[1, 2, 3]"})
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|