elasticord 1.0.4 → 1.0.6

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/config/boot.rb +2 -16
  4. data/config/initializers/elasticord.rb +7 -0
  5. data/lib/dash_overlord/models/v1/dynamo_db/base.rb +18 -11
  6. data/lib/dash_overlord/models/v1/dynamo_db/scan.rb +22 -17
  7. data/lib/dash_overlord/models/v1/{elastic_search.rb → elastic_search/base.rb} +4 -2
  8. data/lib/dash_overlord/models/v1/elastic_search/bee_video.rb +15 -0
  9. data/lib/dash_overlord/use_cases/v1/repositories/dynamo_db/search_and_paginate/base.rb +3 -1
  10. data/lib/dash_overlord/use_cases/v1/videos/import/from_postgres_to_elastic_search/base.rb +32 -0
  11. data/lib/dash_overlord/use_cases/v1/videos/import/from_postgres_to_elastic_search/delete_elastic_search_records.rb +23 -0
  12. data/lib/dash_overlord/use_cases/v1/videos/import/from_postgres_to_elastic_search/parse_hhc_bee_video.rb +21 -0
  13. data/lib/dash_overlord/use_cases/v1/videos/import/from_postgres_to_elastic_search/store_bee_video.rb +37 -0
  14. data/lib/dash_overlord/use_cases/v1/videos/index/base.rb +1 -1
  15. data/lib/dash_overlord/use_cases/v1/videos/index/dynamodb/search_and_paginate_videos.rb +1 -1
  16. data/lib/dash_overlord/use_cases/v1/videos/index/elastic_search/base.rb +1 -0
  17. data/lib/dash_overlord/use_cases/v1/videos/index/elastic_search/search_and_paginate_videos.rb +11 -1
  18. data/lib/dash_overlord/use_cases/v1/videos/index/postgres/get_filters.rb +1 -2
  19. data/lib/dash_overlord/use_cases/v1/videos/index/postgres/search_and_paginate_videos.rb +2 -1
  20. data/lib/dash_overlord/use_cases/v1/videos/index/postgres/search_on_subtitle_lines.rb +2 -1
  21. data/lib/elasticord.rb +0 -4
  22. data/lib/elasticord/client/base.rb +3 -1
  23. data/lib/elasticord/client/search_builder.rb +35 -6
  24. data/lib/elasticord/version.rb +1 -1
  25. data/spec/dash_overlord/use_cases/v1/videos/index/dynamo_db_spec.rb +68 -66
  26. data/spec/dash_overlord/use_cases/v1/videos/index/elastic_search_spec.rb +28 -22
  27. data/spec/dash_overlord/use_cases/v1/videos/index/postgres_spec.rb +2 -2
  28. data/spec/elasticord/base_spec.rb +14 -12
  29. data/spec/elasticord/client/base_spec.rb +4 -4
  30. data/spec/elasticord/client/search_builder_spec.rb +21 -23
  31. data/spec/spec_helper.rb +3 -5
  32. metadata +9 -4
  33. 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: f7d122cf6a147910ddcb4626cbcd0ca47c7ecf65
4
- data.tar.gz: b73e1187a53381158be36e975b36b26e9c0ab931
3
+ metadata.gz: fc79df0348d2af67fe3b48daf37b032356a5047d
4
+ data.tar.gz: 667711293ae4e3395b688c49121bc273c8f38701
5
5
  SHA512:
6
- metadata.gz: 3fb456198e61048fc0306bdd2b8fe34ba3ddf7c2bf4928a57419aef2f1faee7f3035e4b39f09291897bb4380068e3a106521b557c5c6e8da9536dffec62dec43
7
- data.tar.gz: 37f67729dc2d7b531e3ee26dd64035f8fc88be56bcb5fe55150bae9b25794c38e2270f69c6595649d4c7a620feed9b35901d6186d4b0e7d0acf12af7a76d1106
6
+ metadata.gz: bebc8fa99c4adff7c2be20515d1d479abc002a850680bbc9dc3f53f120156a38bb112a06ec80245923db2b5f38b7c2e100d9795ac71ab45c4ed219f9859ea16e
7
+ data.tar.gz: da6a8bf8bf8aba80b42e06533c953c1c09aa7ebb0a50b6bc77c607d266a4f6c9aa18661fae8dffba9decd8c32592fc6aa60b410c8dcc5a33127c5c2e94300f42
@@ -12,7 +12,7 @@ PATH
12
12
  object_attorney (>= 3.0.7)
13
13
  pg (>= 0.17)
14
14
  ransack (>= 1.7.0)
15
- elasticord (1.0.4)
15
+ elasticord (1.0.6)
16
16
  elasticsearch (~> 5.0)
17
17
 
18
18
  GEM
@@ -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
- if ENV['ENV'] == 'test'
28
- credentials = Aws::Credentials.new(
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
@@ -0,0 +1,7 @@
1
+ require 'elasticord'
2
+
3
+ Elasticord.configure do |config|
4
+ config.set :log, false
5
+ config.set \
6
+ :index_namespace, "#{DashOverlord::V1::Config.get(:env)}_not_heroku_at_all"
7
+ end
@@ -10,8 +10,10 @@ module DashOverlord
10
10
  end
11
11
 
12
12
  def self.create_all(items)
13
- client.batch_write_item \
14
- create_all_params(items)
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 self.page(page, last_evaluated_key)
41
- DynamoDb::Scan.new \
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.search(filters)
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 search(filters)
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
- self.current_page = page
15
- self.last_evaluated_key = last_evaluated_key
13
+ # def page(page, last_evaluated_key)
14
+ # self.current_page = page
15
+ # self.last_evaluated_key = last_evaluated_key
16
16
 
17
- self
18
- end
17
+ # self
18
+ # end
19
+
20
+ # def per(per_page)
21
+ # self.limit = per_page
19
22
 
20
- def per(per_page)
21
- self.limit = per_page
23
+ # self
24
+ # end
22
25
 
26
+ def result(distinct)
23
27
  self
24
28
  end
25
29
 
26
- def execute #choose a better name than this...
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.scan(scan_params)
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.scan(params)
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
- expression_attribute_values: {}
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 = \
@@ -3,10 +3,12 @@ require 'elasticord'
3
3
  module DashOverlord
4
4
  module Models
5
5
  module V1
6
+ module ElasticSearch
6
7
 
7
- class ElasticSearch < Elasticord::Base
8
- end
8
+ class Base < Elasticord::Base
9
+ end
9
10
 
11
+ end
10
12
  end
11
13
  end
12
14
  end
@@ -0,0 +1,15 @@
1
+ module DashOverlord
2
+ module Models
3
+ module V1
4
+ module ElasticSearch
5
+
6
+ class BeeVideo < ElasticSearch::Base
7
+ def self.by_dashboard(dashboard_uid)
8
+ client(dashboard_uid)
9
+ end
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+ end
@@ -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
@@ -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
 
7
7
  class Base < V1::Base
8
- DEFAULT_SEARCH_ADAPTER_USE_CASE = Postgres::Base
8
+ DEFAULT_SEARCH_ADAPTER_USE_CASE = ElasticSearch::Base
9
9
 
10
10
  def perform
11
11
  invoke! Users::FindCurrentUser
@@ -5,7 +5,7 @@ module DashOverlord
5
5
  module Index
6
6
  module DynamoDb
7
7
 
8
- class SearchAndPaginateVideos < Repositories::DynamoDb::SearchAndPaginate::Base
8
+ class SearchAndPaginateVideos < Shared::SearchAndPaginate::Base
9
9
  def perform
10
10
  context.videos = search_and_paginate(resource_class)
11
11
  end
@@ -8,6 +8,7 @@ module DashOverlord
8
8
  class Base < V1::Base
9
9
  def perform
10
10
  invoke! SearchAndPaginateVideos
11
+ invoke! Postgres::GetFilters
11
12
  end
12
13
  end
13
14
 
@@ -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 Models::V1::Answer.none
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
 
@@ -17,8 +17,7 @@ module DashOverlord
17
17
  end
18
18
 
19
19
  def hhc
20
- {}
21
- # JSON.parse(File.read('./dash_overlord/lib/dash_overlord/use_cases/v1/video_filters/index/hhc.json'))
20
+ JSON.parse(File.read(File.expand_path('../hhc.json', __FILE__)))
22
21
  end
23
22
 
24
23
  def laundry
@@ -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
@@ -18,8 +18,4 @@ module Elasticord
18
18
  def self.configure
19
19
  yield(Config)
20
20
  end
21
-
22
- # Default values
23
- Config.set(:log, false)
24
- Config.set(:index_namespace, ENV['ENV'] || 'development')
25
21
  end
@@ -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, :index, :type
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 = (body_params[:query][:bool][:filter] ||= [])
64
+ params = body_params[:query][:bool]
63
65
 
64
66
  ransack_filters.each do |key, value|
65
- key = key.to_s.split('_eq').first.to_sym
66
- value = value.downcase if value.is_a? String
67
-
68
- params.push({ term: { key => value } })
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, :index, :type
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
@@ -1,3 +1,3 @@
1
1
  module Elasticord
2
- VERSION = '1.0.4'.freeze
2
+ VERSION = '1.0.6'.freeze
3
3
  end
@@ -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
- DashOverlord::Models::V1::DynamoDb::Video
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
- DashOverlord::Models::V1::DynamoDb::Video
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 = 20.times.map do |index|
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
- before do
70
- @current_user = create('v1/user', :unilever)
70
+ # context 'when no filter params are used' do
71
+ # before do
72
+ # @current_user = create('v1/user', :unilever)
71
73
 
72
- create_answers
74
+ # create_answers
73
75
 
74
- make_the_call
75
- end
76
+ # make_the_call
77
+ # end
76
78
 
77
- it '@context.status should be ok' do
78
- expect(@context.status).to eq 'ok'
79
- end
79
+ # it '@context.status should be ok' do
80
+ # expect(@context.status).to eq 'ok'
81
+ # end
80
82
 
81
- it 'should have the right ammount of data' do
82
- expect(DashOverlord::Models::V1::DynamoDb::Video.all.count) \
83
- .to eq(20)
84
- end
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
- it 'should return pagination meta_data' do
87
- expect(@context.meta.page).to be 1
88
- expect(@context.meta.per_page).to be 10
89
- end
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
- it 'should return 10 results' do
92
- expect(@context.videos.length).to be 10
93
- end
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
- before do
98
- @current_user = create('v1/user', :unilever)
98
+ # context 'when filtering by page = 0' do
99
+ # before do
100
+ # @current_user = create('v1/user', :unilever)
99
101
 
100
- create_answers
102
+ # create_answers
101
103
 
102
- make_the_call page: 0
103
- end
104
+ # make_the_call page: 0
105
+ # end
104
106
 
105
- it '@context.status should be ok' do
106
- expect(@context.status).to eq 'ok'
107
- end
107
+ # it '@context.status should be ok' do
108
+ # expect(@context.status).to eq 'ok'
109
+ # end
108
110
 
109
- it 'should return pagination meta_data' do
110
- expect(@context.meta.page).to be 0
111
- expect(@context.meta.per_page).to be 0
112
- end
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
- it 'should return 20 results', :cana do
115
- expect(@context.videos.length).to be 20
116
- end
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
- before do
121
- @current_user = create('v1/user', :unilever)
121
+ # context 'when filtering by something' do
122
+ # before do
123
+ # @current_user = create('v1/user', :unilever)
122
124
 
123
- create_answers
125
+ # create_answers
124
126
 
125
- @female_videos = @videos.select{|el| el[:gender] == "Female" }
127
+ # @female_videos = @videos.select{|el| el[:gender] == "Female" }
126
128
 
127
- make_the_call \
128
- filter_query: {
129
- gender_eq: 'Female'
130
- }
131
- end
129
+ # make_the_call \
130
+ # filter_query: {
131
+ # gender_eq: 'Female'
132
+ # }
133
+ # end
132
134
 
133
- it '@context.status should be ok' do
134
- expect(@context.status).to eq 'ok'
135
- end
135
+ # it '@context.status should be ok' do
136
+ # expect(@context.status).to eq 'ok'
137
+ # end
136
138
 
137
- it 'should return pagination meta_data' do
138
- expect(@context.meta.page).to be 1
139
- expect(@context.meta.per_page).to be 10
140
- end
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
- it 'should return only female results', :focusrite do
143
- expect(@context.videos.length).to be @female_videos.count
144
- end
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
- DashOverlord::Models::V1::Answer.refresh_index
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
- DashOverlord::Models::V1::Answer.create attributes
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
- DashOverlord::Models::V1::Answer.delete_all
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
- DashOverlord::Models::V1::Answer.delete_all
44
- 20.times { create_answer title: 'Test' }
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 = 2' do
70
+ context 'when filtering by page = 3' do
66
71
  before(:all) do
67
- DashOverlord::Models::V1::Answer.delete_all
68
- 35.times { create_answer title: 'Test' }
72
+ bee_video_client('hhc').delete_all
69
73
 
70
- make_the_call page: 2, per_page: 15
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 2
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 15 results' do
85
- expect(@context.videos.length).to be 15
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
- DashOverlord::Models::V1::Answer.delete_all
97
+ bee_video_client('hhc').delete_all
92
98
 
93
- 15.times { create_answer user_id: 1, gender: 'Female', segment_uid: 'laundry' }
94
- 10.times { create_answer user_id: 1, gender: 'Male', segment_uid: 'hhc' }
95
- 5.times { create_answer user_id: 1, gender: 'Female', segment_uid: 'hhc' }
96
- 20.times { create_answer user_id: 2, gender: 'Female', segment_uid: 'hhc' }
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 the current env' do
6
- expect(described_class.index).to eq ENV['ENV']
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 same current env' do
13
- expect(child_class.index).to eq ENV['ENV']
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 the current env' do
22
- expect(described_class.index).to eq ENV['ENV']
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 protected #index set up' do
67
- expect(@client.send(:index)).to eq ENV['ENV']
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 protected #type set up' do
71
- expect(@client.send(:type)).to eq '_all'
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 "#{ENV['ENV']}_project_1"
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 "#{ENV['ENV']}_project_5"
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 protected #index set up' do
105
- expect(@search_builder.send(:index)).to eq ENV['ENV']
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 protected #type set up' do
109
- expect(@search_builder.send(:type)).to eq 'child_class'
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 = search_builder.page(3)
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 = search_builder.per(15)
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 30 records have been created' do
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 30 total_results' do
174
- expect(@search_result.total_results).to be 30
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
- brand_eq: 'oficial',
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 24
211
- expect(@search_result.length).to be 9
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 multi query params are passed' do
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
- { match: { title: 'child class' } }
236
+ { term: { locked: false } }
241
237
  ],
242
- filter: [
238
+ should: [
243
239
  { term: { brand: 'oficial' } },
244
- { term: { locked: false } }
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 24 total_results' do
251
- expect(@search_result.total_results).to be 24
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
@@ -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
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-20 00:00:00.000000000 Z
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
@@ -1,10 +0,0 @@
1
- module DashOverlord
2
- module Models
3
- module V1
4
-
5
- class Answer < V1::ElasticSearch
6
- end
7
-
8
- end
9
- end
10
- end