]> source.dussan.org Git - gitblit.git/commitdiff
More Lucene progress
authorJames Moger <james.moger@gitblit.com>
Sat, 10 Mar 2012 01:45:52 +0000 (20:45 -0500)
committerJames Moger <james.moger@gitblit.com>
Sat, 10 Mar 2012 01:45:52 +0000 (20:45 -0500)
15 files changed:
src/com/gitblit/GitBlit.java
src/com/gitblit/LuceneExecutor.java
src/com/gitblit/models/SearchResult.java
src/com/gitblit/utils/LuceneUtils.java
src/com/gitblit/wicket/GitBlitWebApp.java
src/com/gitblit/wicket/GitBlitWebApp.properties
src/com/gitblit/wicket/pages/LucenePage.html
src/com/gitblit/wicket/pages/LucenePage.java
src/com/gitblit/wicket/pages/RepositoryPage.java
src/com/gitblit/wicket/panels/ActivityPanel.java
src/com/gitblit/wicket/panels/BranchesPanel.java
src/com/gitblit/wicket/panels/HistoryPanel.java
src/com/gitblit/wicket/panels/LogPanel.java
tests/com/gitblit/tests/IssuesTest.java
tests/com/gitblit/tests/LuceneUtilsTest.java

index f6691dc6d60a0ed8f5c5cd2013402b5eabd016b2..e224025622a37b0d49635d211825f0865a75a028 100644 (file)
@@ -184,6 +184,7 @@ public class GitBlit implements ServletContextListener {
                }\r
                return self().timezone;\r
        }\r
+       \r
 \r
        /**\r
         * Returns the boolean value for the specified key. If the key does not\r
index b4e5134aa1dd1d5db0ea47a398da2a430db10c52..4f06b4ec13a3bd26ec1ac4780eaf6fe6e576dfa6 100644 (file)
@@ -105,26 +105,26 @@ public class LuceneExecutor implements Runnable {
                Set<String> processed = new HashSet<String>();\r
                if (!queue.isEmpty()) {\r
                        // update the repository Lucene index\r
-                       String repositoryName = null;\r
-                       while ((repositoryName = queue.poll()) != null) {\r
-                               if (processed.contains(repositoryName)) {\r
+                       String name = null;\r
+                       while ((name = queue.poll()) != null) {\r
+                               if (processed.contains(name)) {\r
                                        // skipping multi-queued repository\r
                                        continue;\r
                                }\r
                                try {\r
-                                       Repository repository = GitBlit.self().getRepository(repositoryName);\r
+                                       Repository repository = GitBlit.self().getRepository(name);\r
                                        if (repository == null) {\r
                                                logger.warn(MessageFormat.format(\r
                                                                "Lucene executor could not find repository {0}. Skipping.",\r
-                                                               repositoryName));\r
+                                                               name));\r
                                                continue;\r
                                        }\r
-                                       index(repositoryName, repository);\r
+                                       index(name, repository);\r
                                        repository.close();\r
-                                       processed.add(repositoryName);\r
+                                       processed.add(name);\r
                                } catch (Throwable e) {\r
                                        logger.error(MessageFormat.format("Failed to update {0} Lucene index",\r
-                                                       repositoryName), e);\r
+                                                       name), e);\r
                                }\r
                        }\r
                }\r
@@ -134,51 +134,53 @@ public class LuceneExecutor implements Runnable {
         * Synchronously indexes a repository. This may build a complete index of a\r
         * repository or it may update an existing index.\r
         * \r
-        * @param repositoryName\r
+        * @param name\r
         *            the name of the repository\r
         * @param repository\r
         *            the repository object\r
         */\r
-       public void index(String repositoryName, Repository repository) {\r
+       public void index(String name, Repository repository) {\r
                try {\r
                        if (JGitUtils.hasCommits(repository)) {\r
                                if (LuceneUtils.shouldReindex(repository)) {\r
                                        // (re)build the entire index\r
                                        long start = System.currentTimeMillis();\r
-                                       IndexResult result = LuceneUtils.reindex(repository);\r
-                                       long duration = System.currentTimeMillis() - start;\r
+                                       String msg = "Building {0} Lucene index...";\r
+                                       logger.info(MessageFormat.format(msg, name));\r
+                                       IndexResult result = LuceneUtils.reindex(name, repository, true);\r
+                                       float duration = (System.currentTimeMillis() - start)/1000f;\r
                                        if (result.success) {\r
                                                if (result.commitCount > 0) {\r
-                                                       String msg = "Built {0} Lucene index from {1} commits in {2} msecs";\r
-                                                       logger.info(MessageFormat.format(msg, repositoryName,\r
-                                                                       result.commitCount, duration));\r
+                                                       msg = "Built {0} Lucene index from {1} commits and {2} files across {3} branches in {4} secs";\r
+                                                       logger.info(MessageFormat.format(msg, name,\r
+                                                                       result.commitCount, result.blobCount, result.branchCount, duration));\r
                                                }\r
                                        } else {\r
-                                               String msg = "Could not build {0} Lucene index!";\r
-                                               logger.error(MessageFormat.format(msg, repositoryName));\r
+                                               msg = "Could not build {0} Lucene index!";\r
+                                               logger.error(MessageFormat.format(msg, name));\r
                                        }\r
                                } else {\r
                                        // update the index with latest commits\r
                                        long start = System.currentTimeMillis();\r
-                                       IndexResult result = LuceneUtils.updateIndex(repository);\r
-                                       long duration = System.currentTimeMillis() - start;\r
+                                       IndexResult result = LuceneUtils.updateIndex(name, repository);\r
+                                       float duration = (System.currentTimeMillis() - start)/1000f;\r
                                        if (result.success) {\r
                                                if (result.commitCount > 0) {\r
-                                                       String msg = "Updated {0} Lucene index with {1} commits in {2} msecs";\r
-                                                       logger.info(MessageFormat.format(msg, repositoryName,\r
-                                                                       result.commitCount, duration));\r
+                                                       String msg = "Updated {0} Lucene index with {1} commits and {2} files across {3} branches in {4} secs";\r
+                                                       logger.info(MessageFormat.format(msg, name,\r
+                                                                       result.commitCount, result.blobCount, result.branchCount, duration));\r
                                                }\r
                                        } else {\r
                                                String msg = "Could not update {0} Lucene index!";\r
-                                               logger.error(MessageFormat.format(msg, repositoryName));\r
+                                               logger.error(MessageFormat.format(msg, name));\r
                                        }\r
                                }\r
                        } else {\r
                                logger.info(MessageFormat.format("Skipped Lucene index of empty repository {0}",\r
-                                               repositoryName));\r
+                                               name));\r
                        }\r
                } catch (Throwable t) {\r
-                       logger.error(MessageFormat.format("Lucene indexing failure for {0}", repositoryName), t);\r
+                       logger.error(MessageFormat.format("Lucene indexing failure for {0}", name), t);\r
                }\r
        }\r
 \r
index 2fa0db424454218fd244a22d5b943a7c2b51a4c5..ffe4d870e15b8f143e8c21be9d96702e61912826 100644 (file)
@@ -32,6 +32,8 @@ public class SearchResult implements Serializable {
 \r
        public String id;\r
 \r
+       public List<String> tags;\r
+       \r
        public List<String> labels;\r
 \r
        public ObjectType type;\r
index e824236264e261ed112c24047971abd517a7430c..fe36a838044f056e8e91974f2d886c5dfe96a726 100644 (file)
@@ -1,3 +1,18 @@
+/*\r
+ * Copyright 2012 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
 package com.gitblit.utils;\r
 \r
 import java.io.ByteArrayOutputStream;\r
@@ -50,9 +65,11 @@ import org.eclipse.jgit.revwalk.RevObject;
 import org.eclipse.jgit.revwalk.RevWalk;\r
 import org.eclipse.jgit.storage.file.FileBasedConfig;\r
 import org.eclipse.jgit.treewalk.TreeWalk;\r
+import org.eclipse.jgit.treewalk.filter.AndTreeFilter;\r
+import org.eclipse.jgit.treewalk.filter.PathFilterGroup;\r
+import org.eclipse.jgit.treewalk.filter.TreeFilter;\r
 import org.eclipse.jgit.util.FS;\r
 \r
-import com.gitblit.GitBlit;\r
 import com.gitblit.models.IssueModel;\r
 import com.gitblit.models.IssueModel.Attachment;\r
 import com.gitblit.models.PathModel.PathChangeModel;\r
@@ -96,6 +113,7 @@ public class LuceneUtils {
        private static final String FIELD_AUTHOR = "author";\r
        private static final String FIELD_COMMITTER = "committer";\r
        private static final String FIELD_DATE = "date";\r
+       private static final String FIELD_TAG = "tag";\r
        private static final String FIELD_LABEL = "label";\r
        private static final String FIELD_ATTACHMENT = "attachment";\r
 \r
@@ -109,27 +127,47 @@ public class LuceneUtils {
        private static final Map<File, IndexSearcher> SEARCHERS = new ConcurrentHashMap<File, IndexSearcher>();\r
        private static final Map<File, IndexWriter> WRITERS = new ConcurrentHashMap<File, IndexWriter>();\r
 \r
+       private static final String LUCENE_DIR = "lucene";\r
        private static final String CONF_FILE = "lucene.conf";\r
        private static final String CONF_INDEX = "index";\r
        private static final String CONF_VERSION = "version";\r
        private static final String CONF_ALIAS = "aliases";\r
        private static final String CONF_BRANCH = "branches";\r
-\r
+       \r
        /**\r
-        * Returns the name of the repository.\r
+        * Returns the author for the commit, if this information is available.\r
         * \r
-        * @param repository\r
-        * @return the repository name\r
+        * @param commit\r
+        * @return an author or unknown\r
         */\r
-       private static String getName(Repository repository) {\r
-               String rootPath = GitBlit.getRepositoriesFolder().getAbsolutePath();\r
-               if (repository.isBare()) {\r
-                       return StringUtils.getRelativePath(rootPath, repository.getDirectory()\r
-                                       .getAbsolutePath());\r
-               } else {\r
-                       return StringUtils.getRelativePath(rootPath, repository.getDirectory().getParentFile()\r
-                                       .getAbsolutePath());\r
+       private static String getAuthor(RevCommit commit) {\r
+               String name = "unknown";\r
+               try {\r
+                       name = commit.getAuthorIdent().getName();\r
+                       if (StringUtils.isEmpty(name)) {\r
+                               name = commit.getAuthorIdent().getEmailAddress();\r
+                       }\r
+               } catch (NullPointerException n) {                                              \r
                }\r
+               return name;\r
+       }\r
+       \r
+       /**\r
+        * Returns the committer for the commit, if this information is available.\r
+        * \r
+        * @param commit\r
+        * @return an committer or unknown\r
+        */\r
+       private static String getCommitter(RevCommit commit) {\r
+               String name = "unknown";\r
+               try {\r
+                       name = commit.getCommitterIdent().getName();\r
+                       if (StringUtils.isEmpty(name)) {\r
+                               name = commit.getCommitterIdent().getEmailAddress();\r
+                       }\r
+               } catch (NullPointerException n) {                                              \r
+               }\r
+               return name;\r
        }\r
 \r
        /**\r
@@ -182,7 +220,7 @@ public class LuceneUtils {
         */\r
        public static boolean deleteIndex(Repository repository) {\r
                try {\r
-                       File luceneIndex = new File(repository.getDirectory(), "lucene");\r
+                       File luceneIndex = new File(repository.getDirectory(), LUCENE_DIR);\r
                        if (luceneIndex.exists()) {\r
                                org.eclipse.jgit.util.FileUtils.delete(luceneIndex,\r
                                                org.eclipse.jgit.util.FileUtils.RECURSIVE);\r
@@ -201,16 +239,22 @@ public class LuceneUtils {
         * This completely indexes the repository and will destroy any existing\r
         * index.\r
         * \r
+        * @param repositoryName\r
         * @param repository\r
+        * @param fullIndex\r
+        *            If false blob metadata is set to the HEAD revision of each\r
+        *            branch.  If true, each the last commit of each blob is\r
+        *            determined to properly index the author, committer, and date.\r
+        *            Full indexing can be time-consuming.\r
         * @return IndexResult\r
         */\r
-       public static IndexResult reindex(Repository repository) {\r
+       public static IndexResult reindex(String repositoryName, Repository repository,\r
+                       boolean fullIndex) {\r
                IndexResult result = new IndexResult();\r
                if (!LuceneUtils.deleteIndex(repository)) {\r
                        return result;\r
                }\r
-               try {\r
-                       String repositoryName = getName(repository);\r
+               try {                   \r
                        FileBasedConfig config = getConfig(repository);\r
                        Set<String> indexedCommits = new TreeSet<String>();\r
                        IndexWriter writer = getIndexWriter(repository, true);\r
@@ -235,40 +279,64 @@ public class LuceneUtils {
                                }\r
                                String branchName = branch.getName();\r
                                RevWalk revWalk = new RevWalk(repository);\r
-                               RevCommit rev = revWalk.parseCommit(branch.getObjectId());\r
+                               RevCommit branchHead = revWalk.parseCommit(branch.getObjectId());\r
+                               String head = branchHead.getId().getName();\r
 \r
                                String keyName = getBranchKey(branchName);\r
                                config.setString(CONF_ALIAS, null, keyName, branchName);\r
-                               config.setString(CONF_BRANCH, null, keyName, rev.getName());\r
+                               config.setString(CONF_BRANCH, null, keyName, head);\r
 \r
                                // index the blob contents of the tree\r
                                ByteArrayOutputStream os = new ByteArrayOutputStream();\r
                                byte[] tmp = new byte[32767];\r
                                TreeWalk treeWalk = new TreeWalk(repository);\r
-                               treeWalk.addTree(rev.getTree());\r
+                               treeWalk.addTree(branchHead.getTree());\r
                                treeWalk.setRecursive(true);\r
-                               String revDate = DateTools.timeToString(rev.getCommitTime() * 1000L,\r
-                                               Resolution.MINUTE);\r
+                               \r
                                while (treeWalk.next()) {\r
+                                       result.blobCount++;\r
+                                       String blobPath = treeWalk.getPathString();\r
+                                       RevCommit blobRev = branchHead;\r
+                                       \r
+                                       RevWalk blobWalk = null;\r
+                                       if (fullIndex) {\r
+                                               // XXX this is _really_ slow, there must be a better way\r
+                                               // determine the most recent commit for this blob\r
+                                               blobWalk = new RevWalk(repository);\r
+                                               blobWalk.markStart(blobWalk.parseCommit(branch.getObjectId()));\r
+                                               TreeFilter filter = AndTreeFilter.create(\r
+                                                               PathFilterGroup.createFromStrings(Collections.singleton(blobPath)),\r
+                                                               TreeFilter.ANY_DIFF);\r
+                                               blobWalk.setTreeFilter(filter);\r
+\r
+                                               for (RevCommit commit : blobWalk) {\r
+                                                       blobRev = commit;\r
+                                                       break;\r
+                                               }\r
+                                       }\r
+                                       \r
+                                       String blobAuthor = getAuthor(blobRev);\r
+                                       String blobCommitter = getCommitter(blobRev);\r
+                                       String blobDate = DateTools.timeToString(blobRev.getCommitTime() * 1000L,\r
+                                                       Resolution.MINUTE);\r
+                                       \r
+                                       if (blobWalk != null) {\r
+                                               blobWalk.dispose();\r
+                                       }\r
+                                       \r
                                        Document doc = new Document();\r
-                                       doc.add(new Field(FIELD_OBJECT_TYPE, ObjectType.blob.name(), Store.YES,\r
-                                                       Index.NOT_ANALYZED_NO_NORMS));\r
-                                       doc.add(new Field(FIELD_REPOSITORY, repositoryName, Store.YES,\r
-                                                       Index.NOT_ANALYZED));\r
-                                       doc.add(new Field(FIELD_BRANCH, branchName, Store.YES, Index.NOT_ANALYZED));\r
-                                       doc.add(new Field(FIELD_OBJECT_ID, treeWalk.getPathString(), Store.YES,\r
-                                                       Index.NOT_ANALYZED));\r
-                                       doc.add(new Field(FIELD_DATE, revDate, Store.YES, Index.NO));\r
-                                       doc.add(new Field(FIELD_AUTHOR, rev.getAuthorIdent().getName(), Store.YES,\r
-                                                       Index.NOT_ANALYZED_NO_NORMS));\r
-                                       doc.add(new Field(FIELD_COMMITTER, rev.getCommitterIdent().getName(),\r
-                                                       Store.YES, Index.NOT_ANALYZED_NO_NORMS));\r
-                                       doc.add(new Field(FIELD_LABEL, branch.getName(), Store.YES, Index.ANALYZED));\r
+                                       doc.add(new Field(FIELD_OBJECT_TYPE, ObjectType.blob.name(), Store.YES, Index.NOT_ANALYZED_NO_NORMS));\r
+                                       doc.add(new Field(FIELD_REPOSITORY, repositoryName, Store.YES, Index.ANALYZED));\r
+                                       doc.add(new Field(FIELD_BRANCH, branchName, Store.YES, Index.ANALYZED));\r
+                                       doc.add(new Field(FIELD_OBJECT_ID, blobPath, Store.YES, Index.ANALYZED));\r
+                                       doc.add(new Field(FIELD_DATE, blobDate, Store.YES, Index.NO));\r
+                                       doc.add(new Field(FIELD_AUTHOR, blobAuthor, Store.YES, Index.ANALYZED));\r
+                                       doc.add(new Field(FIELD_COMMITTER, blobCommitter, Store.YES, Index.ANALYZED));                                  \r
 \r
                                        // determine extension to compare to the extension\r
                                        // blacklist\r
                                        String ext = null;\r
-                                       String name = treeWalk.getPathString().toLowerCase();\r
+                                       String name = blobPath.toLowerCase();\r
                                        if (name.indexOf('.') > -1) {\r
                                                ext = name.substring(name.lastIndexOf('.') + 1);\r
                                        }\r
@@ -298,25 +366,25 @@ public class LuceneUtils {
                                treeWalk.release();\r
 \r
                                // index the head commit object\r
-                               String head = rev.getId().getName();\r
                                if (indexedCommits.add(head)) {\r
-                                       Document doc = createDocument(rev, tags.get(head));\r
-                                       doc.add(new Field(FIELD_REPOSITORY, repositoryName, Store.YES,\r
-                                                       Index.NOT_ANALYZED));\r
-                                       doc.add(new Field(FIELD_BRANCH, branchName, Store.YES, Index.NOT_ANALYZED));\r
+                                       Document doc = createDocument(branchHead, tags.get(head));\r
+                                       doc.add(new Field(FIELD_REPOSITORY, repositoryName, Store.YES, Index.ANALYZED));\r
+                                       doc.add(new Field(FIELD_BRANCH, branchName, Store.YES, Index.ANALYZED));\r
                                        writer.addDocument(doc);\r
                                        result.commitCount += 1;\r
+                                       result.branchCount += 1;\r
                                }\r
 \r
                                // traverse the log and index the previous commit objects\r
-                               revWalk.markStart(rev);\r
+                               revWalk.reset();\r
+                               revWalk.markStart(branchHead);\r
+                               RevCommit rev;\r
                                while ((rev = revWalk.next()) != null) {\r
                                        String hash = rev.getId().getName();\r
                                        if (indexedCommits.add(hash)) {\r
                                                Document doc = createDocument(rev, tags.get(hash));\r
-                                               doc.add(new Field(FIELD_REPOSITORY, repositoryName, Store.YES,\r
-                                                               Index.NOT_ANALYZED));\r
-                                               doc.add(new Field(FIELD_BRANCH, branchName, Store.YES, Index.NOT_ANALYZED));\r
+                                               doc.add(new Field(FIELD_REPOSITORY, repositoryName, Store.YES, Index.ANALYZED));\r
+                                               doc.add(new Field(FIELD_BRANCH, branchName, Store.YES, Index.ANALYZED));\r
                                                writer.addDocument(doc);\r
                                                result.commitCount += 1;\r
                                        }\r
@@ -329,10 +397,13 @@ public class LuceneUtils {
                        // this repository has a gb-issues branch, index all issues\r
                        if (IssueUtils.getIssuesBranch(repository) != null) {\r
                                List<IssueModel> issues = IssueUtils.getIssues(repository, null);\r
+                               if (issues.size() > 0) {\r
+                                       result.branchCount += 1;\r
+                               }\r
                                for (IssueModel issue : issues) {\r
+                                       result.issueCount++;\r
                                        Document doc = createDocument(issue);\r
-                                       doc.add(new Field(FIELD_REPOSITORY, repositoryName, Store.YES,\r
-                                                       Index.NOT_ANALYZED));\r
+                                       doc.add(new Field(FIELD_REPOSITORY, repositoryName, Store.YES, Index.ANALYZED));\r
                                        writer.addDocument(doc);\r
                                }\r
                        }\r
@@ -353,13 +424,16 @@ public class LuceneUtils {
         * Incrementally update the index with the specified commit for the\r
         * repository.\r
         * \r
+        * @param repositoryName\r
         * @param repository\r
         * @param branch\r
         *            the fully qualified branch name (e.g. refs/heads/master)\r
         * @param commit\r
         * @return true, if successful\r
         */\r
-       public static boolean index(Repository repository, String branch, RevCommit commit) {\r
+       private static IndexResult index(String repositoryName, Repository repository, \r
+                       String branch, RevCommit commit) {\r
+               IndexResult result = new IndexResult();\r
                try {\r
                        if (excludedBranches.contains(branch)) {\r
                                if (IssueUtils.GB_ISSUES.equals(branch)) {\r
@@ -367,20 +441,23 @@ public class LuceneUtils {
                                        String issueId = commit.getShortMessage().substring(2).trim();\r
                                        IssueModel issue = IssueUtils.getIssue(repository, issueId);\r
                                        if (issue == null) {\r
-                                               // delete the old issue from the index, if exists\r
+                                               // issue was deleted, remove from index\r
                                                IndexWriter writer = getIndexWriter(repository, false);\r
                                                writer.deleteDocuments(\r
                                                                new Term(FIELD_OBJECT_TYPE, ObjectType.issue.name()), new Term(\r
                                                                                FIELD_OBJECT_ID, issueId));\r
                                                writer.commit();\r
-                                               return true;\r
+                                               result.success = true;\r
+                                               return result;\r
                                        }\r
-                                       return index(repository, issue);\r
+                                       result.success = index(repositoryName, repository, issue);\r
+                                       result.issueCount++;\r
+                                       return result;\r
+                                       \r
                                }\r
-                               return false;\r
+                               return result;\r
                        }\r
                        List<PathChangeModel> changedPaths = JGitUtils.getFilesInCommit(repository, commit);\r
-                       String repositoryName = getName(repository);\r
                        String revDate = DateTools.timeToString(commit.getCommitTime() * 1000L,\r
                                        Resolution.MINUTE);\r
                        IndexWriter writer = getIndexWriter(repository, false);\r
@@ -391,19 +468,16 @@ public class LuceneUtils {
 \r
                                // re-index the blob\r
                                if (!ChangeType.DELETE.equals(path.changeType)) {\r
+                                       result.blobCount++;\r
                                        Document doc = new Document();\r
                                        doc.add(new Field(FIELD_OBJECT_TYPE, ObjectType.blob.name(), Store.YES,\r
-                                                       Index.NOT_ANALYZED_NO_NORMS));\r
-                                       doc.add(new Field(FIELD_REPOSITORY, repositoryName, Store.YES,\r
                                                        Index.NOT_ANALYZED));\r
-                                       doc.add(new Field(FIELD_BRANCH, branch, Store.YES, Index.NOT_ANALYZED));\r
-                                       doc.add(new Field(FIELD_OBJECT_ID, path.path, Store.YES, Index.NOT_ANALYZED));\r
+                                       doc.add(new Field(FIELD_REPOSITORY, repositoryName, Store.YES, Index.ANALYZED));\r
+                                       doc.add(new Field(FIELD_BRANCH, branch, Store.YES, Index.ANALYZED));\r
+                                       doc.add(new Field(FIELD_OBJECT_ID, path.path, Store.YES, Index.ANALYZED));\r
                                        doc.add(new Field(FIELD_DATE, revDate, Store.YES, Index.NO));\r
-                                       doc.add(new Field(FIELD_AUTHOR, commit.getAuthorIdent().getName(), Store.YES,\r
-                                                       Index.NOT_ANALYZED_NO_NORMS));\r
-                                       doc.add(new Field(FIELD_COMMITTER, commit.getCommitterIdent().getName(),\r
-                                                       Store.YES, Index.NOT_ANALYZED_NO_NORMS));\r
-                                       doc.add(new Field(FIELD_LABEL, branch, Store.YES, Index.ANALYZED));\r
+                                       doc.add(new Field(FIELD_AUTHOR, getAuthor(commit), Store.YES, Index.ANALYZED));\r
+                                       doc.add(new Field(FIELD_COMMITTER, getCommitter(commit), Store.YES, Index.ANALYZED));\r
 \r
                                        // determine extension to compare to the extension\r
                                        // blacklist\r
@@ -425,11 +499,12 @@ public class LuceneUtils {
                        writer.commit();\r
 \r
                        Document doc = createDocument(commit, null);\r
-                       return index(repository, doc);\r
+                       result.commitCount++;\r
+                       result.success = index(repositoryName, repository, doc);\r
                } catch (Exception e) {\r
                        e.printStackTrace();\r
                }\r
-               return false;\r
+               return result;\r
        }\r
 \r
        /**\r
@@ -440,7 +515,7 @@ public class LuceneUtils {
         * @param issue\r
         * @return true, if successful\r
         */\r
-       public static boolean index(Repository repository, IssueModel issue) {\r
+       public static boolean index(String repositoryName, Repository repository, IssueModel issue) {\r
                try {\r
                        // delete the old issue from the index, if exists\r
                        IndexWriter writer = getIndexWriter(repository, false);\r
@@ -449,7 +524,7 @@ public class LuceneUtils {
                        writer.commit();\r
 \r
                        Document doc = createDocument(issue);\r
-                       return index(repository, doc);\r
+                       return index(repositoryName, repository, doc);\r
                } catch (Exception e) {\r
                        e.printStackTrace();\r
                }\r
@@ -459,10 +534,11 @@ public class LuceneUtils {
        /**\r
         * Updates a repository index incrementally from the last indexed commits.\r
         * \r
+        * @param repositoryName\r
         * @param repository\r
         * @return IndexResult\r
         */\r
-       public static IndexResult updateIndex(Repository repository) {\r
+       public static IndexResult updateIndex(String repositoryName, Repository repository) {\r
                IndexResult result = new IndexResult();\r
                try {\r
                        FileBasedConfig config = getConfig(repository);\r
@@ -511,11 +587,14 @@ public class LuceneUtils {
                                        revs = JGitUtils.getRevLog(repository, lastCommit, branchName);\r
                                }\r
 \r
-                               // reverse the list of commits so we start with the first commit\r
+                               if (revs.size() > 0) {\r
+                                       result.branchCount += 1;\r
+                               }\r
+                               \r
+                               // reverse the list of commits so we start with the first commit                                \r
                                Collections.reverse(revs);\r
                                for (RevCommit commit : revs) {\r
-                                       index(repository, branchName, commit);\r
-                                       result.commitCount += 1;\r
+                                       result.add(index(repositoryName, repository, branchName, commit));                                      \r
                                }\r
 \r
                                // update the config\r
@@ -550,12 +629,12 @@ public class LuceneUtils {
        private static Document createDocument(IssueModel issue) {\r
                Document doc = new Document();\r
                doc.add(new Field(FIELD_OBJECT_TYPE, ObjectType.issue.name(), Store.YES,\r
-                               Field.Index.NOT_ANALYZED_NO_NORMS));\r
-               doc.add(new Field(FIELD_OBJECT_ID, issue.id, Store.YES, Index.NOT_ANALYZED));\r
-               doc.add(new Field(FIELD_BRANCH, IssueUtils.GB_ISSUES, Store.YES, Index.NOT_ANALYZED));\r
+                               Field.Index.NOT_ANALYZED));\r
+               doc.add(new Field(FIELD_OBJECT_ID, issue.id, Store.YES, Index.ANALYZED));\r
+               doc.add(new Field(FIELD_BRANCH, IssueUtils.GB_ISSUES, Store.YES, Index.ANALYZED));\r
                doc.add(new Field(FIELD_DATE, DateTools.dateToString(issue.created, Resolution.MINUTE),\r
                                Store.YES, Field.Index.NO));\r
-               doc.add(new Field(FIELD_AUTHOR, issue.reporter, Store.YES, Index.NOT_ANALYZED_NO_NORMS));\r
+               doc.add(new Field(FIELD_AUTHOR, issue.reporter, Store.YES, Index.ANALYZED));\r
                List<String> attachments = new ArrayList<String>();\r
                for (Attachment attachment : issue.getAttachments()) {\r
                        attachments.add(attachment.name.toLowerCase());\r
@@ -579,19 +658,16 @@ public class LuceneUtils {
        private static Document createDocument(RevCommit commit, List<String> tags) {\r
                Document doc = new Document();\r
                doc.add(new Field(FIELD_OBJECT_TYPE, ObjectType.commit.name(), Store.YES,\r
-                               Index.NOT_ANALYZED_NO_NORMS));\r
-               doc.add(new Field(FIELD_OBJECT_ID, commit.getName(), Store.YES, Index.NOT_ANALYZED));\r
+                               Index.NOT_ANALYZED));\r
+               doc.add(new Field(FIELD_OBJECT_ID, commit.getName(), Store.YES, Index.ANALYZED));\r
                doc.add(new Field(FIELD_DATE, DateTools.timeToString(commit.getCommitTime() * 1000L,\r
                                Resolution.MINUTE), Store.YES, Index.NO));\r
-               doc.add(new Field(FIELD_AUTHOR, commit.getCommitterIdent().getName(), Store.YES,\r
-                               Index.NOT_ANALYZED_NO_NORMS));\r
+               doc.add(new Field(FIELD_AUTHOR, getAuthor(commit), Store.YES, Index.ANALYZED));\r
+               doc.add(new Field(FIELD_COMMITTER, getCommitter(commit), Store.YES, Index.ANALYZED));\r
                doc.add(new Field(FIELD_SUMMARY, commit.getShortMessage(), Store.YES, Index.ANALYZED));\r
                doc.add(new Field(FIELD_CONTENT, commit.getFullMessage(), Store.NO, Index.ANALYZED));\r
                if (!ArrayUtils.isEmpty(tags)) {\r
-                       if (!ArrayUtils.isEmpty(tags)) {\r
-                               doc.add(new Field(FIELD_LABEL, StringUtils.flattenStrings(tags), Store.YES,\r
-                                               Index.ANALYZED));\r
-                       }\r
+                       doc.add(new Field(FIELD_TAG, StringUtils.flattenStrings(tags), Store.YES, Index.ANALYZED));\r
                }\r
                return doc;\r
        }\r
@@ -599,13 +675,13 @@ public class LuceneUtils {
        /**\r
         * Incrementally index an object for the repository.\r
         * \r
+        * @param repositoryName\r
         * @param repository\r
         * @param doc\r
         * @return true, if successful\r
         */\r
-       private static boolean index(Repository repository, Document doc) {\r
-               try {\r
-                       String repositoryName = getName(repository);\r
+       private static boolean index(String repositoryName, Repository repository, Document doc) {\r
+               try {                   \r
                        doc.add(new Field(FIELD_REPOSITORY, repositoryName, Store.YES, Index.NOT_ANALYZED));\r
                        IndexWriter writer = getIndexWriter(repository, false);\r
                        writer.addDocument(doc);\r
@@ -629,6 +705,9 @@ public class LuceneUtils {
                result.repository = doc.get(FIELD_REPOSITORY);\r
                result.branch = doc.get(FIELD_BRANCH);\r
                result.id = doc.get(FIELD_OBJECT_ID);\r
+               if (doc.get(FIELD_TAG) != null) {\r
+                       result.tags = StringUtils.getStringsFromValue(doc.get(FIELD_TAG));\r
+               }\r
                if (doc.get(FIELD_LABEL) != null) {\r
                        result.labels = StringUtils.getStringsFromValue(doc.get(FIELD_LABEL));\r
                }\r
@@ -672,7 +751,7 @@ public class LuceneUtils {
        private static IndexWriter getIndexWriter(Repository repository, boolean forceCreate)\r
                        throws IOException {\r
                IndexWriter indexWriter = WRITERS.get(repository.getDirectory());\r
-               File indexFolder = new File(repository.getDirectory(), "lucene");\r
+               File indexFolder = new File(repository.getDirectory(), LUCENE_DIR);\r
                Directory directory = FSDirectory.open(indexFolder);\r
                if (forceCreate || !indexFolder.exists()) {\r
                        // if the writer is going to blow away the existing index and create\r
@@ -794,6 +873,16 @@ public class LuceneUtils {
 \r
        public static class IndexResult {\r
                public boolean success;\r
+               public int branchCount;\r
                public int commitCount;\r
+               public int blobCount;\r
+               public int issueCount;\r
+               \r
+               public void add(IndexResult result) {\r
+                       this.branchCount += result.branchCount;\r
+                       this.commitCount += result.commitCount;\r
+                       this.blobCount += result.blobCount;\r
+                       this.issueCount += result.issueCount;                   \r
+               }\r
        }\r
 }\r
index e2391d6db7f22997d0efc55d0e63f6038bba01b6..5054afa3b67358bd657b034dec4431f49ee597c0 100644 (file)
@@ -26,6 +26,7 @@ import org.apache.wicket.protocol.http.WebApplication;
 import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
 import com.gitblit.wicket.pages.ActivityPage;\r
+import com.gitblit.wicket.pages.BasePage;\r
 import com.gitblit.wicket.pages.BlamePage;\r
 import com.gitblit.wicket.pages.BlobDiffPage;\r
 import com.gitblit.wicket.pages.BlobPage;\r
@@ -90,7 +91,12 @@ public class GitBlitWebApp extends WebApplication {
                mount("/commitdiff", CommitDiffPage.class, "r", "h");\r
                mount("/patch", PatchPage.class, "r", "h", "f");\r
                mount("/history", HistoryPage.class, "r", "h", "f");\r
-               mount("/search", SearchPage.class);\r
+               if (GitBlit.getBoolean(Keys.lucene.enable, false)) {\r
+                       // TODO switch this to LucenePage when it is ready\r
+                       mount("/search", SearchPage.class);\r
+               } else {\r
+                       mount("/search", SearchPage.class);\r
+               }\r
                mount("/metrics", MetricsPage.class, "r");\r
                mount("/blame", BlamePage.class, "r", "h", "f");\r
 \r
@@ -124,6 +130,20 @@ public class GitBlitWebApp extends WebApplication {
        public Class<? extends Page> getHomePage() {\r
                return RepositoriesPage.class;\r
        }\r
+       \r
+       /**\r
+        * Returns the preferred search page class.\r
+        * \r
+        * @return a Wicket class representing a search page\r
+        */\r
+       public Class<? extends BasePage> getSearchPageClass() {\r
+               if (GitBlit.getBoolean(Keys.lucene.enable, false)) {\r
+                       // TODO switch this to LucenePage when it is ready\r
+                       return SearchPage.class;//LucenePage.class;\r
+               }\r
+               return SearchPage.class;\r
+       }\r
+\r
 \r
        @Override\r
        public final Session newSession(Request request, Response response) {\r
index b4501c33b8c3a3fa6d6f012ef7a1ed9b5c1b3567..9f4b3c628f2b5a0db4f1099d136ead5acc01e6e0 100644 (file)
@@ -212,4 +212,6 @@ gb.hookScriptsDescription = run Groovy scripts on pushes to this Gitblit server
 gb.reset = reset\r
 gb.pages = pages\r
 gb.workingCopy = working copy\r
-gb.workingCopyWarning = this repository has a working copy and can not receive pushes
\ No newline at end of file
+gb.workingCopyWarning = this repository has a working copy and can not receive pushes\r
+gb.query = query\r
+gb.queryHelp = write brief explanation of Lucene syntax here
\ No newline at end of file
index 867e607b028b7b546ac1b176e2d021fa6f41636a..ff9111685d7d1469018b9563f7fb87416d79bb51 100644 (file)
@@ -6,17 +6,46 @@
 <body onload="document.getElementById('fragment').focus();">\r
 <wicket:extend>\r
        <div class="pageTitle">\r
-               <h2><wicket:message key="gb.search"></wicket:message><small> lucene</small></h2>\r
+               <h2><wicket:message key="gb.search"></wicket:message></h2>\r
        </div>\r
-       <form class="form-inline" wicket:id="searchForm">\r
-               <input class="span6" wicket:id="fragment" placeholder="enter search text"></input>\r
-               <button class="btn btn-primary" type="submit" value="Search"><wicket:message key="gb.search"></wicket:message></button>\r
+       <form class="form-inline" style="margin:0px;" wicket:id="searchForm">\r
+               <div class="row-fluid">\r
+                       <div class="span3">\r
+                               <h3><wicket:message key="gb.repositories"></wicket:message></h3>\r
+                               <select wicket:id="repositories" ></select>\r
+                       </div>\r
+                       <div class="span9">\r
+                               <div>\r
+                                       <h3><wicket:message key="gb.query"></wicket:message></h3>\r
+                                       <input class="span8" wicket:id="fragment" placeholder="enter search text"></input>\r
+                                       <button class="btn btn-primary" type="submit" value="Search"><wicket:message key="gb.search"></wicket:message></button>\r
+                               </div>\r
+                               <div style="margin-top:10px;">\r
+                                       <div style="margin-left:0px;" class="span4">\r
+                                               <div class="alert alert">\r
+                                                       <b>type:</b> commit or blob<br/>\r
+                                                       <b>id:</b> commit id or file path<br/>\r
+                                                       <b>branch:</b><br/>\r
+                                                       <b>author:</b><br/>\r
+                                                       <b>committer:</b><br/>\r
+                                                       <b>tag:</b> tag<br/>\r
+                                               </div>\r
+                                       </div>\r
+                                       <div class="span5">\r
+                                               <wicket:message key="gb.queryHelp"></wicket:message>\r
+                                       </div>\r
+                               </div>\r
+                       </div>\r
+               </div>\r
        </form>\r
+       <hr/>\r
+       <div class="row-fluid">\r
        <div class="searchResult" wicket:id="searchResults">\r
                <div><i wicket:id="type"></i><span class="summary" wicket:id="summary"></span></div>\r
                <span class="author" wicket:id="author"></span> committed to <span class="repository" wicket:id="repository"></span>:<span class="branch" wicket:id="branch"></span><br/>\r
                <span class="date" wicket:id="date"></span>\r
        </div>\r
+       </div>\r
 </wicket:extend>\r
 </body>\r
 </html>
\ No newline at end of file
index 47f731c21f9026b50248f3ed64880ae28da8c31e..c269c8e665351cc4c84d0e16aa1092c0a2ce8e16 100644 (file)
@@ -20,7 +20,8 @@ import java.util.List;
 \r
 import org.apache.wicket.PageParameters;\r
 import org.apache.wicket.markup.html.basic.Label;\r
-import org.apache.wicket.markup.html.form.Form;\r
+import org.apache.wicket.markup.html.form.ListMultipleChoice;\r
+import org.apache.wicket.markup.html.form.StatelessForm;\r
 import org.apache.wicket.markup.html.form.TextField;\r
 import org.apache.wicket.markup.repeater.Item;\r
 import org.apache.wicket.markup.repeater.data.DataView;\r
@@ -29,6 +30,7 @@ import org.apache.wicket.model.Model;
 import org.eclipse.jgit.lib.Constants;\r
 import org.eclipse.jgit.lib.Repository;\r
 \r
+import com.gitblit.Constants.SearchType;\r
 import com.gitblit.GitBlit;\r
 import com.gitblit.models.SearchResult;\r
 import com.gitblit.utils.LuceneUtils;\r
@@ -50,6 +52,18 @@ public class LucenePage extends RootPage {
 \r
        private void setup(PageParameters params) {\r
                setupPage("", "");\r
+               \r
+               String repository = null;               \r
+               String value = null;\r
+               com.gitblit.Constants.SearchType searchType = null;\r
+\r
+               if (params != null) {\r
+                       repository = WicketUtils.getRepositoryName(params);\r
+                       value = WicketUtils.getSearchString(params);\r
+                       String type = WicketUtils.getSearchType(params);\r
+                       searchType = com.gitblit.Constants.SearchType.forName(type);\r
+               }\r
+               \r
                final List<SearchResult> results = new ArrayList<SearchResult>();\r
                ListDataProvider<SearchResult> resultsDp = new ListDataProvider<SearchResult>(results);\r
                final DataView<SearchResult> resultsView = new DataView<SearchResult>("searchResults", resultsDp) {\r
@@ -86,26 +100,70 @@ public class LucenePage extends RootPage {
                        }\r
                };              \r
                \r
+               // initial query\r
                final Model<String> fragment = new Model<String>();\r
-               Form<Void> form = new Form<Void>("searchForm") {\r
+               if (!StringUtils.isEmpty(value)) {\r
+                       if (searchType == SearchType.COMMIT) {\r
+                               fragment.setObject("type:" + searchType.name().toLowerCase() + " AND \"" + value + "\"");       \r
+                       } else {\r
+                               fragment.setObject(searchType.name().toLowerCase() + ":\"" + value + "\"");\r
+                       }\r
+               }\r
+               \r
+               // selected repositories\r
+               final Model<ArrayList<String>> repositories = new Model<ArrayList<String>>();\r
+               if (!StringUtils.isEmpty(repository)) {                 \r
+                       ArrayList<String> list = new ArrayList<String>();\r
+                       list.add(repository);\r
+                       repositories.setObject(list);\r
+               }\r
+               \r
+               // search form\r
+               StatelessForm<Void> form = new StatelessForm<Void>("searchForm") {\r
+                       \r
+                       private static final long serialVersionUID = 1L;\r
+\r
                        @Override\r
                        public void onSubmit() {\r
                                String f = fragment.getObject();\r
-                               List<Repository> repositories = new ArrayList<Repository>();\r
-                               for (String r : GitBlit.self().getRepositoryList()) {\r
-                                       repositories.add(GitBlit.self().getRepository(r));\r
+                               if (StringUtils.isEmpty(f)) {\r
+                                       error("Query is empty!");\r
+                                       return;\r
+                               }                               \r
+                               if (repositories.getObject().size() == 0) {\r
+                                       error("Please select one or more repositories!");\r
+                                       return;\r
                                }\r
-                               List<SearchResult> srs = LuceneUtils.search(f, 100, repositories.toArray(new Repository[repositories.size()]));\r
                                results.clear();\r
-                               results.addAll(srs);\r
-                               for (Repository r : repositories) {\r
-                                       r.close();\r
-                               }\r
+                               results.addAll(search(repositories, fragment));\r
                                resultsView.setVisible(true);\r
                        }\r
                };\r
+               ListMultipleChoice<String> selections = new ListMultipleChoice<String>("repositories", repositories, GitBlit.self().getRepositoryList());\r
+               selections.setMaxRows(11);\r
+               form.add(selections);\r
                form.add(new TextField<String>("fragment", fragment));\r
                add(form);\r
-               add(resultsView.setVisible(false));\r
+               if (!StringUtils.isEmpty(repository) && !StringUtils.isEmpty(fragment.getObject())) {\r
+                       // search is defined by url parameters\r
+                       results.clear();\r
+                       results.addAll(search(repositories, fragment));\r
+                       add(resultsView.setVisible(true));\r
+               } else {\r
+                       // no pre-defined search\r
+                       add(resultsView.setVisible(false));\r
+               }\r
+       }\r
+       \r
+       private List<SearchResult> search(Model<ArrayList<String>> repositories, Model<String> fragment) {\r
+               List<Repository> repos = new ArrayList<Repository>();\r
+               for (String r : repositories.getObject()) {\r
+                       repos.add(GitBlit.self().getRepository(r));\r
+               }\r
+               List<SearchResult> srs = LuceneUtils.search(fragment.getObject(), 100, repos.toArray(new Repository[repos.size()]));\r
+               for (Repository r : repos) {\r
+                       r.close();\r
+               }\r
+               return srs;\r
        }\r
 }\r
index 080a77231f329e729e3d218682b62020d6576391..4a83b876054e0be4e53884a322df0af3a90c8d35 100644 (file)
@@ -47,6 +47,7 @@ import com.gitblit.models.RepositoryModel;
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.utils.StringUtils;\r
 import com.gitblit.utils.TicgitUtils;\r
+import com.gitblit.wicket.GitBlitWebApp;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.PageRegistration;\r
 import com.gitblit.wicket.PageRegistration.OtherPageLink;\r
@@ -228,6 +229,8 @@ public abstract class RepositoryPage extends BasePage {
 \r
        protected Component createPersonPanel(String wicketId, PersonIdent identity,\r
                        Constants.SearchType searchType) {\r
+               GitBlitWebApp app = (GitBlitWebApp) GitBlitWebSession.get().getApplication();\r
+               final Class<? extends BasePage> searchPageClass = app.getSearchPageClass();\r
                String name = identity == null ? "" : identity.getName();\r
                String address = identity == null ? "" : identity.getEmailAddress();\r
                boolean showEmail = GitBlit.getBoolean(Keys.web.showEmailAddresses, false);\r
@@ -241,20 +244,20 @@ public abstract class RepositoryPage extends BasePage {
                                }\r
                        }\r
                        Fragment partial = new Fragment(wicketId, "partialPersonIdent", this);\r
-                       LinkPanel link = new LinkPanel("personName", "list", value, SearchPage.class,\r
+                       LinkPanel link = new LinkPanel("personName", "list", value, searchPageClass,\r
                                        WicketUtils.newSearchParameter(repositoryName, objectId, value, searchType));\r
                        setPersonSearchTooltip(link, value, searchType);\r
                        partial.add(link);\r
                        return partial;\r
                } else {\r
                        Fragment fullPerson = new Fragment(wicketId, "fullPersonIdent", this);\r
-                       LinkPanel nameLink = new LinkPanel("personName", "list", name, SearchPage.class,\r
+                       LinkPanel nameLink = new LinkPanel("personName", "list", name, searchPageClass,\r
                                        WicketUtils.newSearchParameter(repositoryName, objectId, name, searchType));\r
                        setPersonSearchTooltip(nameLink, name, searchType);\r
                        fullPerson.add(nameLink);\r
 \r
                        LinkPanel addressLink = new LinkPanel("personAddress", "list", "<" + address + ">",\r
-                                       SearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId,\r
+                                       searchPageClass, WicketUtils.newSearchParameter(repositoryName, objectId,\r
                                                        address, searchType));\r
                        setPersonSearchTooltip(addressLink, address, searchType);\r
                        fullPerson.add(addressLink);\r
@@ -357,7 +360,8 @@ public abstract class RepositoryPage extends BasePage {
                                        break;\r
                                }\r
                        }\r
-                       setResponsePage(SearchPage.class,\r
+                       GitBlitWebApp app = (GitBlitWebApp) GitBlitWebSession.get().getApplication();\r
+                       setResponsePage(app.getSearchPageClass(),\r
                                        WicketUtils.newSearchParameter(repositoryName, null, searchString, searchType));\r
                }\r
        }\r
index dc94f3c1766b329ebe461648bd54f679d153b345..37ab9f0ca45c15886f28bbc2a90aa67da92de728 100644 (file)
@@ -28,7 +28,10 @@ import com.gitblit.Constants;
 import com.gitblit.models.Activity;\r
 import com.gitblit.models.Activity.RepositoryCommit;\r
 import com.gitblit.utils.StringUtils;\r
+import com.gitblit.wicket.GitBlitWebApp;\r
+import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.WicketUtils;\r
+import com.gitblit.wicket.pages.BasePage;\r
 import com.gitblit.wicket.pages.CommitDiffPage;\r
 import com.gitblit.wicket.pages.CommitPage;\r
 import com.gitblit.wicket.pages.LogPage;\r
@@ -50,6 +53,9 @@ public class ActivityPanel extends BasePanel {
                super(wicketId);\r
 \r
                Collections.sort(recentActivity);\r
+               \r
+               GitBlitWebApp app = (GitBlitWebApp) GitBlitWebSession.get().getApplication();\r
+               final Class<? extends BasePage> searchPageClass = app.getSearchPageClass();\r
 \r
                DataView<Activity> activityView = new DataView<Activity>("activity",\r
                                new ListDataProvider<Activity>(recentActivity)) {\r
@@ -86,7 +92,7 @@ public class ActivityPanel extends BasePanel {
                                                // author search link\r
                                                String author = commit.getAuthorIdent().getName();\r
                                                LinkPanel authorLink = new LinkPanel("author", "list", author,\r
-                                                               SearchPage.class, WicketUtils.newSearchParameter(commit.repository,\r
+                                                               searchPageClass, WicketUtils.newSearchParameter(commit.repository,\r
                                                                                commit.getName(), author, Constants.SearchType.AUTHOR), true);\r
                                                setPersonSearchTooltip(authorLink, author, Constants.SearchType.AUTHOR);\r
                                                fragment.add(authorLink);\r
index 0d2fe4a941fbbdbd26706f9742ade469aea6fa66..58862095a2badb468da9b688974d59ca0cff1844 100644 (file)
@@ -35,7 +35,10 @@ import com.gitblit.models.RefModel;
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.utils.StringUtils;\r
+import com.gitblit.wicket.GitBlitWebApp;\r
+import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.WicketUtils;\r
+import com.gitblit.wicket.pages.BasePage;\r
 import com.gitblit.wicket.pages.BranchesPage;\r
 import com.gitblit.wicket.pages.CommitPage;\r
 import com.gitblit.wicket.pages.LogPage;\r
@@ -75,6 +78,9 @@ public class BranchesPanel extends BasePanel {
                        add(new Label("branches", new StringResourceModel("gb.branches", this, null)));\r
                }\r
 \r
+               GitBlitWebApp app = (GitBlitWebApp) GitBlitWebSession.get().getApplication();\r
+               final Class<? extends BasePage> searchPageClass = app.getSearchPageClass();\r
+\r
                ListDataProvider<RefModel> branchesDp = new ListDataProvider<RefModel>(branches);\r
                DataView<RefModel> branchesView = new DataView<RefModel>("branch", branchesDp) {\r
                        private static final long serialVersionUID = 1L;\r
@@ -91,7 +97,7 @@ public class BranchesPanel extends BasePanel {
 \r
                                String author = entry.getAuthorIdent().getName();\r
                                LinkPanel authorLink = new LinkPanel("branchAuthor", "list", author,\r
-                                               SearchPage.class, WicketUtils.newSearchParameter(model.name,\r
+                                               searchPageClass, WicketUtils.newSearchParameter(model.name,\r
                                                                entry.getName(), author, Constants.SearchType.AUTHOR));\r
                                setPersonSearchTooltip(authorLink, author, Constants.SearchType.AUTHOR);\r
                                item.add(authorLink);\r
index 36a768062ea411937f73f8c3b176b5859bcef815..23eb2b3f3744c1d421482aef79cc3a64fc8c9ca7 100644 (file)
@@ -38,7 +38,10 @@ import com.gitblit.models.PathModel.PathChangeModel;
 import com.gitblit.models.RefModel;\r
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.utils.StringUtils;\r
+import com.gitblit.wicket.GitBlitWebApp;\r
+import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.WicketUtils;\r
+import com.gitblit.wicket.pages.BasePage;\r
 import com.gitblit.wicket.pages.BlobDiffPage;\r
 import com.gitblit.wicket.pages.BlobPage;\r
 import com.gitblit.wicket.pages.CommitDiffPage;\r
@@ -94,6 +97,9 @@ public class HistoryPanel extends BasePanel {
                // breadcrumbs\r
                add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, path, objectId));\r
 \r
+               GitBlitWebApp app = (GitBlitWebApp) GitBlitWebSession.get().getApplication();\r
+               final Class<? extends BasePage> searchPageClass = app.getSearchPageClass();\r
+\r
                ListDataProvider<RevCommit> dp = new ListDataProvider<RevCommit>(commits);\r
                DataView<RevCommit> logView = new DataView<RevCommit>("commit", dp) {\r
                        private static final long serialVersionUID = 1L;\r
@@ -108,7 +114,7 @@ public class HistoryPanel extends BasePanel {
                                // author search link\r
                                String author = entry.getAuthorIdent().getName();\r
                                LinkPanel authorLink = new LinkPanel("commitAuthor", "list", author,\r
-                                               SearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId,\r
+                                               searchPageClass, WicketUtils.newSearchParameter(repositoryName, objectId,\r
                                                                author, Constants.SearchType.AUTHOR));\r
                                setPersonSearchTooltip(authorLink, author, Constants.SearchType.AUTHOR);\r
                                item.add(authorLink);\r
index a960f6e0bc89e80962ebee9c5fbd6e73396924de..380cc31507c992dc6d8f07d561ef11ad38983dd1 100644 (file)
@@ -35,7 +35,10 @@ import com.gitblit.Keys;
 import com.gitblit.models.RefModel;\r
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.utils.StringUtils;\r
+import com.gitblit.wicket.GitBlitWebApp;\r
+import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.WicketUtils;\r
+import com.gitblit.wicket.pages.BasePage;\r
 import com.gitblit.wicket.pages.CommitDiffPage;\r
 import com.gitblit.wicket.pages.CommitPage;\r
 import com.gitblit.wicket.pages.LogPage;\r
@@ -82,6 +85,9 @@ public class LogPanel extends BasePanel {
                                        WicketUtils.newRepositoryParameter(repositoryName)));\r
                }\r
 \r
+               GitBlitWebApp app = (GitBlitWebApp) GitBlitWebSession.get().getApplication();\r
+               final Class<? extends BasePage> searchPageClass = app.getSearchPageClass();\r
+\r
                ListDataProvider<RevCommit> dp = new ListDataProvider<RevCommit>(commits);\r
                DataView<RevCommit> logView = new DataView<RevCommit>("commit", dp) {\r
                        private static final long serialVersionUID = 1L;\r
@@ -96,7 +102,7 @@ public class LogPanel extends BasePanel {
                                // author search link\r
                                String author = entry.getAuthorIdent().getName();\r
                                LinkPanel authorLink = new LinkPanel("commitAuthor", "list", author,\r
-                                               SearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId,\r
+                                               searchPageClass, WicketUtils.newSearchParameter(repositoryName, objectId,\r
                                                                author, Constants.SearchType.AUTHOR));\r
                                setPersonSearchTooltip(authorLink, author, Constants.SearchType.AUTHOR);\r
                                item.add(authorLink);\r
index 92952119010689bebe27796f41d8be9161582cf1..eb7b66dd1978383132fcf814672aeab3f7cce5e6 100644 (file)
@@ -36,6 +36,7 @@ import com.gitblit.models.SearchResult;
 import com.gitblit.utils.IssueUtils;\r
 import com.gitblit.utils.IssueUtils.IssueFilter;\r
 import com.gitblit.utils.LuceneUtils;\r
+import com.gitblit.utils.StringUtils;\r
 \r
 /**\r
  * Tests the mechanics of distributed issue management on the gb-issues branch.\r
@@ -48,6 +49,8 @@ public class IssuesTest {
        @Test\r
        public void testLifecycle() throws Exception {\r
                Repository repository = GitBlitSuite.getIssuesTestRepository();\r
+               String name = StringUtils.getRelativePath(GitBlitSuite.REPOSITORIES.getAbsolutePath(),\r
+                               repository.getDirectory().getAbsolutePath());\r
                \r
                // create and insert an issue\r
                Change c1 = newChange("testCreation() " + Long.toHexString(System.currentTimeMillis()));\r
@@ -128,7 +131,7 @@ public class IssuesTest {
                // build a new Lucene index\r
                LuceneUtils.deleteIndex(repository);\r
                for (IssueModel anIssue : allIssues) {\r
-                       LuceneUtils.index(repository, anIssue);\r
+                       LuceneUtils.index(name, repository, anIssue);\r
                }\r
                List<SearchResult> hits = LuceneUtils.search("working", 10, repository);\r
                assertTrue(hits.size() > 0);\r
@@ -139,7 +142,7 @@ public class IssuesTest {
                change.comment("this is a test of reindexing an issue");\r
                IssueUtils.updateIssue(repository, issue.id, change);\r
                issue = IssueUtils.getIssue(repository, issue.id);\r
-               LuceneUtils.index(repository, issue);\r
+               LuceneUtils.index(name, repository, issue);\r
 \r
                // delete all issues\r
                for (IssueModel anIssue : allIssues) {\r
index 5e3882370b2788350d1d39ff8193d2003faa20fd..537100908073efbb0a97eaa922d5bd8a91ed60bd 100644 (file)
@@ -24,6 +24,7 @@ import org.junit.Test;
 \r
 import com.gitblit.models.SearchResult;\r
 import com.gitblit.utils.LuceneUtils;\r
+import com.gitblit.utils.StringUtils;\r
 \r
 /**\r
  * Tests Lucene indexing and querying.\r
@@ -37,19 +38,25 @@ public class LuceneUtilsTest {
        public void testFullIndex() throws Exception {\r
                // reindex helloworld\r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
-               LuceneUtils.reindex(repository);\r
+               String name = StringUtils.getRelativePath(GitBlitSuite.REPOSITORIES.getAbsolutePath(),\r
+                               repository.getDirectory().getAbsolutePath());\r
+               LuceneUtils.reindex(name, repository, false);\r
                repository.close();\r
 \r
                // reindex theoretical physics\r
                repository = GitBlitSuite.getTheoreticalPhysicsRepository();\r
-               LuceneUtils.reindex(repository);\r
+               name = StringUtils.getRelativePath(GitBlitSuite.REPOSITORIES.getAbsolutePath(),\r
+                               repository.getDirectory().getAbsolutePath());\r
+               LuceneUtils.reindex(name, repository, false);\r
                repository.close();\r
-\r
+               \r
                // reindex JGit\r
                repository = GitBlitSuite.getJGitRepository();\r
-               LuceneUtils.reindex(repository);\r
+               name = StringUtils.getRelativePath(GitBlitSuite.REPOSITORIES.getAbsolutePath(),\r
+                               repository.getDirectory().getAbsolutePath());\r
+               LuceneUtils.reindex(name, repository, false);\r
                repository.close();\r
-\r
+               \r
                LuceneUtils.close();\r
        }\r
 \r