gitlab-elasticsearch-git 0.0.17 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a29bf85d996a734eafc1d569dc32f20795baedb
4
- data.tar.gz: 72bc712f6d6c40fbca6e9ca2619282f49133cb9e
3
+ metadata.gz: c2f2e02dd07d4a8be46948d3bce7bb400fc85b01
4
+ data.tar.gz: 7351959ff7c27ac48360f9bca26ab7e2727763ca
5
5
  SHA512:
6
- metadata.gz: 6079984bd4f4cd8603b21f878cce916ba97f51186dc6dcef9a58f3a72a8e1c0c03a5a2eb2633d818241303b17c85588c1c48a0e6818fd2e678c92bc4fd42202d
7
- data.tar.gz: f4332529cb1985d21e97bca944a31f7e0a3fab69c8d96d8ffb80c9fb6bb0c26393d88bd358655ec8a777b4a870066cc711ec1fb84ec198735060e31eca1aea34
6
+ metadata.gz: 492e50d3b67c8b2a3adb03c4cd5a62ece0bda3a9d6199cef64b02e678e22414b3943f80581bb7141f002a7230db1c767c039025e61bc056f018f54a78b3027cf
7
+ data.tar.gz: 17086678943cdb815521fa196cb59a1f3d0926ae40b1e209ade66d8f19b75c1ccb4f12f7638a7da5c143b34ab6bb44fb76dd5183bc33d7c7964b826c6ca809f9
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ 1.0.0
2
+ - Blobs and Commits have a parent project
3
+
1
4
  0.0.17
2
5
  - Improve code analyzer
3
6
 
data/Gemfile CHANGED
@@ -3,8 +3,8 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in elasticsearch-git.gemspec
4
4
  gemspec
5
5
 
6
- gem 'elasticsearch-model'
7
- gem 'elasticsearch-api'
6
+ gem 'elasticsearch-model', '~> 0.1.9'
7
+ gem 'elasticsearch-api', '~> 1.1.0'
8
8
  gem 'rugged', '~> 0.24'
9
9
  gem 'rake'
10
10
  gem 'pry'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitlab-elasticsearch-git (0.0.15)
4
+ gitlab-elasticsearch-git (1.0.0)
5
5
  activemodel (~> 4.2)
6
6
  activesupport (~> 4.2)
7
7
  charlock_holmes (~> 0.7)
@@ -13,10 +13,10 @@ PATH
13
13
  GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
- activemodel (4.2.5)
17
- activesupport (= 4.2.5)
16
+ activemodel (4.2.7.1)
17
+ activesupport (= 4.2.7.1)
18
18
  builder (~> 3.1)
19
- activesupport (4.2.5)
19
+ activesupport (4.2.7.1)
20
20
  i18n (~> 0.7)
21
21
  json (~> 1.7, >= 1.7.7)
22
22
  minitest (~> 5.1)
@@ -26,16 +26,16 @@ GEM
26
26
  charlock_holmes (0.7.3)
27
27
  coderay (1.1.0)
28
28
  diff-lcs (1.2.5)
29
- elasticsearch (1.0.15)
30
- elasticsearch-api (= 1.0.15)
31
- elasticsearch-transport (= 1.0.15)
32
- elasticsearch-api (1.0.15)
29
+ elasticsearch (1.1.0)
30
+ elasticsearch-api (= 1.1.0)
31
+ elasticsearch-transport (= 1.1.0)
32
+ elasticsearch-api (1.1.0)
33
33
  multi_json
34
- elasticsearch-model (0.1.8)
34
+ elasticsearch-model (0.1.9)
35
35
  activesupport (> 3)
36
36
  elasticsearch (> 0.4)
37
37
  hashie
38
- elasticsearch-transport (1.0.15)
38
+ elasticsearch-transport (1.1.0)
39
39
  faraday
40
40
  multi_json
41
41
  escape_utils (1.1.0)
@@ -46,15 +46,15 @@ GEM
46
46
  escape_utils (~> 1.1.0)
47
47
  mime-types (>= 1.19)
48
48
  rugged (>= 0.23.0b)
49
- hashie (3.4.3)
49
+ hashie (3.4.4)
50
50
  i18n (0.7.0)
51
51
  json (1.8.3)
52
52
  method_source (0.8.2)
53
53
  mime-types (3.0)
54
54
  mime-types-data (~> 3.2015)
55
55
  mime-types-data (3.2015.1120)
56
- minitest (5.8.3)
57
- multi_json (1.11.2)
56
+ minitest (5.9.0)
57
+ multi_json (1.12.1)
58
58
  multipart-post (2.0.0)
59
59
  pry (0.10.3)
60
60
  coderay (~> 1.1.0)
@@ -85,8 +85,8 @@ PLATFORMS
85
85
 
86
86
  DEPENDENCIES
87
87
  charlock_holmes (~> 0.7.3)
88
- elasticsearch-api
89
- elasticsearch-model
88
+ elasticsearch-api (~> 1.1.0)
89
+ elasticsearch-model (~> 0.1.9)
90
90
  github-linguist (~> 4.7.0)
91
91
  gitlab-elasticsearch-git!
92
92
  pry
@@ -95,4 +95,4 @@ DEPENDENCIES
95
95
  rugged (~> 0.24)
96
96
 
97
97
  BUNDLED WITH
98
- 1.11.2
98
+ 1.12.5
@@ -21,7 +21,7 @@ module Elasticsearch
21
21
  include Elasticsearch::Git::Model
22
22
  include Elasticsearch::Git::EncoderHelper
23
23
 
24
- mapping _timestamp: { enabled: true } do
24
+ mapping _timestamp: { enabled: true }, _parent: { type: 'project' } do
25
25
  indexes :blob do
26
26
  indexes :id, type: :string,
27
27
  index_options: 'offsets',
@@ -119,18 +119,26 @@ module Elasticsearch
119
119
  client_for_indexing.bulk body: bulk_operations
120
120
  end
121
121
 
122
-
123
122
  def delete_blob(blob)
124
123
  return unless blob.text?
125
- { delete: { _index: "#{self.class.index_name}", _type: self.class.name.underscore, _id: "#{repository_id}_#{blob.path}" } }
124
+ {
125
+ delete: {
126
+ _index: "#{self.class.index_name}",
127
+ _type: self.class.name.underscore,
128
+ _id: "#{repository_id}_#{blob.path}",
129
+ _parent: project_id
130
+ }
131
+ }
126
132
  end
127
133
 
128
-
129
134
  def index_blob(blob, target_sha)
130
135
  return unless can_index_blob?(blob)
131
136
  {
132
137
  index: {
133
- _index: "#{self.class.index_name}", _type: self.class.name.underscore, _id: "#{repository_id}_#{blob.path}",
138
+ _index: "#{self.class.index_name}",
139
+ _type: self.class.name.underscore,
140
+ _id: "#{repository_id}_#{blob.path}",
141
+ _parent: project_id,
134
142
  data: {
135
143
  blob: {
136
144
  type: "blob",
@@ -206,7 +214,10 @@ module Elasticsearch
206
214
  def index_commit(commit)
207
215
  {
208
216
  index: {
209
- _index: "#{self.class.index_name}", _type: self.class.name.underscore, _id: "#{repository_id}_#{commit.oid}",
217
+ _index: "#{self.class.index_name}",
218
+ _type: self.class.name.underscore,
219
+ _id: "#{repository_id}_#{commit.oid}",
220
+ _parent: project_id,
210
221
  data: {
211
222
  commit: {
212
223
  type: "commit",
@@ -340,7 +351,7 @@ module Elasticsearch
340
351
  end
341
352
 
342
353
  # Repository id used for identity data from different repositories
343
- # Update this value if need
354
+ # Update this value if needed
344
355
  def set_repository_id(id = nil)
345
356
  @repository_id = id || path_to_repo
346
357
  end
@@ -376,11 +387,6 @@ module Elasticsearch
376
387
  end
377
388
 
378
389
  module ClassMethods
379
- # For Overwrite
380
- def repositories_count
381
- 10
382
- end
383
-
384
390
  def search(query, type: :all, page: 1, per: 20, options: {})
385
391
  results = { blobs: [], commits: []}
386
392
 
@@ -408,21 +414,12 @@ module Elasticsearch
408
414
  must: [{
409
415
  multi_match: {
410
416
  fields: fields,
411
- query: "#{query}",
417
+ query: query,
412
418
  operator: :or
413
419
  }
414
420
  }]
415
421
  }
416
422
  },
417
- aggs: {
418
- commitRepositoryFaset: {
419
- terms: {
420
- field: "commit.rid",
421
- all_terms: true,
422
- size: repositories_count
423
- }
424
- }
425
- },
426
423
  size: per,
427
424
  from: per * (page - 1)
428
425
  }
@@ -440,6 +437,11 @@ module Elasticsearch
440
437
  }
441
438
  end
442
439
 
440
+ if options[:additional_filter]
441
+ query_hash[:query][:bool][:filter] ||= []
442
+ query_hash[:query][:bool][:filter] << options[:additional_filter]
443
+ end
444
+
443
445
  if options[:highlight]
444
446
  es_fields = fields.map { |field| field.split('^').first }.inject({}) do |memo, field|
445
447
  memo[field.to_sym] = {}
@@ -447,9 +449,9 @@ module Elasticsearch
447
449
  end
448
450
 
449
451
  query_hash[:highlight] = {
450
- pre_tags: ["gitlabelasticsearch→"],
451
- post_tags: ["←gitlabelasticsearch"],
452
- fields: es_fields
452
+ pre_tags: ["gitlabelasticsearch→"],
453
+ post_tags: ["←gitlabelasticsearch"],
454
+ fields: es_fields
453
455
  }
454
456
  end
455
457
 
@@ -469,8 +471,7 @@ module Elasticsearch
469
471
  res = self.__elasticsearch__.search(query_hash)
470
472
  {
471
473
  results: res.results,
472
- total_count: res.size,
473
- repositories: res.response["aggregations"]["commitRepositoryFaset"]["buckets"]
474
+ total_count: res.size
474
475
  }
475
476
  end
476
477
 
@@ -489,22 +490,6 @@ module Elasticsearch
489
490
  }
490
491
  }
491
492
  },
492
- aggs: {
493
- languageFacet: {
494
- terms: {
495
- field: :language,
496
- all_terms: true,
497
- size: 20
498
- }
499
- },
500
- blobRepositoryFaset: {
501
- terms: {
502
- field: :rid,
503
- all_terms: true,
504
- size: repositories_count
505
- }
506
- }
507
- },
508
493
  size: per,
509
494
  from: per * (page - 1)
510
495
  }
@@ -519,6 +504,11 @@ module Elasticsearch
519
504
  }
520
505
  end
521
506
 
507
+ if options[:additional_filter]
508
+ query_hash[:query][:bool][:filter] ||= []
509
+ query_hash[:query][:bool][:filter] << options[:additional_filter]
510
+ end
511
+
522
512
  if options[:language]
523
513
  query_hash[:query][:bool][:filter] << {
524
514
  terms: {
@@ -557,9 +547,7 @@ module Elasticsearch
557
547
 
558
548
  {
559
549
  results: res.results,
560
- total_count: res.size,
561
- languages: res.response["aggregations"]["languageFacet"]["buckets"],
562
- repositories: res.response["aggregations"]["blobRepositoryFaset"]["buckets"]
550
+ total_count: res.size
563
551
  }
564
552
  end
565
553
 
@@ -1,5 +1,5 @@
1
1
  module Elasticsearch
2
2
  module Git
3
- VERSION = '0.0.17'
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
@@ -7,8 +7,9 @@ class TestRepository
7
7
 
8
8
  self.__elasticsearch__.client = CLIENT
9
9
 
10
- def initialize(id = 'test_1')
10
+ def initialize(id = 'test_1', project_id = 1)
11
11
  @repo_id = id
12
+ @project_id = 1
12
13
  end
13
14
 
14
15
  def client_for_indexing
@@ -19,6 +20,10 @@ class TestRepository
19
20
  @repo_id
20
21
  end
21
22
 
23
+ def project_id
24
+ @project_id
25
+ end
26
+
22
27
  def path_to_repo
23
28
  TEST_REPO_PATH
24
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-elasticsearch-git
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Kumanyaev
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-08-15 00:00:00.000000000 Z
13
+ date: 2016-09-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: elasticsearch-model
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  version: '0'
160
160
  requirements: []
161
161
  rubyforge_project:
162
- rubygems_version: 2.4.8
162
+ rubygems_version: 2.5.1
163
163
  signing_key:
164
164
  specification_version: 4
165
165
  summary: Elasticsearch integrations for git repositories.