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
0
Merge Requests
0
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
Kazuhiko Shiozaki
gitlab-ce
Commits
f1126f49
Commit
f1126f49
authored
11 years ago
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move files search to gitlab_git
parent
9fdcdb77
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
39 deletions
+38
-39
app/contexts/search_context.rb
app/contexts/search_context.rb
+11
-7
app/controllers/search_controller.rb
app/controllers/search_controller.rb
+2
-1
app/models/project.rb
app/models/project.rb
+0
-12
app/views/layouts/_search.html.haml
app/views/layouts/_search.html.haml
+3
-10
app/views/search/_result.html.haml
app/views/search/_result.html.haml
+21
-9
app/views/search/show.html.haml
app/views/search/show.html.haml
+1
-0
No files found.
app/contexts/search_context.rb
View file @
f1126f49
...
...
@@ -12,12 +12,17 @@ class SearchContext
projects
=
Project
.
where
(
id:
project_ids
)
result
[
:projects
]
=
projects
.
search
(
query
).
limit
(
10
)
if
projects
.
length
==
1
result
[
:snippets
]
=
projects
.
first
.
files
(
query
,
params
[
:branch_ref
])
end
# Search inside singe project
result
[
:project
]
=
project
=
projects
.
first
if
projects
.
length
==
1
if
params
[
:search_code
].
present?
result
[
:blobs
]
=
project
.
repository
.
search_files
(
query
,
params
[
:repository_ref
])
unless
project
.
empty_repo?
else
result
[
:merge_requests
]
=
MergeRequest
.
where
(
project_id:
project_ids
).
search
(
query
).
limit
(
10
)
result
[
:issues
]
=
Issue
.
where
(
project_id:
project_ids
).
search
(
query
).
limit
(
10
)
result
[
:wiki_pages
]
=
[]
end
result
end
...
...
@@ -27,8 +32,7 @@ class SearchContext
merge_requests:
[],
issues:
[],
wiki_pages:
[],
snippet
s:
[]
blob
s:
[]
}
end
end
This diff is collapsed.
Click to expand it.
app/controllers/search_controller.rb
View file @
f1126f49
...
...
@@ -15,9 +15,10 @@ class SearchController < ApplicationController
result
=
SearchContext
.
new
(
project_ids
,
params
).
execute
@projects
=
result
[
:projects
]
@project
=
result
[
:project
]
@merge_requests
=
result
[
:merge_requests
]
@issues
=
result
[
:issues
]
@wiki_pages
=
result
[
:wiki_pages
]
@
snippets
=
result
[
:snippet
s
]
@
blobs
=
result
[
:blob
s
]
end
end
This diff is collapsed.
Click to expand it.
app/models/project.rb
View file @
f1126f49
...
...
@@ -410,16 +410,4 @@ class Project < ActiveRecord::Base
def
forked?
!
(
forked_project_link
.
nil?
||
forked_project_link
.
forked_from_project
.
nil?
)
end
def
files
(
query
,
treeish
)
snippets
=
[]
tree
=
treeish
.
present?
?
treeish
:
default_branch
if
repository
&&
!
tree
.
nil?
greps
=
repository
.
repo
.
grep
(
query
,
3
,
tree
)
greps
.
each
do
|
g
|
snippets
<<
Gitlab
::
BlobSnippet
.
new
(
self
,
tree
,
g
.
content
,
g
.
startline
,
g
.
filename
)
end
end
snippets
end
end
This diff is collapsed.
Click to expand it.
app/views/layouts/_search.html.haml
View file @
f1126f49
...
...
@@ -3,13 +3,6 @@
=
text_field_tag
"search"
,
nil
,
placeholder:
"Search"
,
class:
"search-input"
=
hidden_field_tag
:group_id
,
@group
.
try
(
:id
)
=
hidden_field_tag
:project_id
,
@project
.
try
(
:id
)
-
if
@ref
-
@branch_ref
=
@ref
-
else
-
@branch_ref
=
@project
.
try
(
:default_branch
)
-
if
@branch_ref
.
blank?
-
@branch_ref
=
'master'
=
hidden_field_tag
:branch_ref
,
@branch_ref
-
if
ENV
[
'RAILS_ENV'
]
==
'test'
=
submit_tag
'Go'
=
hidden_field_tag
:repository_ref
,
@ref
=
submit_tag
'Go'
if
ENV
[
'RAILS_ENV'
]
==
'test'
.search-autocomplete-json.hide
{
:'data-autocomplete-opts'
=>
search_autocomplete_source
}
This diff is collapsed.
Click to expand it.
app/views/search/_result.html.haml
View file @
f1126f49
%fieldset
%legend
Search results
%span
.cgray
(
#{
@projects
.
count
+
@merge_requests
.
count
+
@issues
.
count
+
@wiki_pages
.
count
}
)
%span
.cgray
(
#{
@projects
.
count
+
@merge_requests
.
count
+
@issues
.
count
+
@wiki_pages
.
count
+
@blobs
.
count
}
)
-
if
@project
%ul
.nav.nav-pills
%li
{
class:
(
"active"
if
params
[
:search_code
].
present?
)}
=
link_to
search_path
(
params
.
merge
(
search_code:
true
))
do
Repository Code
%li
{
class:
(
"active"
if
params
[
:search_code
].
blank?
)}
=
link_to
search_path
(
params
.
merge
(
search_code:
nil
))
do
Everything else
.search_results
%ul
.
well
-list
%ul
.
bordered
-list
-
@projects
.
each
do
|
project
|
%li
project:
...
...
@@ -32,16 +43,17 @@
%strong
.term
=
truncate
wiki_page
.
title
,
length:
50
%span
.light
(
#{
wiki_page
.
project
.
name_with_namespace
}
)
-
@
snippets
.
each
do
|
snippet
|
-
@
blobs
.
each
do
|
file
|
%li
code:
=
link_to
project_blob_path
(
snippet
.
project
,
tree_join
(
snippet
.
tree
,
snippet
.
filename
),
:anchor
=>
"L"
+
snippet
.
startline
.
to_s
)
do
%strong
.term
=
snippet
.
filename
.file_holder
.file_content.code
.file_title
=
link_to
project_blob_path
(
@project
,
tree_join
(
file
.
ref
,
file
.
filename
),
:anchor
=>
"L"
+
file
.
startline
.
to_s
)
do
%i
.icon-file
%strong
=
file
.
filename
.file_content.code.term
%div
{
class:
user_color_scheme_class
}
=
raw
snippet
.
colorize
(
formatter: :gitlab
,
options:
{
first_line_number:
snippet
.
startline
}
)
=
raw
file
.
colorize
(
formatter: :gitlab
,
options:
{
first_line_number:
file
.
startline
}
)
:javascript
$
(
function
()
{
...
...
This diff is collapsed.
Click to expand it.
app/views/search/show.html.haml
View file @
f1126f49
...
...
@@ -4,6 +4,7 @@
%span
Looking for
.input
=
search_field_tag
:search
,
params
[
:search
],
placeholder:
"issue 143"
,
class:
"input-xxlarge search-text-input"
,
id:
"dashboard_search"
=
hidden_field_tag
:search_code
,
params
[
:search_code
]
=
submit_tag
'Search'
,
class:
"btn btn-primary wide"
.clearfix
.row
...
...
This diff is collapsed.
Click to expand it.
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