Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
bbff948f
Commit
bbff948f
authored
Feb 02, 2016
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move elastic modules to lib
parent
63392cdc
Changes
27
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
584 additions
and
567 deletions
+584
-567
app/elastic/application_search.rb
app/elastic/application_search.rb
+0
-103
app/elastic/issues_search.rb
app/elastic/issues_search.rb
+0
-47
app/elastic/merge_requests_search.rb
app/elastic/merge_requests_search.rb
+0
-63
app/elastic/milestones_search.rb
app/elastic/milestones_search.rb
+0
-33
app/elastic/notes_search.rb
app/elastic/notes_search.rb
+0
-49
app/elastic/projects_search.rb
app/elastic/projects_search.rb
+0
-116
app/elastic/repositories_search.rb
app/elastic/repositories_search.rb
+0
-35
app/elastic/snippets_search.rb
app/elastic/snippets_search.rb
+0
-77
app/elastic/wiki_repositories_search.rb
app/elastic/wiki_repositories_search.rb
+0
-34
app/models/issue.rb
app/models/issue.rb
+1
-1
app/models/merge_request.rb
app/models/merge_request.rb
+1
-1
app/models/milestone.rb
app/models/milestone.rb
+1
-1
app/models/note.rb
app/models/note.rb
+1
-1
app/models/project.rb
app/models/project.rb
+1
-1
app/models/project_wiki.rb
app/models/project_wiki.rb
+1
-1
app/models/repository.rb
app/models/repository.rb
+1
-1
app/models/snippet.rb
app/models/snippet.rb
+1
-1
config/application.rb
config/application.rb
+1
-2
lib/elastic/application_search.rb
lib/elastic/application_search.rb
+105
-0
lib/elastic/issues_search.rb
lib/elastic/issues_search.rb
+49
-0
lib/elastic/merge_requests_search.rb
lib/elastic/merge_requests_search.rb
+65
-0
lib/elastic/milestones_search.rb
lib/elastic/milestones_search.rb
+35
-0
lib/elastic/notes_search.rb
lib/elastic/notes_search.rb
+51
-0
lib/elastic/projects_search.rb
lib/elastic/projects_search.rb
+118
-0
lib/elastic/repositories_search.rb
lib/elastic/repositories_search.rb
+37
-0
lib/elastic/snippets_search.rb
lib/elastic/snippets_search.rb
+79
-0
lib/elastic/wiki_repositories_search.rb
lib/elastic/wiki_repositories_search.rb
+36
-0
No files found.
app/elastic/application_search.rb
deleted
100644 → 0
View file @
63392cdc
module
ApplicationSearch
extend
ActiveSupport
::
Concern
included
do
include
Elasticsearch
::
Model
self
.
__elasticsearch__
.
client
=
Elasticsearch
::
Client
.
new
(
host:
Gitlab
.
config
.
elasticsearch
.
host
,
port:
Gitlab
.
config
.
elasticsearch
.
port
)
index_name
[
Rails
.
application
.
class
.
parent_name
.
downcase
,
self
.
name
.
downcase
,
Rails
.
env
].
join
(
'-'
)
settings
\
index:
{
analysis:
{
analyzer:
{
default
:{
tokenizer:
"standard"
,
filter:
[
"standard"
,
"lowercase"
,
"my_stemmer"
]
}
},
filter:
{
my_stemmer:
{
type:
"stemmer"
,
name:
"light_english"
}
}
}
}
if
Gitlab
.
config
.
elasticsearch
.
enabled
after_commit
on: :create
do
ElasticIndexerWorker
.
perform_async
(
:index
,
self
.
class
.
to_s
,
self
.
id
)
end
after_commit
on: :update
do
ElasticIndexerWorker
.
perform_async
(
:update
,
self
.
class
.
to_s
,
self
.
id
)
end
after_commit
on: :destroy
do
ElasticIndexerWorker
.
perform_async
(
:delete
,
self
.
class
.
to_s
,
self
.
id
)
end
end
end
module
ClassMethods
def
highlight_options
(
fields
)
es_fields
=
fields
.
map
{
|
field
|
field
.
split
(
'^'
).
first
}.
inject
({})
do
|
memo
,
field
|
memo
[
field
.
to_sym
]
=
{}
memo
end
{
fields:
es_fields
}
end
def
basic_query_hash
(
fields
,
query
)
query_hash
=
if
query
.
present?
{
query:
{
filtered:
{
query:
{
multi_match:
{
fields:
fields
,
query:
query
,
operator: :and
}
},
},
}
}
else
{
query:
{
filtered:
{
query:
{
match_all:
{}
}
}
},
track_scores:
true
}
end
query_hash
[
:sort
]
=
[
{
updated_at_sort:
{
order: :desc
,
mode: :min
}
},
:_score
]
query_hash
[
:highlight
]
=
highlight_options
(
fields
)
query_hash
end
def
project_ids_filter
(
query_hash
,
project_ids
)
if
project_ids
query_hash
[
:query
][
:filtered
][
:filter
]
=
{
and:
[
{
terms:
{
project_id:
project_ids
}
}
]
}
end
query_hash
end
end
end
app/elastic/issues_search.rb
deleted
100644 → 0
View file @
63392cdc
module
IssuesSearch
extend
ActiveSupport
::
Concern
included
do
include
ApplicationSearch
mappings
do
indexes
:id
,
type: :integer
indexes
:iid
,
type: :integer
,
index: :not_analyzed
indexes
:title
,
type: :string
,
index_options:
'offsets'
indexes
:description
,
type: :string
,
index_options:
'offsets'
indexes
:created_at
,
type: :date
indexes
:updated_at
,
type: :date
indexes
:state
,
type: :string
indexes
:project_id
,
type: :integer
indexes
:author_id
,
type: :integer
indexes
:project
,
type: :nested
indexes
:author
,
type: :nested
indexes
:updated_at_sort
,
type: :date
,
index: :not_analyzed
end
def
as_indexed_json
(
options
=
{})
as_json
(
include:
{
project:
{
only: :id
},
author:
{
only: :id
}
}
).
merge
({
updated_at_sort:
updated_at
})
end
def
self
.
elastic_search
(
query
,
options:
{})
options
[
:in
]
=
%w(title^2 description)
query_hash
=
basic_query_hash
(
options
[
:in
],
query
)
query_hash
=
project_ids_filter
(
query_hash
,
options
[
:projects_ids
])
self
.
__elasticsearch__
.
search
(
query_hash
)
end
end
end
app/elastic/merge_requests_search.rb
deleted
100644 → 0
View file @
63392cdc
module
MergeRequestsSearch
extend
ActiveSupport
::
Concern
included
do
include
ApplicationSearch
mappings
do
indexes
:id
,
type: :integer
indexes
:iid
,
type: :integer
indexes
:target_branch
,
type: :string
,
index_options:
'offsets'
indexes
:source_branch
,
type: :string
,
index_options:
'offsets'
indexes
:title
,
type: :string
,
index_options:
'offsets'
indexes
:description
,
type: :string
,
index_options:
'offsets'
indexes
:created_at
,
type: :date
indexes
:updated_at
,
type: :date
indexes
:state
,
type: :string
indexes
:merge_status
,
type: :string
indexes
:source_project_id
,
type: :integer
indexes
:target_project_id
,
type: :integer
indexes
:author_id
,
type: :integer
indexes
:source_project
,
type: :nested
indexes
:target_project
,
type: :nested
indexes
:author
,
type: :nested
indexes
:updated_at_sort
,
type: :string
,
index:
'not_analyzed'
end
def
as_indexed_json
(
options
=
{})
as_json
(
include:
{
source_project:
{
only: :id
},
target_project:
{
only: :id
},
author:
{
only: :id
}
}
).
merge
({
updated_at_sort:
updated_at
})
end
def
self
.
elastic_search
(
query
,
options:
{})
query_hash
=
basic_query_hash
(
%w(title^2 description)
,
query
)
if
options
[
:projects_ids
]
query_hash
[
:query
][
:filtered
][
:filter
]
=
{
and:
[
{
terms:
{
target_project_id:
[
options
[
:projects_ids
]].
flatten
}
}
]
}
end
self
.
__elasticsearch__
.
search
(
query_hash
)
end
end
end
app/elastic/milestones_search.rb
deleted
100644 → 0
View file @
63392cdc
module
MilestonesSearch
extend
ActiveSupport
::
Concern
included
do
include
ApplicationSearch
mappings
do
indexes
:id
,
type: :integer
indexes
:title
,
type: :string
,
index_options:
'offsets'
indexes
:description
,
type: :string
,
index_options:
'offsets'
indexes
:project_id
,
type: :integer
indexes
:created_at
,
type: :date
indexes
:updated_at_sort
,
type: :string
,
index:
'not_analyzed'
end
def
as_indexed_json
(
options
=
{})
as_json
.
merge
({
updated_at_sort:
updated_at
})
end
def
self
.
elastic_search
(
query
,
options:
{})
options
[
:in
]
=
%w(title^2 description)
query_hash
=
basic_query_hash
(
options
[
:in
],
query
)
query_hash
=
project_ids_filter
(
query_hash
,
options
[
:projects_ids
])
self
.
__elasticsearch__
.
search
(
query_hash
)
end
end
end
app/elastic/notes_search.rb
deleted
100644 → 0
View file @
63392cdc
module
NotesSearch
extend
ActiveSupport
::
Concern
included
do
include
ApplicationSearch
mappings
do
indexes
:id
,
type: :integer
indexes
:note
,
type: :string
,
index_options:
'offsets'
indexes
:project_id
,
type: :integer
indexes
:created_at
,
type: :date
indexes
:updated_at_sort
,
type: :string
,
index:
'not_analyzed'
end
def
as_indexed_json
(
options
=
{})
as_json
.
merge
({
updated_at_sort:
updated_at
})
end
def
self
.
elastic_search
(
query
,
options:
{})
options
[
:in
]
=
[
"note"
]
query_hash
=
{
query:
{
filtered:
{
query:
{
match:
{
note:
query
}
},
},
}
}
if
query
.
blank?
query_hash
[
:query
][
:filtered
][
:query
]
=
{
match_all:
{}
}
query_hash
[
:track_scores
]
=
true
end
query_hash
=
project_ids_filter
(
query_hash
,
options
[
:projects_ids
])
query_hash
[
:sort
]
=
[
{
updated_at_sort:
{
order: :desc
,
mode: :min
}
},
:_score
]
query_hash
[
:highlight
]
=
highlight_options
(
options
[
:in
])
self
.
__elasticsearch__
.
search
(
query_hash
)
end
end
end
app/elastic/projects_search.rb
deleted
100644 → 0
View file @
63392cdc
module
ProjectsSearch
extend
ActiveSupport
::
Concern
included
do
include
ApplicationSearch
mappings
do
indexes
:id
,
type: :integer
indexes
:name
,
type: :string
,
index_options:
'offsets'
indexes
:path
,
type: :string
,
index_options:
'offsets'
indexes
:name_with_namespace
,
type: :string
,
index_options:
'offsets'
indexes
:path_with_namespace
,
type: :string
,
index_options:
'offsets'
indexes
:description
,
type: :string
,
index_options:
'offsets'
indexes
:namespace_id
,
type: :integer
indexes
:created_at
,
type: :date
indexes
:archived
,
type: :boolean
indexes
:visibility_level
,
type: :integer
indexes
:last_activity_at
,
type: :date
indexes
:last_pushed_at
,
type: :date
end
def
as_indexed_json
(
options
=
{})
as_json
.
merge
({
name_with_namespace:
name_with_namespace
,
path_with_namespace:
path_with_namespace
})
end
def
self
.
elastic_search
(
query
,
options:
{})
options
[
:in
]
=
%w(name^10 name_with_namespace^2 path_with_namespace path^9)
query_hash
=
basic_query_hash
(
options
[
:in
],
query
)
filters
=
[]
if
options
[
:abandoned
]
filters
<<
{
range:
{
last_pushed_at:
{
lte:
"now-6M/m"
}
}
}
end
if
options
[
:with_push
]
filters
<<
{
not:
{
missing:
{
field: :last_pushed_at
,
existence:
true
,
null_value:
true
}
}
}
end
if
options
[
:namespace_id
]
filters
<<
{
terms:
{
namespace_id:
[
options
[
:namespace_id
]].
flatten
}
}
end
if
options
[
:non_archived
]
filters
<<
{
terms:
{
archived:
[
!
options
[
:non_archived
]].
flatten
}
}
end
if
options
[
:visibility_levels
]
filters
<<
{
terms:
{
visibility_level:
[
options
[
:visibility_levels
]].
flatten
}
}
end
if
!
options
[
:owner_id
].
blank?
filters
<<
{
nested:
{
path: :owner
,
filter:
{
term:
{
"owner.id"
=>
options
[
:owner_id
]
}
}
}
}
end
if
options
[
:pids
]
filters
<<
{
ids:
{
values:
options
[
:pids
]
}
}
end
query_hash
[
:query
][
:filtered
][
:filter
]
=
{
and:
filters
}
query_hash
[
:sort
]
=
[
:_score
]
self
.
__elasticsearch__
.
search
(
query_hash
)
end
end
end
app/elastic/repositories_search.rb
deleted
100644 → 0
View file @
63392cdc
module
RepositoriesSearch
extend
ActiveSupport
::
Concern
included
do
include
Elasticsearch
::
Git
::
Repository
self
.
__elasticsearch__
.
client
=
Elasticsearch
::
Client
.
new
(
host:
Gitlab
.
config
.
elasticsearch
.
host
,
port:
Gitlab
.
config
.
elasticsearch
.
port
)
def
repository_id
project
.
id
end
def
self
.
repositories_count
Project
.
count
end
def
client_for_indexing
self
.
__elasticsearch__
.
client
end
def
self
.
import
Repository
.
__elasticsearch__
.
create_index!
Project
.
find_each
do
|
project
|
if
project
.
repository
.
exists?
&&
!
project
.
repository
.
empty?
project
.
repository
.
index_commits
project
.
repository
.
index_blobs
end
end
end
end
end
app/elastic/snippets_search.rb
deleted
100644 → 0
View file @
63392cdc
module
SnippetsSearch
extend
ActiveSupport
::
Concern
included
do
include
ApplicationSearch
mappings
do
indexes
:id
,
type: :integer
indexes
:title
,
type: :string
,
index_options:
'offsets'
indexes
:file_name
,
type: :string
,
index_options:
'offsets'
indexes
:content
,
type: :string
,
index_options:
'offsets'
indexes
:created_at
,
type: :date
indexes
:updated_at
,
type: :date
indexes
:state
,
type: :string
indexes
:project_id
,
type: :integer
indexes
:author_id
,
type: :integer
indexes
:project
,
type: :nested
indexes
:author
,
type: :nested
indexes
:updated_at_sort
,
type: :date
,
index: :not_analyzed
end
def
as_indexed_json
(
options
=
{})
as_json
(
include:
{
project:
{
only: :id
},
author:
{
only: :id
}
}
)
end
def
self
.
elastic_search
(
query
,
options:
{})
query_hash
=
basic_query_hash
(
%w(title file_name)
,
query
)
query_hash
=
limit_ids
(
query_hash
,
options
[
:ids
])
self
.
__elasticsearch__
.
search
(
query_hash
)
end
def
self
.
elastic_search_code
(
query
,
options:
{})
query_hash
=
{
query:
{
filtered:
{
query:
{
match:
{
content:
query
}
},
},
}
}
query_hash
=
limit_ids
(
query_hash
,
options
[
:ids
])
query_hash
[
:sort
]
=
[
{
updated_at_sort:
{
order: :desc
,
mode: :min
}
},
:_score
]
query_hash
[
:highlight
]
=
{
fields:
{
content:
{}
}
}
self
.
__elasticsearch__
.
search
(
query_hash
)
end
def
self
.
limit_ids
(
query_hash
,
ids
)
if
ids
query_hash
[
:query
][
:filtered
][
:filter
]
=
{
and:
[
{
terms:
{
id:
ids
}
}
]
}
end
query_hash
end
end
end
app/elastic/wiki_repositories_search.rb
deleted
100644 → 0
View file @
63392cdc
module
WikiRepositoriesSearch
extend
ActiveSupport
::
Concern
included
do
include
Elasticsearch
::
Git
::
Repository
self
.
__elasticsearch__
.
client
=
Elasticsearch
::
Client
.
new
(
host:
Gitlab
.
config
.
elasticsearch
.
host
,
port:
Gitlab
.
config
.
elasticsearch
.
port
)
def
repository_id
"wiki_
#{
project
.
id
}
"
end
def
self
.
repositories_count
Project
.
where
(
wiki_enabled:
true
).
count
end
def
client_for_indexing
self
.
__elasticsearch__
.
client
end
def
self
.
import
ProjectWiki
.
__elasticsearch__
.
create_index!
Project
.
where
(
wiki_enabled:
true
).
find_each
do
|
project
|
unless
project
.
wiki
.
empty?
project
.
wiki
.
index_blobs
end
end
end
end
end
app/models/issue.rb
View file @
bbff948f
...
...
@@ -27,7 +27,7 @@ class Issue < ActiveRecord::Base
include
Referable
include
Sortable
include
Taskable
include
IssuesSearch
include
Elastic
::
IssuesSearch
WEIGHT_RANGE
=
1
..
9
...
...
app/models/merge_request.rb
View file @
bbff948f
...
...
@@ -35,7 +35,7 @@ class MergeRequest < ActiveRecord::Base
include
Referable
include
Sortable
include
Taskable
include
MergeRequestsSearch
include
Elastic
::
MergeRequestsSearch
belongs_to
:target_project
,
foreign_key: :target_project_id
,
class_name:
"Project"
belongs_to
:source_project
,
foreign_key: :source_project_id
,
class_name:
"Project"
...
...
app/models/milestone.rb
View file @
bbff948f
...
...
@@ -24,7 +24,7 @@ class Milestone < ActiveRecord::Base
include
Sortable
include
Referable
include
StripAttribute
include
MilestonesSearch
include
Elastic
::
MilestonesSearch
belongs_to
:project
has_many
:issues
...
...
app/models/note.rb
View file @
bbff948f
...
...
@@ -26,7 +26,7 @@ class Note < ActiveRecord::Base
include
Gitlab
::
CurrentSettings
include
Participable
include
Mentionable
include
NotesSearch
include
Elastic
::
NotesSearch
default_value_for
:system
,
false
...
...
app/models/project.rb
View file @
bbff948f
...
...
@@ -52,7 +52,7 @@ class Project < ActiveRecord::Base
include
AfterCommitQueue
include
CaseSensitivity
include
TokenAuthenticatable
include
ProjectsSearch
include
Elastic
::
ProjectsSearch
extend
Gitlab
::
ConfigHelper
...
...
app/models/project_wiki.rb
View file @
bbff948f
class
ProjectWiki
include
Gitlab
::
ShellAdapter
include
WikiRepositoriesSearch
include
Elastic
::
WikiRepositoriesSearch
MARKUPS
=
{
'Markdown'
=>
:md
,
...
...
app/models/repository.rb
View file @
bbff948f
require
'securerandom'
class
Repository
include
RepositoriesSearch
include
Elastic
::
RepositoriesSearch
class
CommitError
<
StandardError
;
end
...
...
app/models/snippet.rb
View file @
bbff948f
...
...
@@ -21,7 +21,7 @@ class Snippet < ActiveRecord::Base
include
Participable
include
Referable
include
Sortable
include
SnippetsSearch
include
Elastic
::
SnippetsSearch
default_value_for
:visibility_level
,
Snippet
::
PRIVATE
...
...
config/application.rb
View file @
bbff948f
...
...
@@ -16,8 +16,7 @@ module Gitlab
#{
config
.
root
}
/app/models/hooks
#{
config
.
root
}
/app/models/concerns
#{
config
.
root
}
/app/models/project_services
#{
config
.
root
}
/app/models/members
#{
config
.
root
}
/app/elastic)
)
#{
config
.
root
}
/app/models/members)
)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
...
...
lib/elastic/application_search.rb
0 → 100644
View file @
bbff948f
module
Elastic
module
ApplicationSearch
extend
ActiveSupport
::
Concern
included
do
include
Elasticsearch
::
Model
self
.
__elasticsearch__
.
client
=
Elasticsearch
::
Client
.
new
(
host:
Gitlab
.
config
.
elasticsearch
.
host
,
port:
Gitlab
.
config
.
elasticsearch
.
port
)
index_name
[
Rails
.
application
.
class
.
parent_name
.
downcase
,
self
.
name
.
downcase
,
Rails
.
env
].
join
(
'-'
)
settings
\
index:
{
analysis:
{
analyzer:
{
default
:{
tokenizer:
"standard"
,
filter:
[
"standard"
,
"lowercase"
,
"my_stemmer"
]
}
},
filter:
{
my_stemmer:
{
type:
"stemmer"
,
name:
"light_english"
}
}
}
}
if
Gitlab
.
config
.
elasticsearch
.
enabled
after_commit
on: :create
do
ElasticIndexerWorker
.
perform_async
(
:index
,
self
.
class
.
to_s
,
self
.
id
)
end
after_commit
on: :update
do
ElasticIndexerWorker
.
perform_async
(
:update
,
self
.
class
.
to_s
,
self
.
id
)
end
after_commit
on: :destroy
do
ElasticIndexerWorker
.
perform_async
(
:delete
,
self
.
class
.
to_s
,
self
.
id
)
end
end
end
module
ClassMethods
def
highlight_options
(
fields
)
es_fields
=
fields
.
map
{
|
field
|
field
.
split
(
'^'
).
first
}.
inject
({})
do
|
memo
,
field
|
memo
[
field
.
to_sym
]
=
{}
memo
end
{
fields:
es_fields
}
end
def
basic_query_hash
(
fields
,
query
)
query_hash
=
if
query
.
present?
{
query:
{
filtered:
{
query:
{
multi_match:
{
fields:
fields
,
query:
query
,
operator: :and
}
},
},
}
}
else
{
query:
{
filtered:
{
query:
{
match_all:
{}
}
}
},
track_scores:
true
}
end
query_hash
[
:sort
]
=
[
{
updated_at_sort:
{
order: :desc
,
mode: :min
}
},
:_score
]
query_hash
[
:highlight
]
=
highlight_options
(
fields
)
query_hash
end
def
project_ids_filter
(
query_hash
,
project_ids
)
if
project_ids
query_hash
[
:query
][
:filtered
][
:filter
]
=
{
and:
[
{
terms:
{
project_id:
project_ids
}
}
]
}
end
query_hash
end
end
end
end
lib/elastic/issues_search.rb
0 → 100644
View file @
bbff948f
module
Elastic
module
IssuesSearch
extend
ActiveSupport
::
Concern
included
do
include
ApplicationSearch
mappings
do
indexes
:id
,
type: :integer
indexes
:iid
,
type: :integer
,
index: :not_analyzed
indexes
:title
,
type: :string
,
index_options:
'offsets'
indexes
:description
,
type: :string
,
index_options:
'offsets'
indexes
:created_at
,
type: :date
indexes
:updated_at
,
type: :date
indexes
:state
,
type: :string
indexes
:project_id
,
type: :integer
indexes
:author_id
,
type: :integer
indexes
:project
,
type: :nested
indexes
:author
,
type: :nested
indexes
:updated_at_sort
,
type: :date
,
index: :not_analyzed
end
def
as_indexed_json
(
options
=
{})
as_json
(
include:
{
project:
{
only: :id
},
author:
{
only: :id
}
}
).
merge
({
updated_at_sort:
updated_at
})
end
def
self
.
elastic_search
(
query
,
options:
{})
options
[
:in
]
=
%w(title^2 description)
query_hash
=
basic_query_hash
(
options
[
:in
],
query
)
query_hash
=
project_ids_filter
(
query_hash
,
options
[
:projects_ids
])
self
.
__elasticsearch__
.
search
(
query_hash
)
end
end
end
end
lib/elastic/merge_requests_search.rb
0 → 100644
View file @
bbff948f
module
Elastic
module
MergeRequestsSearch
extend
ActiveSupport
::
Concern
included
do
include
ApplicationSearch
mappings
do
indexes
:id
,
type: :integer
indexes
:iid
,
type: :integer
indexes
:target_branch
,
type: :string
,
index_options:
'offsets'
indexes
:source_branch
,
type: :string
,
index_options:
'offsets'
indexes
:title
,
type: :string
,
index_options:
'offsets'
indexes
:description
,
type: :string
,
index_options:
'offsets'
indexes
:created_at
,
type: :date
indexes
:updated_at
,
type: :date
indexes
:state
,
type: :string
indexes
:merge_status
,
type: :string
indexes
:source_project_id
,
type: :integer
indexes
:target_project_id
,
type: :integer
indexes
:author_id
,
type: :integer
indexes
:source_project
,
type: :nested
indexes
:target_project
,
type: :nested
indexes
:author
,
type: :nested
indexes
:updated_at_sort
,
type: :string
,
index:
'not_analyzed'
end
def
as_indexed_json
(
options
=
{})
as_json
(
include:
{
source_project:
{
only: :id
},
target_project:
{
only: :id
},
author:
{
only: :id
}
}
).
merge
({
updated_at_sort:
updated_at
})
end
def
self
.
elastic_search
(
query
,
options:
{})
query_hash
=
basic_query_hash
(
%w(title^2 description)
,
query
)
if
options
[
:projects_ids
]
query_hash
[
:query
][
:filtered
][
:filter
]
=
{
and:
[
{
terms:
{
target_project_id:
[
options
[
:projects_ids
]].
flatten
}
}
]
}
end
self
.
__elasticsearch__
.
search
(
query_hash
)
end
end
end
end
\ No newline at end of file
lib/elastic/milestones_search.rb
0 → 100644
View file @
bbff948f
module
Elastic
module
MilestonesSearch
extend
ActiveSupport
::
Concern
included
do
include
ApplicationSearch
mappings
do
indexes
:id
,
type: :integer
indexes
:title
,
type: :string
,
index_options:
'offsets'
indexes
:description
,
type: :string
,
index_options:
'offsets'
indexes
:project_id
,
type: :integer
indexes
:created_at
,
type: :date
indexes
:updated_at_sort
,
type: :string
,
index:
'not_analyzed'
end
def
as_indexed_json
(
options
=
{})
as_json
.
merge
({
updated_at_sort:
updated_at
})
end
def
self
.
elastic_search
(
query
,
options:
{})
options
[
:in
]
=
%w(title^2 description)
query_hash
=
basic_query_hash
(
options
[
:in
],
query
)
query_hash
=
project_ids_filter
(
query_hash
,
options
[
:projects_ids
])
self
.
__elasticsearch__
.
search
(
query_hash
)
end
end
end
end
lib/elastic/notes_search.rb
0 → 100644
View file @
bbff948f
module
Elastic
module
NotesSearch
extend
ActiveSupport
::
Concern
included
do
include
ApplicationSearch
mappings
do
indexes
:id
,
type: :integer
indexes
:note
,
type: :string
,
index_options:
'offsets'
indexes
:project_id
,
type: :integer
indexes
:created_at
,
type: :date
indexes
:updated_at_sort
,
type: :string
,
index:
'not_analyzed'
end
def
as_indexed_json
(
options
=
{})
as_json
.
merge
({
updated_at_sort:
updated_at
})
end
def
self
.
elastic_search
(
query
,
options:
{})
options
[
:in
]
=
[
"note"
]
query_hash
=
{
query:
{
filtered:
{
query:
{
match:
{
note:
query
}
},
},
}
}
if
query
.
blank?
query_hash
[
:query
][
:filtered
][
:query
]
=
{
match_all:
{}
}
query_hash
[
:track_scores
]
=
true
end
query_hash
=
project_ids_filter
(
query_hash
,
options
[
:projects_ids
])
query_hash
[
:sort
]
=
[
{
updated_at_sort:
{
order: :desc
,
mode: :min
}
},
:_score
]
query_hash
[
:highlight
]
=
highlight_options
(
options
[
:in
])
self
.
__elasticsearch__
.
search
(
query_hash
)
end
end
end
end
lib/elastic/projects_search.rb
0 → 100644
View file @
bbff948f
module
Elastic
module
ProjectsSearch
extend
ActiveSupport
::
Concern
included
do
include
ApplicationSearch
mappings
do
indexes
:id
,
type: :integer
indexes
:name
,
type: :string
,
index_options:
'offsets'
indexes
:path
,
type: :string
,
index_options:
'offsets'
indexes
:name_with_namespace
,
type: :string
,
index_options:
'offsets'
indexes
:path_with_namespace
,
type: :string
,
index_options:
'offsets'
indexes
:description
,
type: :string
,
index_options:
'offsets'
indexes
:namespace_id
,
type: :integer
indexes
:created_at
,
type: :date
indexes
:archived
,
type: :boolean
indexes
:visibility_level
,
type: :integer
indexes
:last_activity_at
,
type: :date
indexes
:last_pushed_at
,
type: :date
end
def
as_indexed_json
(
options
=
{})
as_json
.
merge
({
name_with_namespace:
name_with_namespace
,
path_with_namespace:
path_with_namespace
})
end
def
self
.
elastic_search
(
query
,
options:
{})
options
[
:in
]
=
%w(name^10 name_with_namespace^2 path_with_namespace path^9)
query_hash
=
basic_query_hash
(
options
[
:in
],
query
)
filters
=
[]
if
options
[
:abandoned
]
filters
<<
{
range:
{
last_pushed_at:
{
lte:
"now-6M/m"
}
}
}
end
if
options
[
:with_push
]
filters
<<
{
not:
{
missing:
{
field: :last_pushed_at
,
existence:
true
,
null_value:
true
}
}
}
end
if
options
[
:namespace_id
]
filters
<<
{
terms:
{
namespace_id:
[
options
[
:namespace_id
]].
flatten
}
}
end
if
options
[
:non_archived
]
filters
<<
{
terms:
{
archived:
[
!
options
[
:non_archived
]].
flatten
}
}
end
if
options
[
:visibility_levels
]
filters
<<
{
terms:
{
visibility_level:
[
options
[
:visibility_levels
]].
flatten
}
}
end
if
!
options
[
:owner_id
].
blank?
filters
<<
{
nested:
{
path: :owner
,
filter:
{
term:
{
"owner.id"
=>
options
[
:owner_id
]
}
}
}
}
end
if
options
[
:pids
]
filters
<<
{
ids:
{
values:
options
[
:pids
]
}
}
end
query_hash
[
:query
][
:filtered
][
:filter
]
=
{
and:
filters
}
query_hash
[
:sort
]
=
[
:_score
]
self
.
__elasticsearch__
.
search
(
query_hash
)
end
end
end
end
\ No newline at end of file
lib/elastic/repositories_search.rb
0 → 100644
View file @
bbff948f
module
Elastic
module
RepositoriesSearch
extend
ActiveSupport
::
Concern
included
do
include
Elasticsearch
::
Git
::
Repository
self
.
__elasticsearch__
.
client
=
Elasticsearch
::
Client
.
new
(
host:
Gitlab
.
config
.
elasticsearch
.
host
,
port:
Gitlab
.
config
.
elasticsearch
.
port
)
def
repository_id
project
.
id
end
def
self
.
repositories_count
Project
.
count
end
def
client_for_indexing
self
.
__elasticsearch__
.
client
end
def
self
.
import
Repository
.
__elasticsearch__
.
create_index!
Project
.
find_each
do
|
project
|
if
project
.
repository
.
exists?
&&
!
project
.
repository
.
empty?
project
.
repository
.
index_commits
project
.
repository
.
index_blobs
end
end
end
end
end
end
\ No newline at end of file
lib/elastic/snippets_search.rb
0 → 100644
View file @
bbff948f
module
Elastic
module
SnippetsSearch
extend
ActiveSupport
::
Concern
included
do
include
ApplicationSearch
mappings
do
indexes
:id
,
type: :integer
indexes
:title
,
type: :string
,
index_options:
'offsets'
indexes
:file_name
,
type: :string
,
index_options:
'offsets'
indexes
:content
,
type: :string
,
index_options:
'offsets'
indexes
:created_at
,
type: :date
indexes
:updated_at
,
type: :date
indexes
:state
,
type: :string
indexes
:project_id
,
type: :integer
indexes
:author_id
,
type: :integer
indexes
:project
,
type: :nested
indexes
:author
,
type: :nested
indexes
:updated_at_sort
,
type: :date
,
index: :not_analyzed
end
def
as_indexed_json
(
options
=
{})
as_json
(
include:
{
project:
{
only: :id
},
author:
{
only: :id
}
}
)
end
def
self
.
elastic_search
(
query
,
options:
{})
query_hash
=
basic_query_hash
(
%w(title file_name)
,
query
)
query_hash
=
limit_ids
(
query_hash
,
options
[
:ids
])
self
.
__elasticsearch__
.
search
(
query_hash
)
end
def
self
.
elastic_search_code
(
query
,
options:
{})
query_hash
=
{
query:
{
filtered:
{
query:
{
match:
{
content:
query
}
},
},
}
}
query_hash
=
limit_ids
(
query_hash
,
options
[
:ids
])
query_hash
[
:sort
]
=
[
{
updated_at_sort:
{
order: :desc
,
mode: :min
}
},
:_score
]
query_hash
[
:highlight
]
=
{
fields:
{
content:
{}
}
}
self
.
__elasticsearch__
.
search
(
query_hash
)
end
def
self
.
limit_ids
(
query_hash
,
ids
)
if
ids
query_hash
[
:query
][
:filtered
][
:filter
]
=
{
and:
[
{
terms:
{
id:
ids
}
}
]
}
end
query_hash
end
end
end
end
\ No newline at end of file
lib/elastic/wiki_repositories_search.rb
0 → 100644
View file @
bbff948f
module
Elastic
module
WikiRepositoriesSearch
extend
ActiveSupport
::
Concern
included
do
include
Elasticsearch
::
Git
::
Repository
self
.
__elasticsearch__
.
client
=
Elasticsearch
::
Client
.
new
(
host:
Gitlab
.
config
.
elasticsearch
.
host
,
port:
Gitlab
.
config
.
elasticsearch
.
port
)
def
repository_id
"wiki_
#{
project
.
id
}
"
end
def
self
.
repositories_count
Project
.
where
(
wiki_enabled:
true
).
count
end
def
client_for_indexing
self
.
__elasticsearch__
.
client
end
def
self
.
import
ProjectWiki
.
__elasticsearch__
.
create_index!
Project
.
where
(
wiki_enabled:
true
).
find_each
do
|
project
|
unless
project
.
wiki
.
empty?
project
.
wiki
.
index_blobs
end
end
end
end
end
end
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment