elasticord 1.0.4 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/config/boot.rb +2 -16
- data/config/initializers/elasticord.rb +7 -0
- data/lib/dash_overlord/models/v1/dynamo_db/base.rb +18 -11
- data/lib/dash_overlord/models/v1/dynamo_db/scan.rb +22 -17
- data/lib/dash_overlord/models/v1/{elastic_search.rb → elastic_search/base.rb} +4 -2
- data/lib/dash_overlord/models/v1/elastic_search/bee_video.rb +15 -0
- data/lib/dash_overlord/use_cases/v1/repositories/dynamo_db/search_and_paginate/base.rb +3 -1
- data/lib/dash_overlord/use_cases/v1/videos/import/from_postgres_to_elastic_search/base.rb +32 -0
- data/lib/dash_overlord/use_cases/v1/videos/import/from_postgres_to_elastic_search/delete_elastic_search_records.rb +23 -0
- data/lib/dash_overlord/use_cases/v1/videos/import/from_postgres_to_elastic_search/parse_hhc_bee_video.rb +21 -0
- data/lib/dash_overlord/use_cases/v1/videos/import/from_postgres_to_elastic_search/store_bee_video.rb +37 -0
- data/lib/dash_overlord/use_cases/v1/videos/index/base.rb +1 -1
- data/lib/dash_overlord/use_cases/v1/videos/index/dynamodb/search_and_paginate_videos.rb +1 -1
- data/lib/dash_overlord/use_cases/v1/videos/index/elastic_search/base.rb +1 -0
- data/lib/dash_overlord/use_cases/v1/videos/index/elastic_search/search_and_paginate_videos.rb +11 -1
- data/lib/dash_overlord/use_cases/v1/videos/index/postgres/get_filters.rb +1 -2
- data/lib/dash_overlord/use_cases/v1/videos/index/postgres/search_and_paginate_videos.rb +2 -1
- data/lib/dash_overlord/use_cases/v1/videos/index/postgres/search_on_subtitle_lines.rb +2 -1
- data/lib/elasticord.rb +0 -4
- data/lib/elasticord/client/base.rb +3 -1
- data/lib/elasticord/client/search_builder.rb +35 -6
- data/lib/elasticord/version.rb +1 -1
- data/spec/dash_overlord/use_cases/v1/videos/index/dynamo_db_spec.rb +68 -66
- data/spec/dash_overlord/use_cases/v1/videos/index/elastic_search_spec.rb +28 -22
- data/spec/dash_overlord/use_cases/v1/videos/index/postgres_spec.rb +2 -2
- data/spec/elasticord/base_spec.rb +14 -12
- data/spec/elasticord/client/base_spec.rb +4 -4
- data/spec/elasticord/client/search_builder_spec.rb +21 -23
- data/spec/spec_helper.rb +3 -5
- metadata +9 -4
- data/lib/dash_overlord/models/v1/answer.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc79df0348d2af67fe3b48daf37b032356a5047d
|
4
|
+
data.tar.gz: 667711293ae4e3395b688c49121bc273c8f38701
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bebc8fa99c4adff7c2be20515d1d479abc002a850680bbc9dc3f53f120156a38bb112a06ec80245923db2b5f38b7c2e100d9795ac71ab45c4ed219f9859ea16e
|
7
|
+
data.tar.gz: da6a8bf8bf8aba80b42e06533c953c1c09aa7ebb0a50b6bc77c607d266a4f6c9aa18661fae8dffba9decd8c32592fc6aa60b410c8dcc5a33127c5c2e94300f42
|
data/Gemfile.lock
CHANGED
data/config/boot.rb
CHANGED
@@ -15,25 +15,11 @@ require 'dash_overlord'
|
|
15
15
|
DashOverlord::V1.configure do |config|
|
16
16
|
config.set(:env, ENV.fetch('ENV'))
|
17
17
|
config.set(:db_config, ENV.fetch('DASH_OVERLORD_V1_DATABASE_URL'))
|
18
|
-
|
19
|
-
config.set(:dynamodb_access_key, ENV.fetch('DASH_OVERLORD_DYNAMODB_ACCESS_KEY'))
|
20
|
-
config.set(:dynamodb_secret_key, ENV.fetch('DASH_OVERLORD_DYNAMODB_SECRET_KEY'))
|
21
|
-
config.set(:dynamodb_region, ENV.fetch('DASH_OVERLORD_DYNAMODB_REGION'))
|
22
18
|
end
|
23
19
|
|
24
20
|
DashOverlord::Models::V1::Base.establish_connection \
|
25
21
|
DashOverlord::V1::Config.get(:db_config)
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
DashOverlord::V1::Config.get(:dynamodb_access_key),
|
30
|
-
DashOverlord::V1::Config.get(:dynamodb_secret_key)
|
31
|
-
)
|
32
|
-
|
33
|
-
Aws.config.update({
|
34
|
-
region: "us-west-2",
|
35
|
-
endpoint: "http://localhost:8000",
|
36
|
-
credentials: credentials
|
37
|
-
})
|
38
|
-
|
23
|
+
Dir[File.expand_path('../initializers/**{,/*/**}/*.rb', __FILE__)].each do |f|
|
24
|
+
require f
|
39
25
|
end
|
@@ -10,8 +10,10 @@ module DashOverlord
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.create_all(items)
|
13
|
-
|
14
|
-
|
13
|
+
items.each_slice(25) do |batch|
|
14
|
+
client.batch_write_item \
|
15
|
+
create_all_params(batch)
|
16
|
+
end
|
15
17
|
end
|
16
18
|
|
17
19
|
def self.create(attributes = {})
|
@@ -37,17 +39,22 @@ module DashOverlord
|
|
37
39
|
resource_class: self
|
38
40
|
end
|
39
41
|
|
40
|
-
def
|
41
|
-
|
42
|
-
current_page: page,
|
43
|
-
last_evaluated_key: last_evaluated_key,
|
44
|
-
client: client,
|
45
|
-
table_name: table_name,
|
46
|
-
resource_class: self
|
47
|
-
|
42
|
+
def result(args)
|
43
|
+
self
|
48
44
|
end
|
49
45
|
|
50
|
-
def self.
|
46
|
+
# def self.page(page, last_evaluated_key)
|
47
|
+
# DynamoDb::Scan.new \
|
48
|
+
# current_page: page,
|
49
|
+
# last_evaluated_key: last_evaluated_key,
|
50
|
+
# client: client,
|
51
|
+
# table_name: table_name,
|
52
|
+
# resource_class: self
|
53
|
+
# end
|
54
|
+
|
55
|
+
def self.ransack(filters)
|
56
|
+
return unless filters
|
57
|
+
|
51
58
|
DynamoDb::Scan.new \
|
52
59
|
client: client,
|
53
60
|
table_name: table_name,
|
@@ -4,30 +4,30 @@ module DashOverlord
|
|
4
4
|
module DynamoDb
|
5
5
|
class Scan < DynamoDb::Base
|
6
6
|
# resource.page(page).per(per_page)
|
7
|
-
def
|
7
|
+
def ransack(filters)
|
8
8
|
self.filters = filters
|
9
9
|
|
10
10
|
self
|
11
11
|
end
|
12
12
|
|
13
|
-
def page(page, last_evaluated_key)
|
14
|
-
|
15
|
-
|
13
|
+
# def page(page, last_evaluated_key)
|
14
|
+
# self.current_page = page
|
15
|
+
# self.last_evaluated_key = last_evaluated_key
|
16
16
|
|
17
|
-
|
18
|
-
end
|
17
|
+
# self
|
18
|
+
# end
|
19
|
+
|
20
|
+
# def per(per_page)
|
21
|
+
# self.limit = per_page
|
19
22
|
|
20
|
-
|
21
|
-
|
23
|
+
# self
|
24
|
+
# end
|
22
25
|
|
26
|
+
def result(distinct)
|
23
27
|
self
|
24
28
|
end
|
25
29
|
|
26
|
-
def
|
27
|
-
if paginated_scan
|
28
|
-
return scan_page
|
29
|
-
end
|
30
|
-
|
30
|
+
def load
|
31
31
|
scan_all
|
32
32
|
end
|
33
33
|
|
@@ -38,7 +38,7 @@ module DashOverlord
|
|
38
38
|
items = []
|
39
39
|
|
40
40
|
loop do
|
41
|
-
result = client.
|
41
|
+
result = client.query(scan_params)
|
42
42
|
items += result.items
|
43
43
|
|
44
44
|
break unless result.last_evaluated_key
|
@@ -54,7 +54,7 @@ module DashOverlord
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def scan_page
|
57
|
-
result = client.
|
57
|
+
result = client.query(params)
|
58
58
|
|
59
59
|
DynamoDb::PaginatedResult.new \
|
60
60
|
items: result.items.map{ |item| resource_class.new(item) },
|
@@ -75,9 +75,14 @@ module DashOverlord
|
|
75
75
|
return {} unless filters
|
76
76
|
|
77
77
|
initial_params = {
|
78
|
+
key_condition_expression: "#dashboard_id = :dashboard_id",
|
78
79
|
filter_expression: [],
|
79
|
-
expression_attribute_names: {
|
80
|
-
|
80
|
+
expression_attribute_names: {
|
81
|
+
"#dashboard_id" => "dashboard_id"
|
82
|
+
},
|
83
|
+
expression_attribute_values: {
|
84
|
+
':dashboard_id' => 1
|
85
|
+
}
|
81
86
|
}
|
82
87
|
|
83
88
|
filters_mapped = \
|
@@ -18,9 +18,11 @@ module DashOverlord
|
|
18
18
|
context.resource = resource
|
19
19
|
|
20
20
|
invoke! ApplyFilters
|
21
|
-
invoke! ApplyPagination
|
22
21
|
|
22
|
+
# invoke! ApplyPagination
|
23
|
+
puts "Before executing... #{DateTime.now}"
|
23
24
|
context.resource = context.resource.execute
|
25
|
+
puts "After executing... #{DateTime.now}"
|
24
26
|
|
25
27
|
context.meta = Entities::V1::MetaData.new \
|
26
28
|
context.attributes.slice :page,
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module DashOverlord
|
2
|
+
module UseCases
|
3
|
+
module V1
|
4
|
+
module Videos
|
5
|
+
module Import
|
6
|
+
module FromPostgresToElasticSearch
|
7
|
+
|
8
|
+
# DashOverlord::UseCases::V1::Videos::Import::FromPostgresToElasticSearch::Base.perform
|
9
|
+
class Base < V1::Base
|
10
|
+
context_reader :segment_uid
|
11
|
+
|
12
|
+
def perform
|
13
|
+
context.segment_uid = 'hhc'
|
14
|
+
|
15
|
+
invoke! DeleteElasticSearchBeeVideos
|
16
|
+
|
17
|
+
postgres_bee_videos.each do |postgres_bee_video|
|
18
|
+
invoke! StoreBeeVideo, postgres_bee_video: postgres_bee_video
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def postgres_bee_videos
|
23
|
+
Models::V1::BeeVideo.where(segment_uid: segment_uid)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module DashOverlord
|
2
|
+
module UseCases
|
3
|
+
module V1
|
4
|
+
module Videos
|
5
|
+
module Import
|
6
|
+
module FromPostgresToElasticSearch
|
7
|
+
|
8
|
+
class DeleteElasticSearchBeeVideos < V1::Base
|
9
|
+
context_reader :segment_uid
|
10
|
+
|
11
|
+
def perform
|
12
|
+
DashOverlord::Models::V1::ElasticSearch::BeeVideo
|
13
|
+
.by_dashboard('hhc')
|
14
|
+
.delete_all
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module DashOverlord
|
2
|
+
module UseCases
|
3
|
+
module V1
|
4
|
+
module Videos
|
5
|
+
module Import
|
6
|
+
module FromPostgresToElasticSearch
|
7
|
+
|
8
|
+
module ParseHhcBeeVideo
|
9
|
+
module_function
|
10
|
+
|
11
|
+
def run(postgres_bee_video)
|
12
|
+
postgres_bee_video.attributes
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/dash_overlord/use_cases/v1/videos/import/from_postgres_to_elastic_search/store_bee_video.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module DashOverlord
|
2
|
+
module UseCases
|
3
|
+
module V1
|
4
|
+
module Videos
|
5
|
+
module Import
|
6
|
+
module FromPostgresToElasticSearch
|
7
|
+
|
8
|
+
class StoreBeeVideo < V1::Base
|
9
|
+
context_reader :segment_uid, :postgres_bee_video
|
10
|
+
|
11
|
+
def perform
|
12
|
+
# results = DashOverlord::Models::V1::ElasticSearch::BeeVideo.by_dashboard('hhc').search
|
13
|
+
|
14
|
+
Models::V1::ElasticSearch::BeeVideo
|
15
|
+
.by_dashboard(segment_uid)
|
16
|
+
.create bee_video_attributes
|
17
|
+
end
|
18
|
+
|
19
|
+
def bee_video_attributes
|
20
|
+
attributes = postgres_bee_video.attributes.dup
|
21
|
+
|
22
|
+
attributes.delete(:extra)
|
23
|
+
|
24
|
+
attributes.merge!(postgres_bee_video.extra || {})
|
25
|
+
|
26
|
+
attributes[:title] = "#{attributes['country']}, #{attributes['category']}"
|
27
|
+
|
28
|
+
attributes
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -5,7 +5,7 @@ module DashOverlord
|
|
5
5
|
module Index
|
6
6
|
module DynamoDb
|
7
7
|
|
8
|
-
class SearchAndPaginateVideos <
|
8
|
+
class SearchAndPaginateVideos < Shared::SearchAndPaginate::Base
|
9
9
|
def perform
|
10
10
|
context.videos = search_and_paginate(resource_class)
|
11
11
|
end
|
data/lib/dash_overlord/use_cases/v1/videos/index/elastic_search/search_and_paginate_videos.rb
CHANGED
@@ -6,8 +6,18 @@ module DashOverlord
|
|
6
6
|
module ElasticSearch
|
7
7
|
|
8
8
|
class SearchAndPaginateVideos < Shared::SearchAndPaginate::Base
|
9
|
+
context_reader :segment_uid
|
10
|
+
|
9
11
|
def perform
|
10
|
-
context.videos = search_and_paginate
|
12
|
+
context.videos = search_and_paginate bee_videos
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def bee_videos
|
18
|
+
Models::V1::ElasticSearch::BeeVideo
|
19
|
+
.by_dashboard(segment_uid)
|
20
|
+
.none
|
11
21
|
end
|
12
22
|
end
|
13
23
|
|
@@ -6,7 +6,7 @@ module DashOverlord
|
|
6
6
|
module Postgres
|
7
7
|
|
8
8
|
class SearchAndPaginateVideos < Shared::SearchAndPaginate::Base
|
9
|
-
context_reader :subtitle_lines
|
9
|
+
context_reader :subtitle_lines, :segment_uid
|
10
10
|
|
11
11
|
def perform
|
12
12
|
context.videos = search_and_paginate bee_videos
|
@@ -17,6 +17,7 @@ module DashOverlord
|
|
17
17
|
def bee_videos
|
18
18
|
scope = Models::V1::BeeVideo
|
19
19
|
.where(rejected_by_system: false)
|
20
|
+
.where(segment_uid: segment_uid)
|
20
21
|
.includes(:subtitle_lines)
|
21
22
|
|
22
23
|
return scope if subtitle_lines.blank?
|
@@ -6,7 +6,7 @@ module DashOverlord
|
|
6
6
|
module Postgres
|
7
7
|
|
8
8
|
class SearchOnSubtitleLines < V1::Base
|
9
|
-
context_reader :full_text_term
|
9
|
+
context_reader :full_text_term, :segment_uid
|
10
10
|
|
11
11
|
def perform
|
12
12
|
return if full_text_term.blank?
|
@@ -14,6 +14,7 @@ module DashOverlord
|
|
14
14
|
context.subtitle_lines =
|
15
15
|
Models::V1::SubtitleLine
|
16
16
|
.order(:start_time)
|
17
|
+
.where(segment_uid: segment_uid)
|
17
18
|
.ft(full_text_term)
|
18
19
|
end
|
19
20
|
end
|
data/lib/elasticord.rb
CHANGED
@@ -14,6 +14,8 @@ module Elasticord
|
|
14
14
|
elastic_search_client, entity, index, type
|
15
15
|
end
|
16
16
|
|
17
|
+
attr_reader :index, :type
|
18
|
+
|
17
19
|
def create(attributes = {})
|
18
20
|
result = Client::Create.one \
|
19
21
|
elastic_search_client, index, type, attributes
|
@@ -51,7 +53,7 @@ module Elasticord
|
|
51
53
|
|
52
54
|
protected
|
53
55
|
|
54
|
-
attr_reader :elastic_search_client, :entity
|
56
|
+
attr_reader :elastic_search_client, :entity
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
@@ -13,6 +13,8 @@ module Elasticord
|
|
13
13
|
elastic_search_client, entity, index, type
|
14
14
|
end
|
15
15
|
|
16
|
+
attr_reader :index, :type
|
17
|
+
|
16
18
|
def_delegators :results, :current_page, :per_page, :size, :from
|
17
19
|
|
18
20
|
def page(new_page)
|
@@ -59,13 +61,14 @@ module Elasticord
|
|
59
61
|
def ransack(ransack_filters = {})
|
60
62
|
return self unless ransack_filters
|
61
63
|
|
62
|
-
params =
|
64
|
+
params = body_params[:query][:bool]
|
63
65
|
|
64
66
|
ransack_filters.each do |key, value|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
67
|
+
if key['_eq_any']
|
68
|
+
add_should_clause(params, key, value)
|
69
|
+
elsif key['_eq']
|
70
|
+
add_must_clause(params, key, value)
|
71
|
+
end
|
69
72
|
end
|
70
73
|
|
71
74
|
self
|
@@ -77,7 +80,7 @@ module Elasticord
|
|
77
80
|
|
78
81
|
protected
|
79
82
|
|
80
|
-
attr_reader :elastic_search_client, :entity
|
83
|
+
attr_reader :elastic_search_client, :entity
|
81
84
|
|
82
85
|
def results
|
83
86
|
@results ||= ArrayWithMetaData.new \
|
@@ -92,6 +95,32 @@ module Elasticord
|
|
92
95
|
|
93
96
|
(hits && hits['total'].to_i > 0) ? hits : { 'hits' => [], 'total' => 0 }
|
94
97
|
end
|
98
|
+
|
99
|
+
def add_must_clause(params, key, value)
|
100
|
+
params[:must] ||= []
|
101
|
+
|
102
|
+
key = key.to_s.split('_eq').first.to_sym
|
103
|
+
|
104
|
+
add_term(params[:must], key, value)
|
105
|
+
end
|
106
|
+
|
107
|
+
def add_should_clause(params, key, values)
|
108
|
+
params[:boost] = 1.0
|
109
|
+
params[:should] ||= []
|
110
|
+
params[:minimum_should_match] = 1
|
111
|
+
|
112
|
+
key = key.to_s.split('_eq_any').first.to_sym
|
113
|
+
|
114
|
+
[*values].each { |value| add_term(params[:should], key, value) }
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def add_term(params, key, value)
|
120
|
+
value = value.downcase if value.is_a? String
|
121
|
+
|
122
|
+
params.push({ term: { key => value } })
|
123
|
+
end
|
95
124
|
end
|
96
125
|
end
|
97
126
|
end
|
data/lib/elasticord/version.rb
CHANGED
@@ -18,20 +18,22 @@ describe DashOverlord::UseCases::V1::Videos::Index::Base,
|
|
18
18
|
end
|
19
19
|
|
20
20
|
before(:all) do
|
21
|
-
migration = DashOverlord::Models::V1::DynamoDb::Migration.new \
|
22
|
-
|
21
|
+
# migration = DashOverlord::Models::V1::DynamoDb::Migration.new \
|
22
|
+
# DashOverlord::Models::V1::DynamoDb::Video
|
23
23
|
|
24
|
-
migration.create!
|
24
|
+
# migration.create!
|
25
25
|
|
26
26
|
end
|
27
27
|
|
28
28
|
after(:all) do
|
29
|
-
migration = DashOverlord::Models::V1::DynamoDb::Migration.new \
|
30
|
-
|
29
|
+
# migration = DashOverlord::Models::V1::DynamoDb::Migration.new \
|
30
|
+
# DashOverlord::Models::V1::DynamoDb::Video
|
31
31
|
|
32
|
-
migration.delete!
|
32
|
+
# migration.delete!
|
33
33
|
end
|
34
34
|
|
35
|
+
let(:number_of_records) { 20 }
|
36
|
+
|
35
37
|
def build_answer
|
36
38
|
{
|
37
39
|
"url": "https://s3-eu-west-1.amazonaws.com/streetbees-assets/dashboards/home_selfie/videos_1/11264-kitchen.MOV",
|
@@ -54,7 +56,7 @@ describe DashOverlord::UseCases::V1::Videos::Index::Base,
|
|
54
56
|
end
|
55
57
|
|
56
58
|
def create_answers
|
57
|
-
@videos =
|
59
|
+
@videos = number_of_records.times.map do |index|
|
58
60
|
build_answer.merge(
|
59
61
|
"id" => (index + 1),
|
60
62
|
"dashboard_id": 1
|
@@ -65,82 +67,82 @@ describe DashOverlord::UseCases::V1::Videos::Index::Base,
|
|
65
67
|
@videos
|
66
68
|
end
|
67
69
|
|
68
|
-
context 'when no filter params are used' do
|
69
|
-
|
70
|
-
|
70
|
+
# context 'when no filter params are used' do
|
71
|
+
# before do
|
72
|
+
# @current_user = create('v1/user', :unilever)
|
71
73
|
|
72
|
-
|
74
|
+
# create_answers
|
73
75
|
|
74
|
-
|
75
|
-
|
76
|
+
# make_the_call
|
77
|
+
# end
|
76
78
|
|
77
|
-
|
78
|
-
|
79
|
-
|
79
|
+
# it '@context.status should be ok' do
|
80
|
+
# expect(@context.status).to eq 'ok'
|
81
|
+
# end
|
80
82
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
83
|
+
# it 'should have the right ammount of data' do
|
84
|
+
# expect(DashOverlord::Models::V1::DynamoDb::Video.all.count) \
|
85
|
+
# .to eq(20)
|
86
|
+
# end
|
85
87
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
88
|
+
# it 'should return pagination meta_data' do
|
89
|
+
# expect(@context.meta.page).to be 1
|
90
|
+
# expect(@context.meta.per_page).to be 10
|
91
|
+
# end
|
90
92
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
93
|
+
# it 'should return 10 results' do
|
94
|
+
# expect(@context.videos.length).to be 10
|
95
|
+
# end
|
96
|
+
# end
|
95
97
|
|
96
|
-
context 'when filtering by page = 0' do
|
97
|
-
|
98
|
-
|
98
|
+
# context 'when filtering by page = 0' do
|
99
|
+
# before do
|
100
|
+
# @current_user = create('v1/user', :unilever)
|
99
101
|
|
100
|
-
|
102
|
+
# create_answers
|
101
103
|
|
102
|
-
|
103
|
-
|
104
|
+
# make_the_call page: 0
|
105
|
+
# end
|
104
106
|
|
105
|
-
|
106
|
-
|
107
|
-
|
107
|
+
# it '@context.status should be ok' do
|
108
|
+
# expect(@context.status).to eq 'ok'
|
109
|
+
# end
|
108
110
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
111
|
+
# it 'should return pagination meta_data' do
|
112
|
+
# expect(@context.meta.page).to be 0
|
113
|
+
# expect(@context.meta.per_page).to be 0
|
114
|
+
# end
|
113
115
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
end
|
116
|
+
# it 'should return 20 results', :cana do
|
117
|
+
# expect(@context.videos.length).to be 20
|
118
|
+
# end
|
119
|
+
# end
|
118
120
|
|
119
|
-
context 'when filtering by something' do
|
120
|
-
|
121
|
-
|
121
|
+
# context 'when filtering by something' do
|
122
|
+
# before do
|
123
|
+
# @current_user = create('v1/user', :unilever)
|
122
124
|
|
123
|
-
|
125
|
+
# create_answers
|
124
126
|
|
125
|
-
|
127
|
+
# @female_videos = @videos.select{|el| el[:gender] == "Female" }
|
126
128
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
129
|
+
# make_the_call \
|
130
|
+
# filter_query: {
|
131
|
+
# gender_eq: 'Female'
|
132
|
+
# }
|
133
|
+
# end
|
132
134
|
|
133
|
-
|
134
|
-
|
135
|
-
|
135
|
+
# it '@context.status should be ok' do
|
136
|
+
# expect(@context.status).to eq 'ok'
|
137
|
+
# end
|
136
138
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
139
|
+
# it 'should return pagination meta_data' do
|
140
|
+
# expect(@context.meta.page).to be 1
|
141
|
+
# expect(@context.meta.per_page).to be 10
|
142
|
+
# end
|
141
143
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
end
|
144
|
+
# it 'should return only filtered results', :focusrite do
|
145
|
+
# expect(@context.videos.length).to be @female_videos.count
|
146
|
+
# end
|
147
|
+
# end
|
146
148
|
end
|
@@ -2,8 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe DashOverlord::UseCases::V1::Videos::Index::ElasticSearch::Base,
|
4
4
|
elasticsearch: true do
|
5
|
+
def bee_video_client(segment_uid)
|
6
|
+
DashOverlord::Models::V1::ElasticSearch::BeeVideo.by_dashboard(segment_uid)
|
7
|
+
end
|
8
|
+
|
5
9
|
def make_the_call(params = nil)
|
6
|
-
|
10
|
+
bee_video_client(params[:segment_uid]).refresh_index
|
7
11
|
|
8
12
|
@context = described_class.perform \
|
9
13
|
(params || {}).merge({ session: user_session })
|
@@ -11,15 +15,15 @@ describe DashOverlord::UseCases::V1::Videos::Index::ElasticSearch::Base,
|
|
11
15
|
raise_context_unknown_error @context
|
12
16
|
end
|
13
17
|
|
14
|
-
def create_answer(attributes = {})
|
15
|
-
|
18
|
+
def create_answer(segment_uid, attributes = {})
|
19
|
+
bee_video_client(segment_uid).create attributes
|
16
20
|
end
|
17
21
|
|
18
22
|
context 'when no bee_videos are available' do
|
19
23
|
before(:all) do
|
20
|
-
|
24
|
+
bee_video_client('hhc').delete_all
|
21
25
|
|
22
|
-
make_the_call
|
26
|
+
make_the_call segment_uid: 'hhc'
|
23
27
|
end
|
24
28
|
|
25
29
|
it '@context.status should be ok' do
|
@@ -40,10 +44,11 @@ describe DashOverlord::UseCases::V1::Videos::Index::ElasticSearch::Base,
|
|
40
44
|
|
41
45
|
context 'when no filter params are used' do
|
42
46
|
before(:all) do
|
43
|
-
|
44
|
-
|
47
|
+
bee_video_client('hhc').delete_all
|
48
|
+
|
49
|
+
20.times { create_answer('hhc', title: 'Test') }
|
45
50
|
|
46
|
-
make_the_call
|
51
|
+
make_the_call segment_uid: 'hhc'
|
47
52
|
end
|
48
53
|
|
49
54
|
it '@context.status should be ok' do
|
@@ -62,12 +67,13 @@ describe DashOverlord::UseCases::V1::Videos::Index::ElasticSearch::Base,
|
|
62
67
|
end
|
63
68
|
end
|
64
69
|
|
65
|
-
context 'when filtering by page =
|
70
|
+
context 'when filtering by page = 3' do
|
66
71
|
before(:all) do
|
67
|
-
|
68
|
-
35.times { create_answer title: 'Test' }
|
72
|
+
bee_video_client('hhc').delete_all
|
69
73
|
|
70
|
-
|
74
|
+
35.times { create_answer('hhc', title: 'Test') }
|
75
|
+
|
76
|
+
make_the_call segment_uid: 'hhc', page: 3, per_page: 15
|
71
77
|
end
|
72
78
|
|
73
79
|
it '@context.status should be ok' do
|
@@ -75,31 +81,31 @@ describe DashOverlord::UseCases::V1::Videos::Index::ElasticSearch::Base,
|
|
75
81
|
end
|
76
82
|
|
77
83
|
it 'should return pagination meta_data' do
|
78
|
-
expect(@context.meta.page).to be
|
84
|
+
expect(@context.meta.page).to be 3
|
79
85
|
expect(@context.meta.per_page).to be 15
|
80
86
|
expect(@context.meta.total_pages).to be 3
|
81
87
|
expect(@context.meta.total_results).to be 35
|
82
88
|
end
|
83
89
|
|
84
|
-
it 'should return
|
85
|
-
expect(@context.videos.length).to be
|
90
|
+
it 'should return 5 results' do
|
91
|
+
expect(@context.videos.length).to be 5
|
86
92
|
end
|
87
93
|
end
|
88
94
|
|
89
95
|
context 'when filtering by something' do
|
90
96
|
before(:all) do
|
91
|
-
|
97
|
+
bee_video_client('hhc').delete_all
|
92
98
|
|
93
|
-
15.times { create_answer user_id: 1, gender: 'Female'
|
94
|
-
10.times { create_answer user_id: 1, gender: 'Male'
|
95
|
-
5.times { create_answer user_id: 1, gender: 'Female'
|
96
|
-
20.times { create_answer user_id: 2, gender: 'Female'
|
99
|
+
15.times { create_answer('laundry', user_id: 1, gender: 'Female') }
|
100
|
+
10.times { create_answer('hhc', user_id: 1, gender: 'Male') }
|
101
|
+
5.times { create_answer('hhc', user_id: 1, gender: 'Female') }
|
102
|
+
20.times { create_answer('hhc', user_id: 2, gender: 'Female') }
|
97
103
|
|
98
104
|
make_the_call \
|
105
|
+
segment_uid: 'hhc',
|
99
106
|
filter_query: {
|
100
107
|
user_id_eq: 1,
|
101
|
-
gender_eq: 'Female'
|
102
|
-
segment_uid_eq: 'hhc'
|
108
|
+
gender_eq: 'Female'
|
103
109
|
}
|
104
110
|
end
|
105
111
|
|
@@ -91,10 +91,10 @@ describe DashOverlord::UseCases::V1::Videos::Index::Postgres::Base do
|
|
91
91
|
20.times { create_bee_video(:female_hhc, user_id: 2) }
|
92
92
|
|
93
93
|
make_the_call \
|
94
|
+
segment_uid: 'hhc',
|
94
95
|
filter_query: {
|
95
96
|
user_id_eq: 1,
|
96
|
-
gender_eq: 'Female'
|
97
|
-
segment_uid_eq: 'hhc'
|
97
|
+
gender_eq: 'Female'
|
98
98
|
}
|
99
99
|
end
|
100
100
|
|
@@ -1,16 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Elasticord::Base, elasticsearch: true do
|
4
|
+
let(:index_namespace) { Elasticord::Config.get(:index_namespace) }
|
5
|
+
|
4
6
|
describe '.index' do
|
5
|
-
it 'described_class should return
|
6
|
-
expect(described_class.index).to eq
|
7
|
+
it 'described_class should return index_namespace' do
|
8
|
+
expect(described_class.index).to eq index_namespace
|
7
9
|
end
|
8
10
|
|
9
11
|
context 'given a child class' do
|
10
12
|
let(:child_class) { Class.new(described_class) }
|
11
13
|
|
12
|
-
it 'child_class should return the
|
13
|
-
expect(child_class.index).to eq
|
14
|
+
it 'child_class should return the index_namespace' do
|
15
|
+
expect(child_class.index).to eq index_namespace
|
14
16
|
end
|
15
17
|
|
16
18
|
context 'given that the child class sets a new index' do
|
@@ -18,8 +20,8 @@ describe Elasticord::Base, elasticsearch: true do
|
|
18
20
|
child_class.index = 'child_class_new_index'
|
19
21
|
end
|
20
22
|
|
21
|
-
it 'described_class should return
|
22
|
-
expect(described_class.index).to eq
|
23
|
+
it 'described_class should return index_namespace' do
|
24
|
+
expect(described_class.index).to eq index_namespace
|
23
25
|
end
|
24
26
|
|
25
27
|
it 'child_class should return "child_class_new_index"' do
|
@@ -63,12 +65,12 @@ describe Elasticord::Base, elasticsearch: true do
|
|
63
65
|
expect(@client.send(:entity)).to eq described_class
|
64
66
|
end
|
65
67
|
|
66
|
-
it 'reaturned client should have a
|
67
|
-
expect(@client.
|
68
|
+
it 'reaturned client should have a #index set up' do
|
69
|
+
expect(@client.index).to eq index_namespace
|
68
70
|
end
|
69
71
|
|
70
|
-
it 'reaturned client should have a
|
71
|
-
expect(@client.
|
72
|
+
it 'reaturned client should have a #type set up' do
|
73
|
+
expect(@client.type).to eq '_all'
|
72
74
|
end
|
73
75
|
end
|
74
76
|
|
@@ -86,7 +88,7 @@ describe Elasticord::Base, elasticsearch: true do
|
|
86
88
|
end
|
87
89
|
|
88
90
|
it 'reaturned client should have a protected #index set up' do
|
89
|
-
expect(@client.send(:index)).to eq "#{
|
91
|
+
expect(@client.send(:index)).to eq "#{index_namespace}_project_1"
|
90
92
|
end
|
91
93
|
|
92
94
|
it 'reaturned client should have a protected #type set up' do
|
@@ -108,7 +110,7 @@ describe Elasticord::Base, elasticsearch: true do
|
|
108
110
|
end
|
109
111
|
|
110
112
|
it 'reaturned client should have a protected #index set up' do
|
111
|
-
expect(@client.send(:index)).to eq "#{
|
113
|
+
expect(@client.send(:index)).to eq "#{index_namespace}_project_5"
|
112
114
|
end
|
113
115
|
|
114
116
|
it 'reaturned client should have a protected #type set up' do
|
@@ -101,12 +101,12 @@ describe Elasticord::Client::Base, elasticsearch: true do
|
|
101
101
|
expect(@search_builder.send(:entity)).to eq OpenStruct
|
102
102
|
end
|
103
103
|
|
104
|
-
it 'reaturned search_builder should have a
|
105
|
-
expect(@search_builder.
|
104
|
+
it 'reaturned search_builder should have a #index set up' do
|
105
|
+
expect(@search_builder.index).to eq ENV['ENV']
|
106
106
|
end
|
107
107
|
|
108
|
-
it 'reaturned search_builder should have a
|
109
|
-
expect(@search_builder.
|
108
|
+
it 'reaturned search_builder should have a #type set up' do
|
109
|
+
expect(@search_builder.type).to eq 'child_class'
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
@@ -55,13 +55,9 @@ describe Elasticord::Client::SearchBuilder, elasticsearch: true do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
describe '#page' do
|
58
|
-
def search_builder
|
59
|
-
@search_builder ||= described_instance
|
60
|
-
end
|
61
|
-
|
62
58
|
context 'sending 3 as an argument' do
|
63
59
|
before do
|
64
|
-
@result =
|
60
|
+
@result = described_instance.page(3)
|
65
61
|
end
|
66
62
|
|
67
63
|
it 'should return a SearchBuilder instance' do
|
@@ -79,13 +75,9 @@ describe Elasticord::Client::SearchBuilder, elasticsearch: true do
|
|
79
75
|
end
|
80
76
|
|
81
77
|
describe '#per' do
|
82
|
-
def search_builder
|
83
|
-
@search_builder ||= described_instance
|
84
|
-
end
|
85
|
-
|
86
78
|
context 'sending 15 as an argument' do
|
87
79
|
before do
|
88
|
-
@result =
|
80
|
+
@result = described_instance.per(15)
|
89
81
|
end
|
90
82
|
|
91
83
|
it 'should return a SearchBuilder instance' do
|
@@ -146,7 +138,7 @@ describe Elasticord::Client::SearchBuilder, elasticsearch: true do
|
|
146
138
|
end
|
147
139
|
end
|
148
140
|
|
149
|
-
context 'given that
|
141
|
+
context 'given that 35 records have been created' do
|
150
142
|
before do
|
151
143
|
client_base.delete_all
|
152
144
|
|
@@ -161,6 +153,10 @@ describe Elasticord::Client::SearchBuilder, elasticsearch: true do
|
|
161
153
|
client_base.create(title: 'child', brand: 'unoficial', locked: false)
|
162
154
|
end
|
163
155
|
|
156
|
+
5.times do
|
157
|
+
client_base.create(title: 'snow', brand: 'fake', locked: false)
|
158
|
+
end
|
159
|
+
|
164
160
|
client_base.refresh_index
|
165
161
|
end
|
166
162
|
|
@@ -170,8 +166,8 @@ describe Elasticord::Client::SearchBuilder, elasticsearch: true do
|
|
170
166
|
@search_result = described_instance.load({})
|
171
167
|
end
|
172
168
|
|
173
|
-
it 'should find
|
174
|
-
expect(@search_result.total_results).to be
|
169
|
+
it 'should find 35 total_results' do
|
170
|
+
expect(@search_result.total_results).to be 35
|
175
171
|
end
|
176
172
|
|
177
173
|
it 'should return a pagination object with 10 instances of the class' do
|
@@ -196,7 +192,7 @@ describe Elasticord::Client::SearchBuilder, elasticsearch: true do
|
|
196
192
|
context 'when #ransack with multiple query params was called' do
|
197
193
|
before do
|
198
194
|
@search_builder = @search_builder.ransack({
|
199
|
-
|
195
|
+
brand_eq_any: ['oficial', 'unoficial'],
|
200
196
|
locked_eq: false
|
201
197
|
})
|
202
198
|
|
@@ -207,8 +203,8 @@ describe Elasticord::Client::SearchBuilder, elasticsearch: true do
|
|
207
203
|
expect(@search_result.per_page).to be 15
|
208
204
|
expect(@search_result.total_pages).to be 2
|
209
205
|
expect(@search_result.current_page).to be 2
|
210
|
-
expect(@search_result.total_results).to be
|
211
|
-
expect(@search_result.length).to be
|
206
|
+
expect(@search_result.total_results).to be 29
|
207
|
+
expect(@search_result.length).to be 14
|
212
208
|
end
|
213
209
|
end
|
214
210
|
end
|
@@ -231,24 +227,26 @@ describe Elasticord::Client::SearchBuilder, elasticsearch: true do
|
|
231
227
|
end
|
232
228
|
end
|
233
229
|
|
234
|
-
context 'when
|
230
|
+
context 'when search for "uniq" and "any" values' do
|
235
231
|
before do
|
236
232
|
@search_result = described_instance.load \
|
237
233
|
query: {
|
238
234
|
bool: {
|
239
235
|
must: [
|
240
|
-
{
|
236
|
+
{ term: { locked: false } }
|
241
237
|
],
|
242
|
-
|
238
|
+
should: [
|
243
239
|
{ term: { brand: 'oficial' } },
|
244
|
-
{ term: {
|
245
|
-
]
|
240
|
+
{ term: { brand: 'unoficial' } }
|
241
|
+
],
|
242
|
+
minimum_should_match: 1,
|
243
|
+
boost: 1.0
|
246
244
|
}
|
247
245
|
}
|
248
246
|
end
|
249
247
|
|
250
|
-
it 'should find
|
251
|
-
expect(@search_result.total_results).to be
|
248
|
+
it 'should find 29 total_results' do
|
249
|
+
expect(@search_result.total_results).to be 29
|
252
250
|
end
|
253
251
|
|
254
252
|
it 'should return a pagination object with 10 resources' do
|
data/spec/spec_helper.rb
CHANGED
@@ -10,6 +10,9 @@ Dir[File.expand_path('../**/support/**/*.rb', __FILE__)].each do |file|
|
|
10
10
|
require file
|
11
11
|
end
|
12
12
|
|
13
|
+
Elasticord::Config.set(:log, false)
|
14
|
+
Elasticord::Config.set(:index_namespace, ENV['ENV'])
|
15
|
+
|
13
16
|
# I guess either "FactoryGirl" or "DatabaseCleaner" needs this line bellow
|
14
17
|
ActiveRecord::Base.establish_connection DashOverlord::V1::Config.get(:db_config)
|
15
18
|
|
@@ -34,11 +37,6 @@ RSpec.configure do |config|
|
|
34
37
|
DatabaseCleaner.clean
|
35
38
|
end
|
36
39
|
|
37
|
-
config.before(:each, elasticsearch: true) do
|
38
|
-
DashOverlord::Models::V1::ElasticSearch.delete_all
|
39
|
-
DashOverlord::Models::V1::ElasticSearch.refresh_index
|
40
|
-
end
|
41
|
-
|
42
40
|
BCrypt::Engine.cost = 1
|
43
41
|
end
|
44
42
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- StreetBees Dev Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- Rakefile
|
66
66
|
- bin/setup_config_files.sh
|
67
67
|
- config/boot.rb
|
68
|
+
- config/initializers/elasticord.rb
|
68
69
|
- dash_overlord.gemspec
|
69
70
|
- db/migrate/20160321174733_devise_create_users.rb
|
70
71
|
- db/migrate/20161014155300_create_bee_videos.rb
|
@@ -95,7 +96,6 @@ files:
|
|
95
96
|
- lib/dash_overlord/locales/v1/en/users.yml
|
96
97
|
- lib/dash_overlord/models/base.rb
|
97
98
|
- lib/dash_overlord/models/v1/admin.rb
|
98
|
-
- lib/dash_overlord/models/v1/answer.rb
|
99
99
|
- lib/dash_overlord/models/v1/base.rb
|
100
100
|
- lib/dash_overlord/models/v1/basic_user.rb
|
101
101
|
- lib/dash_overlord/models/v1/bee_video.rb
|
@@ -106,7 +106,8 @@ files:
|
|
106
106
|
- lib/dash_overlord/models/v1/dynamo_db/paginated_result.rb
|
107
107
|
- lib/dash_overlord/models/v1/dynamo_db/scan.rb
|
108
108
|
- lib/dash_overlord/models/v1/dynamo_db/video.rb
|
109
|
-
- lib/dash_overlord/models/v1/elastic_search.rb
|
109
|
+
- lib/dash_overlord/models/v1/elastic_search/base.rb
|
110
|
+
- lib/dash_overlord/models/v1/elastic_search/bee_video.rb
|
110
111
|
- lib/dash_overlord/models/v1/subtitle_line.rb
|
111
112
|
- lib/dash_overlord/models/v1/user.rb
|
112
113
|
- lib/dash_overlord/requirable.rb
|
@@ -217,6 +218,10 @@ files:
|
|
217
218
|
- lib/dash_overlord/use_cases/v1/users/show_current_user/find_current_user.rb
|
218
219
|
- lib/dash_overlord/use_cases/v1/users/show_current_user/get_current_user.rb
|
219
220
|
- lib/dash_overlord/use_cases/v1/users/update/base.rb
|
221
|
+
- lib/dash_overlord/use_cases/v1/videos/import/from_postgres_to_elastic_search/base.rb
|
222
|
+
- lib/dash_overlord/use_cases/v1/videos/import/from_postgres_to_elastic_search/delete_elastic_search_records.rb
|
223
|
+
- lib/dash_overlord/use_cases/v1/videos/import/from_postgres_to_elastic_search/parse_hhc_bee_video.rb
|
224
|
+
- lib/dash_overlord/use_cases/v1/videos/import/from_postgres_to_elastic_search/store_bee_video.rb
|
220
225
|
- lib/dash_overlord/use_cases/v1/videos/index/base.rb
|
221
226
|
- lib/dash_overlord/use_cases/v1/videos/index/dynamodb/base.rb
|
222
227
|
- lib/dash_overlord/use_cases/v1/videos/index/dynamodb/search_and_paginate_videos.rb
|