Skip to content
Snippets Groups Projects
Commit 78b6dd89 authored by Valery Sizov's avatar Valery Sizov
Browse files

Merge branch 'parent_project' into 'master'

Parent project



See merge request !18
parents 74b023d0 ca4856a3
No related branches found
No related tags found
1 merge request!18Parent project
Pipeline #
1.0.0
- Blobs and Commits have a parent project
0.0.17
- Improve code analyzer
 
Loading
Loading
PATH
remote: .
specs:
gitlab-elasticsearch-git (0.0.17)
gitlab-elasticsearch-git (1.0.0)
activemodel (~> 4.2)
activesupport (~> 4.2)
charlock_holmes (~> 0.7)
Loading
Loading
Loading
Loading
@@ -21,7 +21,7 @@ module Elasticsearch
include Elasticsearch::Git::Model
include Elasticsearch::Git::EncoderHelper
 
mapping _timestamp: { enabled: true } do
mapping _timestamp: { enabled: true }, _parent: { type: 'project' } do
indexes :blob do
indexes :id, type: :string,
index_options: 'offsets',
Loading
Loading
@@ -119,18 +119,26 @@ module Elasticsearch
client_for_indexing.bulk body: bulk_operations
end
 
def delete_blob(blob)
return unless blob.text?
{ delete: { _index: "#{self.class.index_name}", _type: self.class.name.underscore, _id: "#{repository_id}_#{blob.path}" } }
{
delete: {
_index: "#{self.class.index_name}",
_type: self.class.name.underscore,
_id: "#{repository_id}_#{blob.path}",
_parent: project_id
}
}
end
 
def index_blob(blob, target_sha)
return unless can_index_blob?(blob)
{
index: {
_index: "#{self.class.index_name}", _type: self.class.name.underscore, _id: "#{repository_id}_#{blob.path}",
_index: "#{self.class.index_name}",
_type: self.class.name.underscore,
_id: "#{repository_id}_#{blob.path}",
_parent: project_id,
data: {
blob: {
type: "blob",
Loading
Loading
@@ -206,7 +214,10 @@ module Elasticsearch
def index_commit(commit)
{
index: {
_index: "#{self.class.index_name}", _type: self.class.name.underscore, _id: "#{repository_id}_#{commit.oid}",
_index: "#{self.class.index_name}",
_type: self.class.name.underscore,
_id: "#{repository_id}_#{commit.oid}",
_parent: project_id,
data: {
commit: {
type: "commit",
Loading
Loading
@@ -340,7 +351,7 @@ module Elasticsearch
end
 
# Repository id used for identity data from different repositories
# Update this value if need
# Update this value if needed
def set_repository_id(id = nil)
@repository_id = id || path_to_repo
end
Loading
Loading
@@ -376,11 +387,6 @@ module Elasticsearch
end
 
module ClassMethods
# For Overwrite
def repositories_count
10
end
def search(query, type: :all, page: 1, per: 20, options: {})
results = { blobs: [], commits: []}
 
Loading
Loading
@@ -408,21 +414,12 @@ module Elasticsearch
must: [{
multi_match: {
fields: fields,
query: "#{query}",
query: query,
operator: :or
}
}]
}
},
aggs: {
commitRepositoryFaset: {
terms: {
field: "commit.rid",
all_terms: true,
size: repositories_count
}
}
},
size: per,
from: per * (page - 1)
}
Loading
Loading
@@ -440,6 +437,11 @@ module Elasticsearch
}
end
 
if options[:additional_filter]
query_hash[:query][:bool][:filter] ||= []
query_hash[:query][:bool][:filter] << options[:additional_filter]
end
if options[:highlight]
es_fields = fields.map { |field| field.split('^').first }.inject({}) do |memo, field|
memo[field.to_sym] = {}
Loading
Loading
@@ -447,9 +449,9 @@ module Elasticsearch
end
 
query_hash[:highlight] = {
pre_tags: ["gitlabelasticsearch→"],
post_tags: ["←gitlabelasticsearch"],
fields: es_fields
pre_tags: ["gitlabelasticsearch→"],
post_tags: ["←gitlabelasticsearch"],
fields: es_fields
}
end
 
Loading
Loading
@@ -469,8 +471,7 @@ module Elasticsearch
res = self.__elasticsearch__.search(query_hash)
{
results: res.results,
total_count: res.size,
repositories: res.response["aggregations"]["commitRepositoryFaset"]["buckets"]
total_count: res.size
}
end
 
Loading
Loading
@@ -489,22 +490,6 @@ module Elasticsearch
}
}
},
aggs: {
languageFacet: {
terms: {
field: :language,
all_terms: true,
size: 20
}
},
blobRepositoryFaset: {
terms: {
field: :rid,
all_terms: true,
size: repositories_count
}
}
},
size: per,
from: per * (page - 1)
}
Loading
Loading
@@ -519,6 +504,11 @@ module Elasticsearch
}
end
 
if options[:additional_filter]
query_hash[:query][:bool][:filter] ||= []
query_hash[:query][:bool][:filter] << options[:additional_filter]
end
if options[:language]
query_hash[:query][:bool][:filter] << {
terms: {
Loading
Loading
@@ -557,9 +547,7 @@ module Elasticsearch
 
{
results: res.results,
total_count: res.size,
languages: res.response["aggregations"]["languageFacet"]["buckets"],
repositories: res.response["aggregations"]["blobRepositoryFaset"]["buckets"]
total_count: res.size
}
end
 
Loading
Loading
module Elasticsearch
module Git
VERSION = '0.0.17'
VERSION = '1.0.0'
end
end
Loading
Loading
@@ -7,8 +7,9 @@ class TestRepository
 
self.__elasticsearch__.client = CLIENT
 
def initialize(id = 'test_1')
def initialize(id = 'test_1', project_id = 1)
@repo_id = id
@project_id = 1
end
 
def client_for_indexing
Loading
Loading
@@ -19,6 +20,10 @@ class TestRepository
@repo_id
end
 
def project_id
@project_id
end
def path_to_repo
TEST_REPO_PATH
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment