gitlab-elasticsearch-git 0.0.15 → 0.0.16

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: 805299d2c9977f838c91ad88a5ae27415345ad8d
4
- data.tar.gz: f4c2c5211cb767f10042b1373d4ebbcafe9e0b89
3
+ metadata.gz: 054efbf7262d71c052ff192800e9bc22920085b4
4
+ data.tar.gz: c49f66ffa207e47d68527065a7c0cc656a3b658d
5
5
  SHA512:
6
- metadata.gz: 73ce23ee1c90b94713d5b4dc49878cb6a110de5ebec9a002abc423249532337e0cf544ff0e6bb6b43c118373afd27b34e87645bb4e6a6b1c080e7497287e1b99
7
- data.tar.gz: 9e1227a3b202f421667e45e3adfa1bef6db62096f2f00ab8eae3c35bafe60ef12b92bdc533413ccbcb1ead5f5e0d48f1d40b049a96d0ba032c64a05127002a34
6
+ metadata.gz: fe1ff8b03b42c23ebf79210a2b7e0ee576e5d60934dbafd8b5d08c3371ac74c916d3308d294b7d23f766c9673a38f4563e767baa512439c8f86eaa77aa6eb6ec
7
+ data.tar.gz: 2e04673c2d31379398109e8cf2534bc9b2880dd3c603334fd12eb1e063cb4d83add0a9ce25ab8baf3561f23a7d4ded9daef672be68c23ee3bd85f73aad091b06
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,16 @@
1
+ image: "ruby:2.3"
2
+
3
+ services:
4
+ - elasticsearch:latest
5
+
6
+ variables:
7
+ ELASTICSEARCH_HOST: "elasticsearch"
8
+
9
+ before_script:
10
+ - apt-get update -yqqq; apt-get -o dir::cache::archives="vendor/apt" install -y -qq --force-yes libicu-dev cmake
11
+ - gem install bundler # Bundler is not installed with the image
12
+ - bundle install -j $(nproc) # Install dependencies
13
+
14
+ rspec:
15
+ script:
16
+ - rspec
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ 0.0.16
2
+ - Analyzer for CamelCased terms
3
+
1
4
  0.0.15
2
5
  - Search through the filenames
3
6
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitlab-elasticsearch-git (0.0.13)
4
+ gitlab-elasticsearch-git (0.0.15)
5
5
  activemodel (~> 4.2)
6
6
  activesupport (~> 4.2)
7
7
  charlock_holmes (~> 0.7)
@@ -24,11 +24,6 @@ module Elasticsearch
24
24
  index: {
25
25
  analysis: {
26
26
  analyzer: {
27
- human_analyzer: {
28
- type: 'custom',
29
- tokenizer: 'human_tokenizer',
30
- filter: %w(lowercase asciifolding)
31
- },
32
27
  path_analyzer: {
33
28
  type: 'custom',
34
29
  tokenizer: 'path_tokenizer',
@@ -42,32 +37,30 @@ module Elasticsearch
42
37
  code_analyzer: {
43
38
  type: 'custom',
44
39
  tokenizer: 'standard',
45
- filter: %w(lowercase asciifolding code_stemmer),
40
+ filter: %w(code lowercase asciifolding),
46
41
  char_filter: ["code_mapping"]
47
42
  }
48
43
  },
49
44
  tokenizer: {
50
45
  sha_tokenizer: {
51
46
  type: "edgeNGram",
52
- min_gram: 8,
47
+ min_gram: 5,
53
48
  max_gram: 40,
54
49
  token_chars: %w(letter digit)
55
50
  },
56
- human_tokenizer: {
57
- type: "nGram",
58
- min_gram: 1,
59
- max_gram: 20,
60
- token_chars: %w(letter digit)
61
- },
62
51
  path_tokenizer: {
63
52
  type: 'path_hierarchy',
64
53
  reverse: true
65
54
  },
66
55
  },
67
56
  filter: {
68
- code_stemmer: {
69
- type: "stemmer",
70
- name: "minimal_english"
57
+ code: {
58
+ type: "pattern_capture",
59
+ preserve_original: 1,
60
+ patterns: [
61
+ "(\\p{Ll}+|\\p{Lu}\\p{Ll}+|\\p{Lu}+)",
62
+ "(\\d+)"
63
+ ]
71
64
  }
72
65
  },
73
66
  char_filter: {
@@ -23,34 +23,51 @@ module Elasticsearch
23
23
 
24
24
  mapping _timestamp: { enabled: true } do
25
25
  indexes :blob do
26
- indexes :id, type: :string, index_options: 'offsets', analyzer: :human_analyzer
27
- indexes :rid, type: :string, index: :not_analyzed
28
- indexes :oid, type: :string, index_options: 'offsets', analyzer: :code_analyzer
29
- indexes :commit_sha, type: :string, index_options: 'offsets', analyzer: :sha_analyzer
30
- indexes :path, type: :string, analyzer: :path_analyzer
31
- indexes :file_name, type: :string, analyzer: :code_analyzer
32
- indexes :content, type: :string, index_options: 'offsets', analyzer: :code_analyzer
33
- indexes :language, type: :string, index: :not_analyzed
26
+ indexes :id, type: :string,
27
+ index_options: 'offsets',
28
+ analyzer: :sha_analyzer
29
+ indexes :rid, type: :string,
30
+ index: :not_analyzed
31
+ indexes :oid, type: :string,
32
+ index_options: 'offsets',
33
+ analyzer: :sha_analyzer
34
+ indexes :commit_sha, type: :string,
35
+ index_options: 'offsets',
36
+ analyzer: :sha_analyzer
37
+ indexes :path, type: :string,
38
+ analyzer: :path_analyzer
39
+ indexes :file_name, type: :string,
40
+ analyzer: :code_analyzer
41
+ indexes :content, type: :string,
42
+ index_options: 'offsets',
43
+ analyzer: :code_analyzer
44
+ indexes :language, type: :string,
45
+ index: :not_analyzed
34
46
  end
35
47
 
36
48
  indexes :commit do
37
- indexes :id, type: :string, index_options: 'offsets', analyzer: :human_analyzer
38
- indexes :rid, type: :string, index: :not_analyzed
39
- indexes :sha, type: :string, index_options: 'offsets', analyzer: :sha_analyzer
49
+ indexes :id, type: :string,
50
+ index_options: 'offsets',
51
+ analyzer: :sha_analyzer
52
+ indexes :rid, type: :string,
53
+ index: :not_analyzed
54
+ indexes :sha, type: :string,
55
+ index_options: 'offsets',
56
+ analyzer: :sha_analyzer
40
57
 
41
58
  indexes :author do
42
- indexes :name, type: :string, index_options: 'offsets', analyzer: :code_analyzer
43
- indexes :email, type: :string, index_options: 'offsets', analyzer: :code_analyzer
59
+ indexes :name, type: :string, index_options: 'offsets'
60
+ indexes :email, type: :string, index_options: 'offsets'
44
61
  indexes :time, type: :date, format: :basic_date_time_no_millis
45
62
  end
46
63
 
47
64
  indexes :commiter do
48
- indexes :name, type: :string, index_options: 'offsets', analyzer: :code_analyzer
49
- indexes :email, type: :string, index_options: 'offsets', analyzer: :code_analyzer
65
+ indexes :name, type: :string, index_options: 'offsets'
66
+ indexes :email, type: :string, index_options: 'offsets'
50
67
  indexes :time, type: :date, format: :basic_date_time_no_millis
51
68
  end
52
69
 
53
- indexes :message, type: :string, index_options: 'offsets', analyzer: :code_analyzer
70
+ indexes :message, type: :string, index_options: 'offsets'
54
71
  end
55
72
  end
56
73
 
@@ -331,11 +348,6 @@ module Elasticsearch
331
348
  @repository_id
332
349
  end
333
350
 
334
- # For Overwrite
335
- def self.repositories_count
336
- 10
337
- end
338
-
339
351
  unless defined?(path_to_repo)
340
352
  def path_to_repo
341
353
  if @path_to_repo.blank?
@@ -359,8 +371,15 @@ module Elasticsearch
359
371
  def client_for_indexing
360
372
  @client_for_indexing ||= Elasticsearch::Client.new retry_on_failure: 5
361
373
  end
374
+ end
362
375
 
363
- def self.search(query, type: :all, page: 1, per: 20, options: {})
376
+ module ClassMethods
377
+ # For Overwrite
378
+ def repositories_count
379
+ 10
380
+ end
381
+
382
+ def search(query, type: :all, page: 1, per: 20, options: {})
364
383
  results = { blobs: [], commits: []}
365
384
 
366
385
  case type.to_sym
@@ -375,9 +394,7 @@ module Elasticsearch
375
394
 
376
395
  results
377
396
  end
378
- end
379
397
 
380
- module ClassMethods
381
398
  def search_commit(query, page: 1, per: 20, options: {})
382
399
  page ||= 1
383
400
 
@@ -1,5 +1,5 @@
1
1
  module Elasticsearch
2
2
  module Git
3
- VERSION = '0.0.15'
3
+ VERSION = '0.0.16'
4
4
  end
5
5
  end
data/spec/main_spec.rb CHANGED
@@ -3,18 +3,16 @@ require 'spec_helper'
3
3
  describe TestRepository do
4
4
  before do
5
5
  remove_index(TestRepository.index_name)
6
+ TestRepository.__elasticsearch__.create_index!
6
7
  end
7
8
 
8
- it "creates an index" do
9
- expect(index_exist?(TestRepository.index_name)).to be_falsey
10
-
11
- TestRepository.__elasticsearch__.create_index!
9
+ let(:repo) { TestRepository.new }
12
10
 
11
+ it "creates an index" do
13
12
  expect(index_exist?(TestRepository.index_name)).to be_truthy
14
13
  end
15
14
 
16
15
  it "indexes all blobs and searches" do
17
- repo = TestRepository.new
18
16
  repo.index_blobs
19
17
 
20
18
  TestRepository.__elasticsearch__.refresh_index!
@@ -23,27 +21,24 @@ describe TestRepository do
23
21
  end
24
22
 
25
23
  it "indexes all commits and searches" do
26
- repo = TestRepository.new
27
24
  repo.index_commits
28
25
 
29
26
  TestRepository.__elasticsearch__.refresh_index!
30
27
 
31
- expect(repo.search('test', type: :commit)[:commits][:total_count]).to eq(2)
28
+ expect(repo.search('test', type: :commit)[:commits][:total_count]).to eq(3)
32
29
  end
33
30
 
34
31
  it "searches through all types" do
35
- repo = TestRepository.new
36
32
  repo.index_commits
37
33
  repo.index_blobs
38
34
 
39
35
  TestRepository.__elasticsearch__.refresh_index!
40
36
 
41
- expect(repo.search('test')[:commits][:total_count]).to eq(2)
37
+ expect(repo.search('test')[:commits][:total_count]).to eq(3)
42
38
  expect(repo.search('def')[:blobs][:total_count]).to eq(4)
43
39
  end
44
40
 
45
41
  it "searches through filename" do
46
- repo = TestRepository.new
47
42
  repo.index_blobs
48
43
 
49
44
  TestRepository.__elasticsearch__.refresh_index!
@@ -55,8 +50,20 @@ describe TestRepository do
55
50
  expect(found_version_file).to be_truthy
56
51
  end
57
52
 
53
+ it "searches through camel cased words" do
54
+ TestRepository.__elasticsearch__.create_index!(force: true)
55
+ repo.index_blobs
56
+
57
+ TestRepository.__elasticsearch__.refresh_index!
58
+
59
+ found_version_file = repo.search('Hip')[:blobs][:results].any? do |result|
60
+ result["_source"]["blob"]["file_name"] == "camelCase.rb"
61
+ end
62
+
63
+ expect(found_version_file).to be_truthy
64
+ end
65
+
58
66
  it "indexes specified commits" do
59
- repo = TestRepository.new
60
67
  repo.index_commits(
61
68
  from_rev: '40f4a7a617393735a95a0bb67b08385bc1e7c66d',
62
69
  to_rev: '732401c65e924df81435deb12891ef570167d2e2'
@@ -68,7 +75,6 @@ describe TestRepository do
68
75
  end
69
76
 
70
77
  it "indexes specified blobs" do
71
- repo = TestRepository.new
72
78
  repo.index_blobs(
73
79
  from_rev: '40f4a7a617393735a95a0bb67b08385bc1e7c66d',
74
80
  to_rev: '732401c65e924df81435deb12891ef570167d2e2'
@@ -80,7 +86,6 @@ describe TestRepository do
80
86
  end
81
87
 
82
88
  it "applies repository_id filter for blobs" do
83
- repo = TestRepository.new
84
89
  repo.index_blobs
85
90
 
86
91
  TestRepository.new("repo_second").index_blobs
@@ -92,14 +97,13 @@ describe TestRepository do
92
97
  end
93
98
 
94
99
  it "applies repository_id filter for commits" do
95
- repo = TestRepository.new
96
100
  repo.index_commits
97
101
 
98
102
  TestRepository.new("repo_second").index_commits
99
103
 
100
104
  TestRepository.__elasticsearch__.refresh_index!
101
105
 
102
- expect(TestRepository.__elasticsearch__.search('test').results.count).to eq(4)
103
- expect(repo.search('test')[:commits][:total_count]).to eq(2)
106
+ expect(TestRepository.__elasticsearch__.search('test').results.count).to eq(6)
107
+ expect(repo.search('test')[:commits][:total_count]).to eq(3)
104
108
  end
105
- end
109
+ end
data/spec/spec_helper.rb CHANGED
@@ -13,4 +13,4 @@ RSpec.configure do |config|
13
13
  config.include ElasticHelper
14
14
  config.include SeedHelper
15
15
  config.before(:all) { ensure_seeds }
16
- end
16
+ end
@@ -9,6 +9,7 @@ module ElasticHelper
9
9
  end
10
10
 
11
11
  def elastic_url
12
- 'http://localhost:9200/'
12
+ host = ENV['ELASTICSEARCH_HOST'] || 'localhost'
13
+ "http://#{host}:9200/"
13
14
  end
14
- end
15
+ end
@@ -1,7 +1,7 @@
1
1
  require 'fileutils'
2
2
 
3
3
  module SeedHelper
4
- GITLAB_URL = "git@gitlab.com:gitlab-org/gitlab-elasticsearch-git-test.git"
4
+ GITLAB_URL = "https://gitlab.com/gitlab-org/gitlab-elasticsearch-git-test.git"
5
5
 
6
6
  def ensure_seeds
7
7
  if File.exists?(SUPPORT_PATH)
@@ -22,4 +22,4 @@ module SeedHelper
22
22
  def git_env
23
23
  {'GIT_TEMPLATE_DIR' => ''}
24
24
  end
25
- end
25
+ end
@@ -1,10 +1,20 @@
1
1
  class TestRepository
2
2
  include Elasticsearch::Git::Repository
3
3
 
4
+ CLIENT = Elasticsearch::Client.new(
5
+ host: (ENV['ELASTICSEARCH_HOST'] || 'localhost')
6
+ )
7
+
8
+ self.__elasticsearch__.client = CLIENT
9
+
4
10
  def initialize(id = 'test_1')
5
11
  @repo_id = id
6
12
  end
7
13
 
14
+ def client_for_indexing
15
+ CLIENT
16
+ end
17
+
8
18
  def repository_id
9
19
  @repo_id
10
20
  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.15
4
+ version: 0.0.16
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-05-20 00:00:00.000000000 Z
13
+ date: 2016-08-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: elasticsearch-model
@@ -119,6 +119,7 @@ extensions: []
119
119
  extra_rdoc_files: []
120
120
  files:
121
121
  - ".gitignore"
122
+ - ".gitlab-ci.yml"
122
123
  - ".rspec"
123
124
  - CHANGELOG
124
125
  - Gemfile