gitlab-elasticsearch-git 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c17d708d0668ff43d5497e36a96feb66787903b3
4
- data.tar.gz: 5f0c4d7aa9e70b69644cc9ee7775f7d53caee20d
3
+ metadata.gz: ba4d3958d1aa1aa5ebc18dd268708607ea22cf59
4
+ data.tar.gz: a40a0d48a99aaf2d876ed4d733acf41e2b78ee8e
5
5
  SHA512:
6
- metadata.gz: 836b2f456c9e68ea424ef76ce9d5c74cb9c0434a835575250c161c6898ddc9a837fa71e0c258bb5db11b92477a495b383b4182896c8b2abad7f8c4de1197f993
7
- data.tar.gz: 135521c6f5cde51751ec7b0fbb561ff88016e2d584127e3c98bdbd0bd94ff0096ce3b91024816b104901f8a7ea12869ec7dd6db9da0cb92f4f8c03ff037db40b
6
+ metadata.gz: 90799948082455a0d6cde26b83b3f6b65664b3223ebd8e8edf8e4fbf6af8570c11d041874c088f2eac5d9608f0f7298f47ee1027482e6ad0000b8336e9dab6e7
7
+ data.tar.gz: 5f7c8eec4c6b73be317eeb394c6f6f928d4976290f1824934d311b4c638eb7c8e445f0fabe5740d7b99e8a84a5ba0602ae99c9f1f874a1fb1d69f626a2729812
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 0.0.14
2
+ - Improve code search analyzer (custom word delimeter of source code)
3
+ - Fix encoding issues
4
+ - Replace deprecated "filtered" query with "bool" query
5
+
1
6
  0.0.13
2
7
  - Improve code search analyzer
3
8
 
@@ -42,7 +42,8 @@ module Elasticsearch
42
42
  code_analyzer: {
43
43
  type: 'custom',
44
44
  tokenizer: 'standard',
45
- filter: %w(lowercase asciifolding word_delimiter code_stemmer)
45
+ filter: %w(lowercase asciifolding code_stemmer),
46
+ char_filter: ["code_mapping"]
46
47
  }
47
48
  },
48
49
  tokenizer: {
@@ -68,7 +69,15 @@ module Elasticsearch
68
69
  type: "stemmer",
69
70
  name: "minimal_english"
70
71
  }
71
- }
72
+ },
73
+ char_filter: {
74
+ code_mapping: {
75
+ type: "mapping",
76
+ mappings: [
77
+ ". => ' '"
78
+ ]
79
+ }
80
+ },
72
81
  }
73
82
  }
74
83
  end
@@ -184,13 +184,13 @@ module Elasticsearch
184
184
  rid: repository_id,
185
185
  sha: commit.oid,
186
186
  author: {
187
- name: commit.author[:name],
188
- email: commit.author[:email],
187
+ name: encode!(commit.author[:name]),
188
+ email: encode!(commit.author[:email]),
189
189
  time: commit.author[:time].strftime('%Y%m%dT%H%M%S%z'),
190
190
  },
191
191
  committer: {
192
- name: commit.committer[:name],
193
- email: commit.committer[:email],
192
+ name: encode!(commit.committer[:name]),
193
+ email: encode!(commit.committer[:email]),
194
194
  time: commit.committer[:time].strftime('%Y%m%dT%H%M%S%z'),
195
195
  },
196
196
  message: encode!(commit.message)
@@ -312,7 +312,7 @@ module Elasticsearch
312
312
 
313
313
  # Repository id used for identity data from different repositories
314
314
  # Update this value if need
315
- def set_repository_id id = nil
315
+ def set_repository_id(id = nil)
316
316
  @repository_id = id || path_to_repo
317
317
  end
318
318
 
@@ -375,15 +375,15 @@ module Elasticsearch
375
375
 
376
376
  query_hash = {
377
377
  query: {
378
- filtered: {
379
- query: {
378
+ bool: {
379
+ must: [{
380
380
  multi_match: {
381
381
  fields: fields,
382
382
  query: "#{query}",
383
383
  operator: :or
384
384
  }
385
- },
386
- },
385
+ }]
386
+ }
387
387
  },
388
388
  aggs: {
389
389
  commitRepositoryFaset: {
@@ -399,15 +399,14 @@ module Elasticsearch
399
399
  }
400
400
 
401
401
  if query.blank?
402
- query_hash[:query][:filtered][:query] = { match_all: {}}
402
+ query_hash[:query][:bool][:must] = { match_all: {}}
403
403
  query_hash[:track_scores] = true
404
404
  end
405
405
 
406
406
  if options[:repository_id]
407
- query_hash[:query][:filtered][:filter] ||= { and: [] }
408
- query_hash[:query][:filtered][:filter][:and] << {
407
+ query_hash[:query][:bool][:filter] = {
409
408
  terms: {
410
- "commit.rid" => [options[:repository_id]].flatten
409
+ 'commit.rid' => [options[:repository_id]].flatten
411
410
  }
412
411
  }
413
412
  end
@@ -451,8 +450,8 @@ module Elasticsearch
451
450
 
452
451
  query_hash = {
453
452
  query: {
454
- filtered: {
455
- query: {
453
+ bool: {
454
+ must: {
456
455
  multi_match: {
457
456
  query: query,
458
457
  operator: :and,
@@ -481,20 +480,20 @@ module Elasticsearch
481
480
  from: per * (page - 1)
482
481
  }
483
482
 
483
+ query_hash[:query][:bool][:filter] = []
484
+
484
485
  if options[:repository_id]
485
- query_hash[:query][:filtered][:filter] ||= { and: [] }
486
- query_hash[:query][:filtered][:filter][:and] << {
486
+ query_hash[:query][:bool][:filter] << {
487
487
  terms: {
488
- "blob.rid" => [options[:repository_id]].flatten
488
+ 'blob.rid' => [options[:repository_id]].flatten
489
489
  }
490
490
  }
491
491
  end
492
492
 
493
493
  if options[:language]
494
- query_hash[:query][:filtered][:filter] ||= { and: [] }
495
- query_hash[:query][:filtered][:filter][:and] << {
494
+ query_hash[:query][:bool][:filter] << {
496
495
  terms: {
497
- "blob.language" => [options[:language]].flatten
496
+ 'blob.language' => [options[:language]].flatten
498
497
  }
499
498
  }
500
499
  end
@@ -540,12 +539,12 @@ module Elasticsearch
540
539
  fields: ['blob.path'],
541
540
  query: {
542
541
  fuzzy: {
543
- "repository.blob.path" => { value: query }
542
+ 'repository.blob.path' => { value: query }
544
543
  },
545
544
  },
546
545
  filter: {
547
546
  term: {
548
- "repository.blob.rid" => [options[:repository_id]].flatten
547
+ 'repository.blob.rid' => [options[:repository_id]].flatten
549
548
  }
550
549
  },
551
550
  size: per,
@@ -1,5 +1,5 @@
1
1
  module Elasticsearch
2
2
  module Git
3
- VERSION = "0.0.13"
3
+ VERSION = "0.0.14"
4
4
  end
5
5
  end
@@ -27,7 +27,7 @@ describe TestRepository do
27
27
  repo.index_commits
28
28
 
29
29
  TestRepository.__elasticsearch__.refresh_index!
30
-
30
+
31
31
  expect(repo.search('test', type: :commit)[:commits][:total_count]).to eq(2)
32
32
  end
33
33
 
@@ -37,12 +37,12 @@ describe TestRepository do
37
37
  repo.index_blobs
38
38
 
39
39
  TestRepository.__elasticsearch__.refresh_index!
40
-
40
+
41
41
  expect(repo.search('test')[:commits][:total_count]).to eq(2)
42
42
  expect(repo.search('def')[:blobs][:total_count]).to eq(4)
43
43
  end
44
44
 
45
- it "it indexes specified commits" do
45
+ it "indexes specified commits" do
46
46
  repo = TestRepository.new
47
47
  repo.index_commits(
48
48
  from_rev: '40f4a7a617393735a95a0bb67b08385bc1e7c66d',
@@ -50,11 +50,11 @@ describe TestRepository do
50
50
  )
51
51
 
52
52
  TestRepository.__elasticsearch__.refresh_index!
53
-
53
+
54
54
  expect(repo.search('empty', type: :commit)[:commits][:total_count]).to eq(1)
55
55
  end
56
56
 
57
- it "it indexes specified blobs" do
57
+ it "indexes specified blobs" do
58
58
  repo = TestRepository.new
59
59
  repo.index_blobs(
60
60
  from_rev: '40f4a7a617393735a95a0bb67b08385bc1e7c66d',
@@ -62,7 +62,31 @@ describe TestRepository do
62
62
  )
63
63
 
64
64
  TestRepository.__elasticsearch__.refresh_index!
65
-
65
+
66
66
  expect(repo.search('Permission is hereby granted', type: :blob)[:blobs][:total_count]).to eq(1)
67
67
  end
68
+
69
+ it "applies repository_id filter for blobs" do
70
+ repo = TestRepository.new
71
+ repo.index_blobs
72
+
73
+ TestRepository.new("repo_second").index_blobs
74
+
75
+ TestRepository.__elasticsearch__.refresh_index!
76
+
77
+ expect(TestRepository.__elasticsearch__.search('def').results.count).to eq(8)
78
+ expect(repo.search('def')[:blobs][:total_count]).to eq(4)
79
+ end
80
+
81
+ it "applies repository_id filter for commits" do
82
+ repo = TestRepository.new
83
+ repo.index_commits
84
+
85
+ TestRepository.new("repo_second").index_commits
86
+
87
+ TestRepository.__elasticsearch__.refresh_index!
88
+
89
+ expect(TestRepository.__elasticsearch__.search('test').results.count).to eq(4)
90
+ expect(repo.search('test')[:commits][:total_count]).to eq(2)
91
+ end
68
92
  end
@@ -1,8 +1,12 @@
1
1
  class TestRepository
2
2
  include Elasticsearch::Git::Repository
3
3
 
4
+ def initialize(id = 'test_1')
5
+ @repo_id = id
6
+ end
7
+
4
8
  def repository_id
5
- 'test_1'
9
+ @repo_id
6
10
  end
7
11
 
8
12
  def path_to_repo
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.13
4
+ version: 0.0.14
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-04-15 00:00:00.000000000 Z
13
+ date: 2016-05-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: elasticsearch-model