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
5c6312f3
Commit
5c6312f3
authored
Jan 18, 2016
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ES: one more refactoring
parent
15566190
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
64 additions
and
166 deletions
+64
-166
app/elastic/application_search.rb
app/elastic/application_search.rb
+41
-22
app/elastic/issues_search.rb
app/elastic/issues_search.rb
+1
-15
app/elastic/merge_requests_search.rb
app/elastic/merge_requests_search.rb
+14
-20
app/elastic/milestones_search.rb
app/elastic/milestones_search.rb
+1
-16
app/elastic/notes_search.rb
app/elastic/notes_search.rb
+1
-8
app/elastic/projects_search.rb
app/elastic/projects_search.rb
+0
-3
app/elastic/snippets_search.rb
app/elastic/snippets_search.rb
+5
-20
app/elastic/users_search.rb
app/elastic/users_search.rb
+0
-60
app/models/user.rb
app/models/user.rb
+0
-1
lib/tasks/gitlab/elastic.rake
lib/tasks/gitlab/elastic.rake
+1
-1
No files found.
app/elastic/application_search.rb
View file @
5c6312f3
...
...
@@ -70,30 +70,49 @@ module ApplicationSearch
end
def
basic_query_hash
(
fields
,
query
)
if
query
.
present?
{
query:
{
filtered:
{
query:
{
multi_match:
{
fields:
fields
,
query:
query
,
operator: :and
}
},
},
}
}
else
{
query:
{
filtered:
{
query:
{
match_all:
{}
}
}
},
track_scores:
true
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
View file @
5c6312f3
...
...
@@ -37,22 +37,8 @@ module IssuesSearch
query_hash
=
basic_query_hash
(
options
[
:in
],
query
)
if
options
[
:projects_ids
]
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
query_hash
[
:query
][
:filtered
][
:filter
][
:and
]
<<
{
terms:
{
project_id:
[
options
[
:projects_ids
]].
flatten
}
}
end
query_hash
[
:sort
]
=
[
{
updated_at_sort:
{
order: :desc
,
mode: :min
}
},
:_score
]
query_hash
=
project_ids_filter
(
query_hash
,
options
[
:projects_ids
])
query_hash
[
:highlight
]
=
{
fields:
options
[
:in
].
inject
({})
{
|
a
,
o
|
a
[
o
.
to_sym
]
=
{}
}
}
self
.
__elasticsearch__
.
search
(
query_hash
)
end
end
...
...
app/elastic/merge_requests_search.rb
View file @
5c6312f3
...
...
@@ -44,30 +44,24 @@ module MergeRequestsSearch
query_hash
=
basic_query_hash
(
options
[
:in
],
query
)
if
options
[
:projects_ids
]
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
query_hash
[
:query
][
:filtered
][
:filter
][
:and
]
<<
{
or:
[
{
terms:
{
source_project_id:
[
options
[
:projects_ids
]].
flatten
query_hash
[
:query
][
:filtered
][
:filter
]
=
{
and:
[{
or:
[
{
terms:
{
source_project_id:
[
options
[
:projects_ids
]].
flatten
}
},
{
terms:
{
target_project_id:
[
options
[
:projects_ids
]].
flatten
}
}
},
{
terms:
{
target_project_id:
[
options
[
:projects_ids
]].
flatten
}
}
]
]
}]
}
end
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
...
...
app/elastic/milestones_search.rb
View file @
5c6312f3
...
...
@@ -23,22 +23,7 @@ module MilestonesSearch
query_hash
=
basic_query_hash
(
options
[
:in
],
query
)
if
options
[
:project_ids
]
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
query_hash
[
:query
][
:filtered
][
:filter
][
:and
]
<<
{
terms:
{
project_id:
[
options
[
:project_ids
]].
flatten
}
}
end
query_hash
[
:sort
]
=
[
{
updated_at_sort:
{
order: :desc
,
mode: :min
}
},
:_score
]
query_hash
[
:highlight
]
=
highlight_options
(
options
[
:in
])
query_hash
=
project_ids_filter
(
query_hash
,
options
[
:projects_ids
])
self
.
__elasticsearch__
.
search
(
query_hash
)
end
...
...
app/elastic/notes_search.rb
View file @
5c6312f3
...
...
@@ -33,14 +33,7 @@ module NotesSearch
query_hash
[
:track_scores
]
=
true
end
if
options
[
:project_ids
]
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
query_hash
[
:query
][
:filtered
][
:filter
][
:and
]
<<
{
terms:
{
project_id:
[
options
[
:project_ids
]].
flatten
}
}
end
query_hash
=
project_ids_filter
(
query_hash
,
options
[
:projects_ids
])
query_hash
[
:sort
]
=
[
{
updated_at_sort:
{
order: :desc
,
mode: :min
}
},
...
...
app/elastic/projects_search.rb
View file @
5c6312f3
...
...
@@ -105,9 +105,6 @@ module ProjectsSearch
query_hash
[
:sort
]
=
[
:_score
]
query_hash
[
:highlight
]
=
highlight_options
(
options
[
:in
])
self
.
__elasticsearch__
.
search
(
query_hash
)
end
end
...
...
app/elastic/snippets_search.rb
View file @
5c6312f3
...
...
@@ -38,27 +38,15 @@ module SnippetsSearch
query_hash
=
basic_query_hash
(
options
[
:in
],
query
)
if
options
[
:ids
]
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
query_hash
[
:query
][
:filtered
][
:filter
][
:and
]
<<
{
terms:
{
id:
[
options
[
:ids
]].
flatten
}
query_hash
[
:query
][
:filtered
][
:filter
]
=
{
and:
[
{
terms:
{
id:
[
options
[
:ids
]].
flatten
}
}
]
}
end
query_hash
[
:sort
]
=
[
{
updated_at_sort:
{
order: :desc
,
mode: :min
}
},
:_score
]
query_hash
[
:highlight
]
=
{
fields:
options
[
:in
].
inject
({})
{
|
a
,
o
|
a
[
o
.
to_sym
]
=
{}
}
}
self
.
__elasticsearch__
.
search
(
query_hash
)
end
def
self
.
elastic_search_code
(
query
,
options:
{})
options
[
:in
]
=
%w(title file_name)
query_hash
=
{
query:
{
filtered:
{
...
...
@@ -68,11 +56,8 @@ module SnippetsSearch
}
if
options
[
:ids
]
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
query_hash
[
:query
][
:filtered
][
:filter
][
:and
]
<<
{
terms:
{
id:
[
options
[
:ids
]].
flatten
}
query_hash
[
:query
][
:filtered
][
:filter
]
=
{
and:
[
{
terms:
{
id:
[
options
[
:ids
]].
flatten
}
}
]
}
end
...
...
@@ -81,7 +66,7 @@ module SnippetsSearch
:_score
]
query_hash
[
:highlight
]
=
{
fields:
options
[
:in
].
inject
({})
{
|
a
,
o
|
a
[
o
.
to_sym
]
=
{}
}
}
query_hash
[
:highlight
]
=
{
fields:
{
content:
{}
}
}
self
.
__elasticsearch__
.
search
(
query_hash
)
end
...
...
app/elastic/users_search.rb
deleted
100644 → 0
View file @
15566190
module
UsersSearch
extend
ActiveSupport
::
Concern
included
do
include
ApplicationSearch
mappings
do
indexes
:id
,
type: :integer
indexes
:email
,
type: :string
,
index_options:
'offsets'
,
search_analyzer: :search_analyzer
,
analyzer: :my_analyzer
indexes
:name
,
type: :string
,
index_options:
'offsets'
,
search_analyzer: :search_analyzer
,
analyzer: :my_analyzer
indexes
:username
,
type: :string
,
index_options:
'offsets'
,
search_analyzer: :search_analyzer
,
analyzer: :my_analyzer
indexes
:bio
,
type: :string
indexes
:skype
,
type: :string
,
index_options:
'offsets'
,
search_analyzer: :search_analyzer
,
analyzer: :my_analyzer
indexes
:linkedin
,
type: :string
indexes
:twitter
,
type: :string
,
index_options:
'offsets'
,
search_analyzer: :search_analyzer
,
analyzer: :my_analyzer
indexes
:state
,
type: :string
indexes
:website_url
,
type: :string
indexes
:created_at
,
type: :date
indexes
:admin
,
type: :boolean
end
def
as_indexed_json
(
options
=
{})
as_json
.
merge
({
name_sort:
name
.
downcase
,
updated_at_sort:
updated_at
,
created_at_sort:
created_at
})
end
def
self
.
elastic_search
(
query
,
options:
{})
options
[
:in
]
=
%w(name^3 username^2 email)
query_hash
=
basic_query_hash
(
options
[
:in
],
query
)
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
if
options
[
:uids
]
query_hash
[
:query
][
:filtered
][
:filter
][
:and
]
<<
{
ids:
{
values:
options
[
:uids
]
}
}
end
if
options
[
:active
]
query_hash
[
:query
][
:filtered
][
:filter
][
:and
]
<<
{
terms:
{
state:
[
"active"
]
}
}
end
query_hash
[
:sort
]
=
[
:_score
]
query_hash
[
:highlight
]
=
highlight_options
(
options
[
:in
])
self
.
__elasticsearch__
.
search
(
query_hash
)
end
end
end
app/models/user.rb
View file @
5c6312f3
...
...
@@ -73,7 +73,6 @@ class User < ActiveRecord::Base
include
Sortable
include
CaseSensitivity
include
TokenAuthenticatable
include
UsersSearch
add_authentication_token_field
:authentication_token
...
...
lib/tasks/gitlab/elastic.rake
View file @
5c6312f3
...
...
@@ -12,7 +12,7 @@ namespace :gitlab do
desc
"Create indexes in the Elasticsearch from database records"
task
create_index: :environment
do
[
Project
,
User
,
Issue
,
MergeRequest
,
Snippet
,
Note
,
Milestone
].
each
do
|
klass
|
[
Project
,
Issue
,
MergeRequest
,
Snippet
,
Note
,
Milestone
].
each
do
|
klass
|
klass
.
__elasticsearch__
.
create_index!
klass
.
import
end
...
...
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