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
38dc25db
Commit
38dc25db
authored
Mar 03, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix search by iid when Elasticsearch is enabled
parent
c8bbbdc7
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
130 additions
and
15 deletions
+130
-15
lib/elastic/application_search.rb
lib/elastic/application_search.rb
+11
-1
lib/elastic/issues_search.rb
lib/elastic/issues_search.rb
+5
-3
lib/elastic/merge_requests_search.rb
lib/elastic/merge_requests_search.rb
+5
-1
lib/gitlab/elastic/search_results.rb
lib/gitlab/elastic/search_results.rb
+2
-10
spec/lib/gitlab/elastic/search_results_spec.rb
spec/lib/gitlab/elastic/search_results_spec.rb
+107
-0
No files found.
lib/elastic/application_search.rb
View file @
38dc25db
...
...
@@ -95,6 +95,16 @@ module Elastic
query_hash
end
def
iid_query_hash
(
query_hash
,
iid
)
{
query:
{
filtered:
{
query:
{
match:
{
iid:
iid
}
}
}
}
}
end
def
project_ids_filter
(
query_hash
,
project_ids
)
if
project_ids
query_hash
[
:query
][
:filtered
][
:filter
]
=
{
...
...
lib/elastic/issues_search.rb
View file @
38dc25db
...
...
@@ -36,9 +36,11 @@ module Elastic
end
def
self
.
elastic_search
(
query
,
options:
{})
options
[
:in
]
=
%w(title^2 description)
query_hash
=
basic_query_hash
(
options
[
:in
],
query
)
if
query
=~
/#(\d+)\z/
query_hash
=
iid_query_hash
(
query_hash
,
$1
)
else
query_hash
=
basic_query_hash
(
%w(title^2 description)
,
query
)
end
query_hash
=
project_ids_filter
(
query_hash
,
options
[
:projects_ids
])
...
...
lib/elastic/merge_requests_search.rb
View file @
38dc25db
...
...
@@ -59,7 +59,11 @@ module Elastic
end
def
self
.
elastic_search
(
query
,
options:
{})
if
query
=~
/#(\d+)\z/
query_hash
=
iid_query_hash
(
query_hash
,
$1
)
else
query_hash
=
basic_query_hash
(
%w(title^2 description)
,
query
)
end
if
options
[
:projects_ids
]
query_hash
[
:query
][
:filtered
][
:filter
]
=
{
...
...
lib/gitlab/elastic/search_results.rb
View file @
38dc25db
...
...
@@ -66,12 +66,8 @@ module Gitlab
projects_ids:
limit_project_ids
}
if
query
=~
/#(\d+)\z/
Issue
.
in_projects
(
limit_project_ids
).
where
(
iid:
$1
)
else
Issue
.
elastic_search
(
query
,
options:
opt
)
end
end
def
milestones
opt
=
{
...
...
@@ -86,12 +82,8 @@ module Gitlab
projects_ids:
limit_project_ids
}
if
query
=~
/[#!](\d+)\z/
MergeRequest
.
in_projects
(
limit_project_ids
).
where
(
iid:
$1
)
else
MergeRequest
.
elastic_search
(
query
,
options:
opt
)
end
end
def
default_scope
'projects'
...
...
spec/lib/gitlab/elastic/search_results_spec.rb
0 → 100644
View file @
38dc25db
require
'spec_helper'
describe
Gitlab
::
Elastic
::
SearchResults
,
lib:
true
do
before
do
allow
(
Gitlab
.
config
.
elasticsearch
).
to
receive
(
:enabled
).
and_return
(
true
)
Issue
.
__elasticsearch__
.
create_index!
MergeRequest
.
__elasticsearch__
.
create_index!
end
after
do
allow
(
Gitlab
.
config
.
elasticsearch
).
to
receive
(
:enabled
).
and_return
(
false
)
Issue
.
__elasticsearch__
.
delete_index!
MergeRequest
.
__elasticsearch__
.
delete_index!
end
let
(
:project_1
)
{
create
(
:project
)
}
let
(
:project_2
)
{
create
(
:project
)
}
let
(
:limit_project_ids
)
{
[
project_1
.
id
]
}
describe
'issues'
do
let!
(
:issue_1
)
{
create
(
:issue
,
project:
project_1
,
title:
'Hello world, here I am!'
,
iid:
1
)
}
let!
(
:issue_2
)
{
create
(
:issue
,
project:
project_1
,
title:
'Issue 2'
,
description:
'Hello world, here I am!'
,
iid:
2
)
}
let!
(
:issue_3
)
{
create
(
:issue
,
project:
project_2
,
title:
'Issue 3'
,
iid:
2
)
}
before
do
Issue
.
__elasticsearch__
.
refresh_index!
end
it
'should list issues that title or description contain the query'
do
results
=
described_class
.
new
(
limit_project_ids
,
'hello world'
)
issues
=
results
.
objects
(
'issues'
)
expect
(
issues
).
to
include
issue_1
expect
(
issues
).
to
include
issue_2
expect
(
issues
).
not_to
include
issue_3
expect
(
results
.
issues_count
).
to
eq
2
end
it
'should return empty list when issues title or description does not contain the query'
do
results
=
described_class
.
new
(
limit_project_ids
,
'security'
)
expect
(
results
.
objects
(
'issues'
)).
to
be_empty
expect
(
results
.
issues_count
).
to
eq
0
end
it
'should list issue when search by a valid iid'
do
results
=
described_class
.
new
(
limit_project_ids
,
'#2'
)
issues
=
results
.
objects
(
'issues'
)
expect
(
issues
).
not_to
include
issue_1
expect
(
issues
).
to
include
issue_2
expect
(
issues
).
not_to
include
issue_3
expect
(
results
.
issues_count
).
to
eq
1
end
it
'should return empty list when search by invalid iid'
do
results
=
described_class
.
new
(
limit_project_ids
,
'#222'
)
expect
(
results
.
objects
(
'issues'
)).
to
be_empty
expect
(
results
.
issues_count
).
to
eq
0
end
end
describe
'merge requests'
do
let!
(
:merge_request_1
)
{
create
(
:merge_request
,
source_project:
project_1
,
target_project:
project_1
,
title:
'Hello world, here I am!'
,
iid:
1
)
}
let!
(
:merge_request_2
)
{
create
(
:merge_request
,
:conflict
,
source_project:
project_1
,
target_project:
project_1
,
title:
'Merge Request 2'
,
description:
'Hello world, here I am!'
,
iid:
2
)
}
let!
(
:merge_request_3
)
{
create
(
:merge_request
,
source_project:
project_2
,
target_project:
project_2
,
title:
'Merge Request 3'
,
iid:
2
)
}
before
do
MergeRequest
.
__elasticsearch__
.
refresh_index!
end
it
'should list merge requests that title or description contain the query'
do
results
=
described_class
.
new
(
limit_project_ids
,
'hello world'
)
merge_requests
=
results
.
objects
(
'merge_requests'
)
expect
(
merge_requests
).
to
include
merge_request_1
expect
(
merge_requests
).
to
include
merge_request_2
expect
(
merge_requests
).
not_to
include
merge_request_3
expect
(
results
.
merge_requests_count
).
to
eq
2
end
it
'should return empty list when merge requests title or description does not contain the query'
do
results
=
described_class
.
new
(
limit_project_ids
,
'security'
)
expect
(
results
.
objects
(
'merge_requests'
)).
to
be_empty
expect
(
results
.
merge_requests_count
).
to
eq
0
end
it
'should list merge request when search by a valid iid'
do
results
=
described_class
.
new
(
limit_project_ids
,
'#2'
)
merge_requests
=
results
.
objects
(
'merge_requests'
)
expect
(
merge_requests
).
not_to
include
merge_request_1
expect
(
merge_requests
).
to
include
merge_request_2
expect
(
merge_requests
).
not_to
include
merge_request_3
expect
(
results
.
merge_requests_count
).
to
eq
1
end
it
'should return empty list when search by invalid iid'
do
results
=
described_class
.
new
(
limit_project_ids
,
'#222'
)
expect
(
results
.
objects
(
'merge_requests'
)).
to
be_empty
expect
(
results
.
merge_requests_count
).
to
eq
0
end
end
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