diff --git a/project/build.scala b/project/build.scala index 8450203..774c0dd 100644 --- a/project/build.scala +++ b/project/build.scala @@ -33,8 +33,6 @@ "org.apache.commons" % "commons-compress" % "1.5", "com.typesafe.slick" %% "slick" % "1.0.1", "com.h2database" % "h2" % "1.3.171", - "com.google.guava" % "guava" % "14.0.1", - "com.google.code.findbugs" % "jsr305" % "2.0.1", "ch.qos.logback" % "logback-classic" % "1.0.6" % "runtime", "org.eclipse.jetty" % "jetty-webapp" % "8.1.8.v20121106" % "container", "org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;provided;test" artifacts (Artifact("javax.servlet", "jar", "jar")) diff --git a/src/main/scala/app/IndexController.scala b/src/main/scala/app/IndexController.scala index e2c0642..b865c36 100644 --- a/src/main/scala/app/IndexController.scala +++ b/src/main/scala/app/IndexController.scala @@ -8,16 +8,14 @@ import org.eclipse.jgit.revwalk.RevWalk import scala.collection.mutable.ListBuffer import org.eclipse.jgit.lib.FileMode -import com.google.common.cache.{CacheLoader, CacheBuilder} -import java.util.concurrent.TimeUnit import model.Issue class IndexController extends IndexControllerBase - with RepositoryService with AccountService with SystemSettingsService with ActivityService + with RepositoryService with AccountService with SystemSettingsService with ActivityService with IssuesService with ReferrerAuthenticator trait IndexControllerBase extends ControllerBase { self: RepositoryService - with SystemSettingsService with ActivityService + with SystemSettingsService with ActivityService with IssuesService with ReferrerAuthenticator => val searchForm = mapping( @@ -54,7 +52,7 @@ } - val SearchResult(files, issues) = cache.get(repository.owner, repository.name, query) + val SearchResult(files, issues) = searchRepository(repository.owner, repository.name, query) target.toLowerCase match { case "issue" => @@ -83,6 +81,51 @@ } }) + case class SearchResult( + files: List[(String, String)], + issues: List[(Issue, Int, String)] + ) + + def searchRepository(owner: String, repository: String, query: String): SearchResult = { + val issues = if(query.isEmpty) Nil else searchIssuesByKeyword(owner, repository, query) + val files = if(query.isEmpty) Nil else searchRepositoryFiles(owner, repository, query) + SearchResult(files, issues) + } + + 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 objectId = git.getRepository.resolve("HEAD") + val revCommit = revWalk.parseCommit(objectId) + val treeWalk = new TreeWalk(git.getRepository) + treeWalk.setRecursive(true) + treeWalk.addTree(revCommit.getTree) + + val keywords = StringUtil.splitWords(query.toLowerCase) + val list = new ListBuffer[(String, String)] + + while (treeWalk.next()) { + if(treeWalk.getFileMode(0) != FileMode.TREE){ + JGitUtil.getContent(git, treeWalk.getObjectId(0), false).foreach { bytes => + if(FileUtil.isText(bytes)){ + val text = new String(bytes, "UTF-8") + val lowerText = text.toLowerCase + val indices = keywords.map(lowerText.indexOf _) + if(!indices.exists(_ < 0)){ + list.append((treeWalk.getPathString, text)) + } + } + } + } + } + treeWalk.release + revWalk.release + + list.toList + } + } + + private def getHighlightText(content: String, query: String): (String, Int) = { val keywords = StringUtil.splitWords(query.toLowerCase) val lowerText = content.toLowerCase @@ -116,58 +159,6 @@ highlightLineNumber: Int) object RepositorySearch extends IssuesService { - val CodeLimit = 10 val IssueLimit = 10 - - case class SearchResult( - files: List[(String, String)], - issues: List[(Issue, Int, String)] - ) - - val cache = CacheBuilder.newBuilder() - .maximumSize(100) - .expireAfterWrite(10, TimeUnit.MINUTES) - .build( - new CacheLoader[(String, String, String), SearchResult]() { - override def load(key: (String, String, String)) = { - val (owner, repository, query) = key - val issues = if(query.isEmpty) Nil else searchIssuesByKeyword(owner, repository, query) - val files = if(query.isEmpty) Nil else searchRepositoryFiles(owner, repository, query) - SearchResult(files, issues) - } - }) - - 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 objectId = git.getRepository.resolve("HEAD") - val revCommit = revWalk.parseCommit(objectId) - val treeWalk = new TreeWalk(git.getRepository) - treeWalk.setRecursive(true) - treeWalk.addTree(revCommit.getTree) - - val keywords = StringUtil.splitWords(query.toLowerCase) - val list = new ListBuffer[(String, String)] - - while (treeWalk.next()) { - if(treeWalk.getFileMode(0) != FileMode.TREE){ - JGitUtil.getContent(git, treeWalk.getObjectId(0), false).foreach { bytes => - if(FileUtil.isText(bytes)){ - val text = new String(bytes, "UTF-8") - val lowerText = text.toLowerCase - val indices = keywords.map(lowerText.indexOf _) - if(!indices.exists(_ < 0)){ - list.append((treeWalk.getPathString, text)) - } - } - } - } - } - treeWalk.release - revWalk.release - - list.toList - } - } } \ No newline at end of file