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
f95c84ae
Commit
f95c84ae
authored
Jan 18, 2016
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ES: tests fix, refactoring
parent
6040e1ba
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
78 additions
and
152 deletions
+78
-152
app/elastic/application_search.rb
app/elastic/application_search.rb
+39
-12
app/elastic/issues_search.rb
app/elastic/issues_search.rb
+1
-18
app/elastic/merge_requests_search.rb
app/elastic/merge_requests_search.rb
+9
-22
app/elastic/milestones_search.rb
app/elastic/milestones_search.rb
+1
-18
app/elastic/notes_search.rb
app/elastic/notes_search.rb
+2
-2
app/elastic/projects_search.rb
app/elastic/projects_search.rb
+12
-32
app/elastic/snippets_search.rb
app/elastic/snippets_search.rb
+2
-19
app/elastic/users_search.rb
app/elastic/users_search.rb
+2
-19
lib/gitlab/elastic/project_search_results.rb
lib/gitlab/elastic/project_search_results.rb
+3
-3
lib/gitlab/elastic/search_results.rb
lib/gitlab/elastic/search_results.rb
+5
-5
lib/gitlab/elastic/snippet_search_results.rb
lib/gitlab/elastic/snippet_search_results.rb
+2
-2
No files found.
app/elastic/application_search.rb
View file @
f95c84ae
...
...
@@ -14,13 +14,13 @@ module ApplicationSearch
default_field: :name
},
analysis:
{
:analyzer
=>
{
:my_analyzer
=>
{
analyzer:
{
my_analyzer
:
{
type:
"custom"
,
tokenizer:
"ngram_tokenizer"
,
filter:
%w(lowercase asciifolding name_ngrams)
},
:search_analyzer
=>
{
search_analyzer:
{
type:
"custom"
,
tokenizer:
"standard"
,
filter:
%w(lowercase asciifolding)
...
...
@@ -59,14 +59,41 @@ module ApplicationSearch
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
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
{
fields:
es_fields
}
end
end
def
basic_query_hash
(
fields
,
query
)
if
query
.
present?
{
query:
{
filtered:
{
query:
{
multi_match:
{
fields:
fields
,
query:
query
,
operator: :and
}
},
},
}
}
else
query_hash
=
{
query:
{
filtered:
{
query:
{
match_all:
{}
}
}
},
track_scores:
true
}
end
end
end
end
app/elastic/issues_search.rb
View file @
f95c84ae
...
...
@@ -35,24 +35,7 @@ module IssuesSearch
def
self
.
elastic_search
(
query
,
options:
{})
options
[
:in
]
=
%w(title^2 description)
query_hash
=
{
query:
{
filtered:
{
query:
{
multi_match:
{
fields:
options
[
:in
],
query:
"
#{
query
}
"
,
operator: :and
}
},
},
}
}
if
query
.
blank?
query_hash
[
:query
][
:filtered
][
:query
]
=
{
match_all:
{}}
query_hash
[
:track_scores
]
=
true
end
query_hash
=
basic_query_hash
(
options
[
:in
],
query
)
if
options
[
:projects_ids
]
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
...
...
app/elastic/merge_requests_search.rb
View file @
f95c84ae
...
...
@@ -41,34 +41,21 @@ module MergeRequestsSearch
def
self
.
elastic_search
(
query
,
options:
{})
options
[
:in
]
=
%w(title^2 description)
query_hash
=
{
query:
{
filtered:
{
query:
{
multi_match:
{
fields:
options
[
:in
],
query:
"
#{
query
}
"
,
operator: :and
}
},
},
}
}
if
query
.
blank?
query_hash
[
:query
][
:filtered
][
:query
]
=
{
match_all:
{}}
query_hash
[
:track_scores
]
=
true
end
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
{
terms:
{
source_project_id:
[
options
[
:projects_ids
]].
flatten
}
},
terms:
{
target_project_id:
[
options
[
:projects_ids
]].
flatten
{
terms:
{
target_project_id:
[
options
[
:projects_ids
]].
flatten
}
}
]
}
...
...
app/elastic/milestones_search.rb
View file @
f95c84ae
...
...
@@ -21,24 +21,7 @@ module MilestonesSearch
def
self
.
elastic_search
(
query
,
options:
{})
options
[
:in
]
=
%w(title^2 description)
query_hash
=
{
query:
{
filtered:
{
query:
{
multi_match:
{
fields:
options
[
:in
],
query:
"
#{
query
}
"
,
operator: :and
}
},
},
}
}
if
query
.
blank?
query_hash
[
:query
][
:filtered
][
:query
]
=
{
match_all:
{}}
query_hash
[
:track_scores
]
=
true
end
query_hash
=
basic_query_hash
(
options
[
:in
],
query
)
if
options
[
:project_ids
]
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
...
...
app/elastic/notes_search.rb
View file @
f95c84ae
...
...
@@ -23,13 +23,13 @@ module NotesSearch
query_hash
=
{
query:
{
filtered:
{
query:
{
match:
{
note:
query
}
},
query:
{
match:
{
note:
query
}
},
},
}
}
if
query
.
blank?
query_hash
[
:query
][
:filtered
][
:query
]
=
{
match_all:
{}}
query_hash
[
:query
][
:filtered
][
:query
]
=
{
match_all:
{}
}
query_hash
[
:track_scores
]
=
true
end
...
...
app/elastic/projects_search.rb
View file @
f95c84ae
...
...
@@ -32,28 +32,12 @@ module ProjectsSearch
def
self
.
elastic_search
(
query
,
options:
{})
options
[
:in
]
=
%w(name^10 name_with_namespace^2 path_with_namespace path^9)
query_hash
=
{
query:
{
filtered:
{
query:
{
multi_match:
{
fields:
options
[
:in
],
query:
"
#{
query
}
"
,
operator: :and
}
},
},
},
}
if
query
.
blank?
query_hash
[
:query
][
:filtered
][
:query
]
=
{
match_all:
{}
}
query_hash
[
:track_scores
]
=
true
end
query_hash
=
basic_query_hash
(
options
[
:in
],
query
)
filters
=
[]
if
options
[
:abandoned
]
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
query_hash
[
:query
][
:filtered
][
:filter
][
:and
]
<<
{
filters
<<
{
range:
{
last_pushed_at:
{
lte:
"now-6M/m"
...
...
@@ -63,8 +47,7 @@ module ProjectsSearch
end
if
options
[
:with_push
]
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
query_hash
[
:query
][
:filtered
][
:filter
][
:and
]
<<
{
filters
<<
{
not:
{
missing:
{
field: :last_pushed_at
,
...
...
@@ -76,8 +59,7 @@ module ProjectsSearch
end
if
options
[
:namespace_id
]
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
query_hash
[
:query
][
:filtered
][
:filter
][
:and
]
<<
{
filters
<<
{
terms:
{
namespace_id:
[
options
[
:namespace_id
]].
flatten
}
...
...
@@ -85,8 +67,7 @@ module ProjectsSearch
end
if
options
[
:non_archived
]
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
query_hash
[
:query
][
:filtered
][
:filter
][
:and
]
<<
{
filters
<<
{
terms:
{
archived:
[
!
options
[
:non_archived
]].
flatten
}
...
...
@@ -94,8 +75,7 @@ module ProjectsSearch
end
if
options
[
:visibility_levels
]
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
query_hash
[
:query
][
:filtered
][
:filter
][
:and
]
<<
{
filters
<<
{
terms:
{
visibility_level:
[
options
[
:visibility_levels
]].
flatten
}
...
...
@@ -103,8 +83,7 @@ module ProjectsSearch
end
if
!
options
[
:owner_id
].
blank?
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
query_hash
[
:query
][
:filtered
][
:filter
][
:and
]
<<
{
filters
<<
{
nested:
{
path: :owner
,
filter:
{
...
...
@@ -115,14 +94,15 @@ module ProjectsSearch
end
if
options
[
:pids
]
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
query_hash
[
:query
][
:filtered
][
:filter
][
:and
]
<<
{
filters
<<
{
ids:
{
values:
options
[
:pids
]
}
}
end
query_hash
[
:query
][
:filtered
][
:filter
]
=
{
and:
filters
}
query_hash
[
:sort
]
=
[
:_score
]
query_hash
[
:highlight
]
=
highlight_options
(
options
[
:in
])
...
...
app/elastic/snippets_search.rb
View file @
f95c84ae
...
...
@@ -35,24 +35,7 @@ module SnippetsSearch
def
self
.
elastic_search
(
query
,
options:
{})
options
[
:in
]
=
%w(title file_name)
query_hash
=
{
query:
{
filtered:
{
query:
{
multi_match:
{
fields:
options
[
:in
],
query:
"
#{
query
}
"
,
operator: :and
}
},
},
}
}
if
query
.
blank?
query_hash
[
:query
][
:filtered
][
:query
]
=
{
match_all:
{}}
query_hash
[
:track_scores
]
=
true
end
query_hash
=
basic_query_hash
(
options
[
:in
],
query
)
if
options
[
:ids
]
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
...
...
@@ -79,7 +62,7 @@ module SnippetsSearch
query_hash
=
{
query:
{
filtered:
{
query:
{
match:
{
content:
query
}
},
query:
{
match:
{
content:
query
}
},
},
}
}
...
...
app/elastic/users_search.rb
View file @
f95c84ae
...
...
@@ -30,27 +30,11 @@ module UsersSearch
def
self
.
elastic_search
(
query
,
options:
{})
options
[
:in
]
=
%w(name^3 username^2 email)
query_hash
=
{
query:
{
filtered:
{
query:
{
multi_match:
{
fields:
options
[
:in
],
query:
"
#{
query
}
"
,
operator: :and
}
},
},
}
}
query_hash
=
basic_query_hash
(
options
[
:in
],
query
)
if
query
.
blank?
query_hash
[
:query
][
:filtered
][
:query
]
=
{
match_all:
{}}
query_hash
[
:track_scores
]
=
true
end
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
if
options
[
:uids
]
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
query_hash
[
:query
][
:filtered
][
:filter
][
:and
]
<<
{
ids:
{
values:
options
[
:uids
]
...
...
@@ -59,7 +43,6 @@ module UsersSearch
end
if
options
[
:active
]
query_hash
[
:query
][
:filtered
][
:filter
]
||=
{
and:
[]
}
query_hash
[
:query
][
:filtered
][
:filter
][
:and
]
<<
{
terms:
{
state:
[
"active"
]
...
...
lib/gitlab/elastic/project_search_results.rb
View file @
f95c84ae
...
...
@@ -60,7 +60,7 @@ module Gitlab
project
.
repository
.
search
(
query
,
type: :blob
,
options:
{
highlight:
true
}
options:
{
highlight:
true
}
)[
:blobs
][
:results
].
response
else
Kaminari
.
paginate_array
(
...
...
@@ -75,7 +75,7 @@ module Gitlab
project
.
wiki
.
search
(
query
,
type: :blob
,
options:
{
highlight:
true
}
options:
{
highlight:
true
}
)[
:blobs
][
:results
].
response
else
Kaminari
.
paginate_array
([])
...
...
@@ -113,4 +113,4 @@ module Gitlab
end
end
end
end
\ No newline at end of file
end
lib/gitlab/elastic/search_results.rb
View file @
f95c84ae
...
...
@@ -67,9 +67,9 @@ module Gitlab
}
if
query
=~
/#(\d+)\z/
issues
=
Issue
.
where
(
project_id:
limit_project_ids
).
where
(
iid:
$1
)
Issue
.
where
(
project_id:
limit_project_ids
).
where
(
iid:
$1
)
else
issues
=
Issue
.
elastic_search
(
query
,
options:
opt
)
Issue
.
elastic_search
(
query
,
options:
opt
)
end
end
...
...
@@ -78,7 +78,7 @@ module Gitlab
projects_ids:
limit_project_ids
}
milestones
=
Milestone
.
elastic_search
(
query
,
options:
opt
)
Milestone
.
elastic_search
(
query
,
options:
opt
)
end
def
merge_requests
...
...
@@ -87,9 +87,9 @@ module Gitlab
}
if
query
=~
/[#!](\d+)\z/
merge_requests
=
MergeRequest
.
in_projects
(
limit_project_ids
).
where
(
iid:
$1
)
MergeRequest
.
in_projects
(
limit_project_ids
).
where
(
iid:
$1
)
else
merge_requests
=
MergeRequest
.
elastic_search
(
query
,
options:
opt
)
MergeRequest
.
elastic_search
(
query
,
options:
opt
)
end
end
...
...
lib/gitlab/elastic/snippet_search_results.rb
View file @
f95c84ae
...
...
@@ -16,8 +16,8 @@ module Gitlab
# We process whole list of items then paginate it. Not too smart
# Should be refactored in the CE side first to prevent conflicts hell
Kaminari
.
paginate_array
(
snippet_blobs
.
records
.
map
do
|
snippet
|
chunk_snippet
(
snippet
)
snippet_blobs
.
records
.
map
do
|
snippet
|
chunk_snippet
(
snippet
)
end
).
page
(
page
).
per
(
per_page
)
else
...
...
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