mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 05:55:51 +01:00
(refs #3)Add result count to the menu.
This commit is contained in:
@@ -43,11 +43,12 @@ trait IndexControllerBase extends ControllerBase { self: RepositoryService
|
|||||||
val query = params("q").trim
|
val query = params("q").trim
|
||||||
val target = params.getOrElse("type", "code")
|
val target = params.getOrElse("type", "code")
|
||||||
|
|
||||||
|
val issues = if(query.isEmpty) Nil else searchIssuesByKeyword(repository.owner, repository.name, query)
|
||||||
|
val files = if(query.isEmpty) Nil else searchRepositoryFiles(repository.owner, repository.name, query)
|
||||||
|
|
||||||
target.toLowerCase match {
|
target.toLowerCase match {
|
||||||
case "issue" => if(query.isEmpty){
|
case "issue" =>
|
||||||
search.html.issues(Nil, "", repository)
|
search.html.issues(issues.map { case (issue, commentCount, content) =>
|
||||||
} else {
|
|
||||||
search.html.issues(searchIssuesByKeyword(repository.owner, repository.name, query).map { case (issue, commentCount, content) =>
|
|
||||||
IssueSearchResult(
|
IssueSearchResult(
|
||||||
issue.issueId,
|
issue.issueId,
|
||||||
issue.title,
|
issue.title,
|
||||||
@@ -55,13 +56,21 @@ trait IndexControllerBase extends ControllerBase { self: RepositoryService
|
|||||||
issue.registeredDate,
|
issue.registeredDate,
|
||||||
commentCount,
|
commentCount,
|
||||||
getHighlightText(content, query)._1)
|
getHighlightText(content, query)._1)
|
||||||
}, query, repository)
|
}, files.size, query, repository)
|
||||||
}
|
case _ =>
|
||||||
case _ => if(query.isEmpty){
|
|
||||||
// TODO move to JGitUtil?
|
|
||||||
search.html.code(Nil, "", repository)
|
|
||||||
} else {
|
|
||||||
JGitUtil.withGit(getRepositoryDir(repository.owner, repository.name)){ git =>
|
JGitUtil.withGit(getRepositoryDir(repository.owner, repository.name)){ git =>
|
||||||
|
val commits = JGitUtil.getLatestCommitFromPaths(git, files.toList.map(_._1), "HEAD")
|
||||||
|
|
||||||
|
search.html.code(files.toList.map { case (path, text) =>
|
||||||
|
val (highlightText, lineNumber) = getHighlightText(text, query)
|
||||||
|
FileSearchResult(path, commits(path).getCommitterIdent.getWhen, highlightText, lineNumber)
|
||||||
|
}, issues.size, query, repository)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
private def searchRepositoryFiles(owner: String, repository: String, query: String): List[(String, String)] = {
|
||||||
|
JGitUtil.withGit(getRepositoryDir(owner, repository)){ git =>
|
||||||
val revWalk = new RevWalk(git.getRepository)
|
val revWalk = new RevWalk(git.getRepository)
|
||||||
val objectId = git.getRepository.resolve("HEAD")
|
val objectId = git.getRepository.resolve("HEAD")
|
||||||
val revCommit = revWalk.parseCommit(objectId)
|
val revCommit = revWalk.parseCommit(objectId)
|
||||||
@@ -70,7 +79,8 @@ trait IndexControllerBase extends ControllerBase { self: RepositoryService
|
|||||||
treeWalk.addTree(revCommit.getTree)
|
treeWalk.addTree(revCommit.getTree)
|
||||||
|
|
||||||
val keywords = StringUtil.splitWords(query.toLowerCase)
|
val keywords = StringUtil.splitWords(query.toLowerCase)
|
||||||
val list = new ListBuffer[(String, (String, Int))]
|
val list = new ListBuffer[(String, String)]
|
||||||
|
|
||||||
while (treeWalk.next()) {
|
while (treeWalk.next()) {
|
||||||
if(treeWalk.getFileMode(0) != FileMode.TREE){
|
if(treeWalk.getFileMode(0) != FileMode.TREE){
|
||||||
JGitUtil.getContent(git, treeWalk.getObjectId(0), false).foreach { bytes =>
|
JGitUtil.getContent(git, treeWalk.getObjectId(0), false).foreach { bytes =>
|
||||||
@@ -79,7 +89,7 @@ trait IndexControllerBase extends ControllerBase { self: RepositoryService
|
|||||||
val lowerText = text.toLowerCase
|
val lowerText = text.toLowerCase
|
||||||
val indices = keywords.map(lowerText.indexOf _)
|
val indices = keywords.map(lowerText.indexOf _)
|
||||||
if(!indices.exists(_ < 0)){
|
if(!indices.exists(_ < 0)){
|
||||||
list.append((treeWalk.getPathString, getHighlightText(text, query)))
|
list.append((treeWalk.getPathString, text))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,15 +98,9 @@ trait IndexControllerBase extends ControllerBase { self: RepositoryService
|
|||||||
treeWalk.release
|
treeWalk.release
|
||||||
revWalk.release
|
revWalk.release
|
||||||
|
|
||||||
val commits = JGitUtil.getLatestCommitFromPaths(git, list.toList.map(_._1), "HEAD")
|
list.toList
|
||||||
|
|
||||||
search.html.code(list.toList.map { case (path, highlightText) =>
|
|
||||||
FileSearchResult(path, commits(path).getCommitterIdent.getWhen, highlightText._1, highlightText._2)
|
|
||||||
}, query, repository)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
private def getHighlightText(content: String, query: String): (String, Int) = {
|
private def getHighlightText(content: String, query: String): (String, Int) = {
|
||||||
val keywords = StringUtil.splitWords(query.toLowerCase)
|
val keywords = StringUtil.splitWords(query.toLowerCase)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
@(files: List[app.FileSearchResult], query: String, repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context)
|
@(files: List[app.FileSearchResult], issueCount: Int, query: String, repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context)
|
||||||
@import context._
|
@import context._
|
||||||
@import view.helpers._
|
@import view.helpers._
|
||||||
@html.main("Search Results", Some(repository)){
|
@html.main("Search Results", Some(repository)){
|
||||||
@menu("code", query, repository){
|
@menu("code", files.size, issueCount, query, repository){
|
||||||
@if(files.isEmpty){
|
@if(files.isEmpty){
|
||||||
<h4>We couldn't find any code matching '@query'</h4>
|
<h4>We couldn't find any code matching '@query'</h4>
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
@(issues: List[app.IssueSearchResult], query: String, repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context)
|
@(issues: List[app.IssueSearchResult], fileCount: Int, query: String, repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context)
|
||||||
@import context._
|
@import context._
|
||||||
@import view.helpers._
|
@import view.helpers._
|
||||||
@html.main("Search Results", Some(repository)){
|
@html.main("Search Results", Some(repository)){
|
||||||
@menu("issue", query, repository){
|
@menu("issue", fileCount, issues.size, query, repository){
|
||||||
@if(issues.isEmpty){
|
@if(issues.isEmpty){
|
||||||
<h4>We couldn't find any code matching '@query'</h4>
|
<h4>We couldn't find any code matching '@query'</h4>
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
@(active: String, query: String, repository: service.RepositoryService.RepositoryInfo)(body: Html)(implicit context: app.Context)
|
@(active: String, fileCount: Int, issueCount: Int, query: String,
|
||||||
|
repository: service.RepositoryService.RepositoryInfo)(body: Html)(implicit context: app.Context)
|
||||||
@import context._
|
@import context._
|
||||||
@import view.helpers._
|
@import view.helpers._
|
||||||
@html.header("", repository)
|
@html.header("", repository)
|
||||||
@@ -7,10 +8,16 @@
|
|||||||
<div class="box">
|
<div class="box">
|
||||||
<ul class="nav nav-tabs nav-stacked side-menu">
|
<ul class="nav nav-tabs nav-stacked side-menu">
|
||||||
<li@if(active=="code"){ class="active"}>
|
<li@if(active=="code"){ class="active"}>
|
||||||
<a href="@url(repository)/search?q=@urlEncode(query)&type=code">Code</a>
|
<a href="@url(repository)/search?q=@urlEncode(query)&type=code">
|
||||||
|
<span class="badge pull-right">@fileCount</span>
|
||||||
|
Code
|
||||||
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li@if(active=="issue"){ class="active"}>
|
<li@if(active=="issue"){ class="active"}>
|
||||||
<a href="@url(repository)/search?q=@urlEncode(query)&type=issue">Issue</a>
|
<a href="@url(repository)/search?q=@urlEncode(query)&type=issue">
|
||||||
|
<span class="badge pull-right">@issueCount</span>
|
||||||
|
Issue
|
||||||
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user