The Unified and Autonomous Development Platform
Finished regular expression search API.
robin shined0312decaa6f
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/Symbol.java b/commons.lang/src/main/java/com/pmease/commons/lang/Symbol.javaindex b0355efa1c..aa8bac2855 100644--- a/commons.lang/src/main/java/com/pmease/commons/lang/Symbol.java+++ b/commons.lang/src/main/java/com/pmease/commons/lang/Symbol.java@@ -3,6 +3,7 @@ package com.pmease.commons.lang;import java.io.Serializable;import java.util.ArrayList;import java.util.List;+import java.util.regex.Pattern;import javax.annotation.Nullable;@@ -38,7 +39,22 @@ public abstract class Symbol implements Serializable {return searchables;}- public List<Symbol> search(String searchFor, boolean exactMatch, boolean caseSensitive) {+ public List<Symbol> search(Pattern pattern, int count) {+ List<Symbol> matches = new ArrayList<>();+ String searchable = getSearchable();+ if (searchable != null) {+ if (pattern.matcher(searchable).find())+ matches.add(this);+ }+ for (Symbol child: children) {+ if (matches.size() < count)+ matches.addAll(child.search(pattern, count-matches.size()));+ }++ return matches;+ }++ public List<Symbol> search(String searchFor, boolean exactMatch, boolean caseSensitive, int count) {List<Symbol> matches = new ArrayList<>();String searchable = getSearchable();if (searchable != null) {@@ -58,8 +74,10 @@ public abstract class Symbol implements Serializable {}}}- for (Symbol child: children)- matches.addAll(child.search(searchFor, exactMatch, caseSensitive));+ for (Symbol child: children) {+ if (matches.size() < count)+ matches.addAll(child.search(searchFor, exactMatch, caseSensitive, count-matches.size()));+ }return matches;}diff --git a/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultIndexManager.java b/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultIndexManager.javaindex 0aed04b56a..a05c33fa42 100644--- a/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultIndexManager.java+++ b/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultIndexManager.java@@ -236,7 +236,7 @@ public class DefaultIndexManager implements IndexManager {document.add(new StoredField(BLOB_INDEX_VERSION.name(), getCurrentBlobIndexVersion(extractor)));document.add(new StringField(BLOB_HASH.name(), blobId.name(), Store.NO));- document.add(new TextField(BLOB_PATH.name(), blobPath, Store.YES));+ document.add(new StringField(BLOB_PATH.name(), blobPath, Store.YES));if (blobPath.indexOf('/') != -1)document.add(new TextField(BLOB_SYMBOLS.name(), StringUtils.substringAfterLast(blobPath, "/"), Store.NO));diff --git a/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultSearchManager.java b/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultSearchManager.javaindex 63faad6992..74f89cf495 100644--- a/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultSearchManager.java+++ b/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultSearchManager.java@@ -127,6 +127,13 @@ public class DefaultSearchManager implements SearchManager, IndexListener {context.reader(), FieldConstants.BLOB_PATH.name(), false);String blobPath = cachedBlobPaths.get(doc).utf8ToString();+ /*+ if (query.getPathPrefix() != null && !blobPath.startsWith(query.getPathPrefix()))+ return;+ if (query.getPathSuffix() != null && !blobPath.endsWith(query.getPathSuffix()))+ return;+ */+if (!checkedBlobPaths.contains(blobPath)) {TreeWalk treeWalk = TreeWalk.forPath(repo, blobPath, revTree);if (treeWalk != null)diff --git a/gitplex.search/src/main/java/com/pmease/gitplex/search/query/BlobQuery.java b/gitplex.search/src/main/java/com/pmease/gitplex/search/query/BlobQuery.javaindex 045ace0f6f..db1267b101 100644--- a/gitplex.search/src/main/java/com/pmease/gitplex/search/query/BlobQuery.java+++ b/gitplex.search/src/main/java/com/pmease/gitplex/search/query/BlobQuery.java@@ -1,5 +1,6 @@package com.pmease.gitplex.search.query;+import static com.pmease.gitplex.search.FieldConstants.*;import static com.pmease.gitplex.search.IndexConstants.NGRAM_SIZE;import java.util.List;@@ -9,6 +10,7 @@ import javax.annotation.Nullable;import org.apache.lucene.search.BooleanClause.Occur;import org.apache.lucene.search.BooleanQuery;import org.apache.lucene.search.Query;+import org.apache.lucene.search.WildcardQuery;import org.eclipse.jgit.treewalk.TreeWalk;import com.pmease.gitplex.search.hit.QueryHit;@@ -32,17 +34,16 @@ public abstract class BlobQuery {private final String pathSuffix;- public BlobQuery(String fieldName, String searchFor, @Nullable String pathPrefix,- @Nullable String pathSuffix, boolean wordMatch, boolean caseSensitive,- boolean regex, int count) {+ public BlobQuery(String fieldName, String searchFor, boolean regex, boolean wordMatch, boolean caseSensitive,+ @Nullable String pathPrefix, @Nullable String pathSuffix, int count) {this.fieldName = fieldName;this.searchFor = searchFor;+ this.regex = regex;+ this.wordMatch = wordMatch;+ this.caseSensitive = caseSensitive;this.pathPrefix = pathPrefix;this.pathSuffix = pathSuffix;this.count = count;- this.caseSensitive = caseSensitive;- this.wordMatch = wordMatch;- this.regex = regex;}public String getFieldName() {@@ -81,17 +82,31 @@ public abstract class BlobQuery {public Query asLuceneQuery() {BooleanQuery query = new BooleanQuery(true);- if (regex)- query.add(new RegexLiterals(searchFor).asLuceneQuery(fieldName), Occur.MUST);- else if (searchFor.length() >= NGRAM_SIZE)+ if (regex) {+ Query literalsQuery = new RegexLiterals(searchFor).asLuceneQuery(fieldName);+ if (literalsQuery != null)+ query.add(literalsQuery, Occur.MUST);+ } else if (searchFor.length() >= NGRAM_SIZE) {query.add(new NGramLuceneQuery(fieldName, searchFor), Occur.MUST);-+ }++ /*if (pathPrefix != null && pathPrefix.length() >= NGRAM_SIZE)query.add(new NGramLuceneQuery(fieldName, pathPrefix), Occur.MUST);if (pathSuffix != null && pathSuffix.length() >= NGRAM_SIZE)query.add(new NGramLuceneQuery(fieldName, pathSuffix), Occur.MUST);+ */- return query;+ if (pathPrefix != null)+ query.add(new WildcardQuery(BLOB_PATH.term(pathPrefix + "*")), Occur.MUST);+ if (pathSuffix != null)+ query.add(new WildcardQuery(BLOB_PATH.term("*" + pathSuffix)), Occur.MUST);++ if (query.getClauses().length != 0)+ return query;+ else+ return new WildcardQuery(BLOB_PATH.term("*"));}+}diff --git a/gitplex.search/src/main/java/com/pmease/gitplex/search/query/SymbolQuery.java b/gitplex.search/src/main/java/com/pmease/gitplex/search/query/SymbolQuery.javaindex 7a3123b6e9..d345a108fa 100644--- a/gitplex.search/src/main/java/com/pmease/gitplex/search/query/SymbolQuery.java+++ b/gitplex.search/src/main/java/com/pmease/gitplex/search/query/SymbolQuery.java@@ -3,6 +3,7 @@ package com.pmease.gitplex.search.query;import java.io.IOException;import java.nio.charset.Charset;import java.util.List;+import java.util.regex.Pattern;import javax.annotation.Nullable;@@ -23,14 +24,14 @@ import com.pmease.gitplex.search.hit.SymbolHit;public class SymbolQuery extends BlobQuery {- public SymbolQuery(String searchFor, @Nullable String pathPrefix, @Nullable String pathSuffix,- boolean exactMatch, boolean caseSensitive, boolean regex, int count) {- super(FieldConstants.BLOB_SYMBOLS.name(), pathPrefix, pathSuffix, searchFor, exactMatch,- caseSensitive, regex, count);+ public SymbolQuery(String searchFor, boolean regex, boolean exactMatch, boolean caseSensitive,+ @Nullable String pathPrefix, @Nullable String pathSuffix, int count) {+ super(FieldConstants.BLOB_SYMBOLS.name(), searchFor, regex, exactMatch,+ caseSensitive, pathPrefix, pathSuffix, count);}- public SymbolQuery(String searchFor, boolean exactMatch, boolean caseSensitive, boolean regex, int count) {- this(searchFor, null, null, exactMatch, caseSensitive, regex, count);+ public SymbolQuery(String searchFor, boolean regex, boolean exactMatch, boolean caseSensitive, int count) {+ this(searchFor, regex, exactMatch, caseSensitive, null, null, count);}@Override@@ -49,10 +50,27 @@ public class SymbolQuery extends BlobQuery {if (charset != null) {String content = new String(bytes, charset);Symbol symbol = extractor.extract(content);- for (Symbol match: symbol.search(getSearchFor(), isWordMatch(), isCaseSensitive())) {- hits.add(new SymbolHit(blobPath, match));- if (hits.size() >= getCount())- break;+ int count = getCount()-hits.size();+ if (isRegex()) {+ String regex = getSearchFor();++ if (isWordMatch()) {+ if (!regex.startsWith("^"))+ regex = "^" + regex;+ if (!regex.endsWith("$"))+ regex = regex + "$";+ }+ Pattern pattern;+ if (isCaseSensitive())+ pattern = Pattern.compile(regex);+ else+ pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);++ for (Symbol match: symbol.search(pattern, count))+ hits.add(new SymbolHit(blobPath, match));+ } else {+ for (Symbol match: symbol.search(getSearchFor(), isWordMatch(), isCaseSensitive(), count))+ hits.add(new SymbolHit(blobPath, match));}}}diff --git a/gitplex.search/src/main/java/com/pmease/gitplex/search/query/TextQuery.java b/gitplex.search/src/main/java/com/pmease/gitplex/search/query/TextQuery.javaindex 227458dabf..0a6b3157fe 100644--- a/gitplex.search/src/main/java/com/pmease/gitplex/search/query/TextQuery.java+++ b/gitplex.search/src/main/java/com/pmease/gitplex/search/query/TextQuery.java@@ -4,6 +4,8 @@ import java.io.IOException;import java.nio.charset.Charset;import java.util.ArrayList;import java.util.List;+import java.util.regex.Matcher;+import java.util.regex.Pattern;import javax.annotation.Nullable;@@ -19,14 +21,14 @@ import com.pmease.gitplex.search.hit.QueryHit;public class TextQuery extends BlobQuery {- public TextQuery(String searchFor, @Nullable String pathPrefix, @Nullable String pathSuffix,- boolean caseSensitive, boolean regex, int count) {- super(FieldConstants.BLOB_TEXT.name(), searchFor, pathPrefix, pathSuffix, false,- caseSensitive, regex, count);+ public TextQuery(String searchFor, boolean regex, boolean matchWord, boolean caseSensitive,+ @Nullable String pathPrefix, @Nullable String pathSuffix, int count) {+ super(FieldConstants.BLOB_TEXT.name(), searchFor, regex, matchWord, caseSensitive,+ pathPrefix, pathSuffix, count);}- public TextQuery(String searchFor, boolean caseSensitive, boolean regex, int count) {- this(searchFor, null, null, caseSensitive, regex, count);+ public TextQuery(String searchFor, boolean regex, boolean matchWord, boolean caseSensitive, int count) {+ this(searchFor, regex, matchWord, caseSensitive, null, null, count);}@Override@@ -40,30 +42,61 @@ public class TextQuery extends BlobQuery {if (charset != null) {String blobPath = treeWalk.getPathString();String content = new String(bytes, charset);- String searchFor = getSearchFor();- if (!isCaseSensitive())- searchFor = searchFor.toLowerCase();-- int lineNo = 0;- for (String line: Splitter.on("\n").split(content)) {- List<TextHit.Match> matches = new ArrayList<>();- String normalizedLine = line;- if (!isCaseSensitive())- normalizedLine = line.toLowerCase();- int start = normalizedLine.indexOf(searchFor, 0);- while (start != -1) {- int end = start + searchFor.length();- matches.add(new TextHit.Match(start, end));- start = normalizedLine.indexOf(searchFor, end);++ if (isRegex()) {+ String regex = getSearchFor();+ if (isWordMatch()) {+ if (!regex.startsWith("\\b"))+ regex = "\\b" + regex;+ if (!regex.endsWith("\\b"))+ regex = regex + "\\b";}- if (!matches.isEmpty()) {- TextHit hit = new TextHit(blobPath, line, lineNo, matches);- hits.add(hit);- if (hits.size() >= getCount())- break;+ Pattern pattern;+ if (isCaseSensitive())+ pattern = Pattern.compile(regex);+ else+ pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);+ int lineNo = 0;+ for (String line: Splitter.on("\n").split(content)) {+ List<TextHit.Match> matches = new ArrayList<>();+ Matcher matcher = pattern.matcher(line);+ while (matcher.find())+ matches.add(new TextHit.Match(matcher.start(), matcher.end()));++ if (!matches.isEmpty()) {+ TextHit hit = new TextHit(blobPath, line, lineNo, matches);+ hits.add(hit);+ if (hits.size() >= getCount())+ break;+ }+ lineNo++;}+ } else {+ String searchFor = getSearchFor();+ if (!isCaseSensitive())+ searchFor = searchFor.toLowerCase();- lineNo++;+ int lineNo = 0;+ for (String line: Splitter.on("\n").split(content)) {+ List<TextHit.Match> matches = new ArrayList<>();+ String normalizedLine = line;+ if (!isCaseSensitive())+ normalizedLine = line.toLowerCase();+ int start = normalizedLine.indexOf(searchFor, 0);+ while (start != -1) {+ int end = start + searchFor.length();+ matches.add(new TextHit.Match(start, end));+ start = normalizedLine.indexOf(searchFor, end);+ }+ if (!matches.isEmpty()) {+ TextHit hit = new TextHit(blobPath, line, lineNo, matches);+ hits.add(hit);+ if (hits.size() >= getCount())+ break;+ }++ lineNo++;+ }}}}diff --git a/gitplex.search/src/main/java/com/pmease/gitplex/search/query/regex/RegexLiterals.java b/gitplex.search/src/main/java/com/pmease/gitplex/search/query/regex/RegexLiterals.javaindex 05df3d06eb..d136accb83 100644--- a/gitplex.search/src/main/java/com/pmease/gitplex/search/query/regex/RegexLiterals.java+++ b/gitplex.search/src/main/java/com/pmease/gitplex/search/query/regex/RegexLiterals.java@@ -4,10 +4,13 @@ import static com.pmease.gitplex.search.IndexConstants.NGRAM_SIZE;import java.util.List;+import javax.annotation.Nullable;+import org.antlr.v4.runtime.ANTLRInputStream;import org.antlr.v4.runtime.CommonTokenStream;import org.apache.lucene.search.BooleanClause.Occur;import org.apache.lucene.search.BooleanQuery;+import org.apache.lucene.search.Query;import com.google.common.base.Strings;import com.pmease.gitplex.search.query.NGramLuceneQuery;@@ -25,7 +28,8 @@ public class RegexLiterals {rows = orLiterals.flattern(true);}- public BooleanQuery asLuceneQuery(String fieldName) {+ @Nullable+ public Query asLuceneQuery(String fieldName) {BooleanQuery orQuery = new BooleanQuery();for (List<LeafLiterals> row: rows) {BooleanQuery andQuery = new BooleanQuery();@@ -33,9 +37,13 @@ public class RegexLiterals {if (literals.getLiteral() != null && literals.getLiteral().length()>=NGRAM_SIZE)andQuery.add(new NGramLuceneQuery(fieldName, literals.getLiteral()), Occur.MUST);}- orQuery.add(andQuery, Occur.SHOULD);+ if (andQuery.getClauses().length != 0)+ orQuery.add(andQuery, Occur.SHOULD);}- return orQuery;+ if (orQuery.getClauses().length != 0)+ return orQuery;+ else+ return null;}@Overridediff --git a/gitplex.search/src/test/java/com/pmease/gitplex/search/IndexAndSearchTest.java b/gitplex.search/src/test/java/com/pmease/gitplex/search/IndexAndSearchTest.javaindex 2a3bd62d62..4204b42885 100644--- a/gitplex.search/src/test/java/com/pmease/gitplex/search/IndexAndSearchTest.java+++ b/gitplex.search/src/test/java/com/pmease/gitplex/search/IndexAndSearchTest.java@@ -29,8 +29,9 @@ import com.pmease.gitplex.core.manager.IndexResult;import com.pmease.gitplex.core.manager.StorageManager;import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.search.hit.QueryHit;-import com.pmease.gitplex.search.query.TextQuery;+import com.pmease.gitplex.search.query.BlobQuery;import com.pmease.gitplex.search.query.SymbolQuery;+import com.pmease.gitplex.search.query.TextQuery;public class IndexAndSearchTest extends AbstractGitTest {@@ -89,16 +90,16 @@ public class IndexAndSearchTest extends AbstractGitTest {String commitHash = git.parseRevision("master", true);assertEquals(2, indexManager.index(repository, commitHash).getIndexed());- TextQuery contentQuery = new TextQuery("public", false, false, Integer.MAX_VALUE);- List<QueryHit> hits = searchManager.search(repository, commitHash, contentQuery);+ BlobQuery query = new TextQuery("public", false, false, false, Integer.MAX_VALUE);+ List<QueryHit> hits = searchManager.search(repository, commitHash, query);assertEquals(4, hits.size());- SymbolQuery symbolQuery = new SymbolQuery("nam", false, false, false, Integer.MAX_VALUE);- hits = searchManager.search(repository, commitHash, symbolQuery);+ query = new SymbolQuery("nam", false, false, false, Integer.MAX_VALUE);+ hits = searchManager.search(repository, commitHash, query);assertEquals(2, hits.size());- symbolQuery = new SymbolQuery("name", true, false, false, Integer.MAX_VALUE);- hits = searchManager.search(repository, commitHash, symbolQuery);+ query = new SymbolQuery("name", true, false, false, Integer.MAX_VALUE);+ hits = searchManager.search(repository, commitHash, query);assertEquals(2, hits.size());code = ""@@ -111,12 +112,12 @@ public class IndexAndSearchTest extends AbstractGitTest {commitHash = git.parseRevision("master", true);assertEquals(1, indexManager.index(repository, commitHash).getIndexed());- contentQuery = new TextQuery("strin", false, false, Integer.MAX_VALUE);- hits = searchManager.search(repository, commitHash, contentQuery);+ query = new TextQuery("strin", false, false, false, Integer.MAX_VALUE);+ hits = searchManager.search(repository, commitHash, query);assertEquals(2, hits.size());- symbolQuery = new SymbolQuery("Age", true, false, false, Integer.MAX_VALUE);- hits = searchManager.search(repository, commitHash, symbolQuery);+ query = new SymbolQuery("Age", true, false, false, Integer.MAX_VALUE);+ hits = searchManager.search(repository, commitHash, query);assertEquals(1, hits.size());code = ""@@ -174,8 +175,8 @@ public class IndexAndSearchTest extends AbstractGitTest {assertEquals(2, indexManager.index(repository, commitHash).getIndexed());- symbolQuery = new SymbolQuery("tiger", true, false, false, Integer.MAX_VALUE);- hits = searchManager.search(repository, commitHash, symbolQuery);+ query = new SymbolQuery("tiger", true, false, false, Integer.MAX_VALUE);+ hits = searchManager.search(repository, commitHash, query);assertEquals(2, hits.size());}@@ -184,6 +185,7 @@ public class IndexAndSearchTest extends AbstractGitTest {String code = ""+ "public class Dog {\n"+ " public String name;\n"+ + " public String nam;\n"+ "}";addFileAndCommit("Dog.java", code, "add dog");@@ -194,11 +196,63 @@ public class IndexAndSearchTest extends AbstractGitTest {addFileAndCommit("Cat.java", code, "add cat");String commitHash = git.parseRevision("master", true);- assertEquals(2, indexManager.index(repository, commitHash).getIndexed());+ indexManager.index(repository, commitHash);++ BlobQuery query = new TextQuery("public|}", true, false, false, Integer.MAX_VALUE);+ List<QueryHit> hits = searchManager.search(repository, commitHash, query);+ assertEquals(7, hits.size());- TextQuery contentQuery = new TextQuery("public", false, false, Integer.MAX_VALUE);- List<QueryHit> hits = searchManager.search(repository, commitHash, contentQuery);- assertEquals(4, hits.size());+ query = new TextQuery("nam", true, false, false, Integer.MAX_VALUE);+ hits = searchManager.search(repository, commitHash, query);+ assertEquals(3, hits.size());++ query = new TextQuery("nam", true, true, false, Integer.MAX_VALUE);+ hits = searchManager.search(repository, commitHash, query);+ assertEquals(1, hits.size());++ query = new SymbolQuery("\\w+", true, false, false, Integer.MAX_VALUE);+ hits = searchManager.search(repository, commitHash, query);+ assertEquals(5, hits.size());++ query = new SymbolQuery("nam", true, false, false, Integer.MAX_VALUE);+ hits = searchManager.search(repository, commitHash, query);+ assertEquals(3, hits.size());++ query = new SymbolQuery("nam", true, true, false, Integer.MAX_VALUE);+ hits = searchManager.search(repository, commitHash, query);+ assertEquals(1, hits.size());+ }++ @Test+ public void testPath() throws InterruptedException {+ String code = ""+ + "public class Dog {\n"+ + " public String name;\n"+ + "}";+ addFileAndCommit("animals/Dog.c", code, "add dog");++ code = ""+ + "public class Cat {\n"+ + " public String name;\n"+ + "}";+ addFileAndCommit("aminals/Cat.c", code, "add cat");++ code = ""+ + "public class Pine {\n"+ + " public String name;\n"+ + "}";+ addFileAndCommit("plants/Pine.java", code, "add pine");++ String commitHash = git.parseRevision("master", true);+ indexManager.index(repository, commitHash);++ BlobQuery query = new TextQuery("name", false, false, true, "plants/", null, Integer.MAX_VALUE);+ List<QueryHit> hits = searchManager.search(repository, commitHash, query);+ assertEquals(1, hits.size());++ query = new TextQuery("name", false, false, true, null, ".c", Integer.MAX_VALUE);+ hits = searchManager.search(repository, commitHash, query);+ assertEquals(2, hits.size());}@Overridediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/search/BlobSearcher.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/search/BlobSearcher.javaindex af6509ebc7..eafdbb36f2 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/search/BlobSearcher.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/search/BlobSearcher.java@@ -190,7 +190,7 @@ public abstract class BlobSearcher extends Panel {throw new RuntimeException(e);}- query = new TextQuery(input.getInput(), caseSensitive, false, MAX_QUERY_ENTRIES);+ query = new TextQuery(input.getInput(), false, caseSensitive, false, MAX_QUERY_ENTRIES);try {textHits = searchManager.search(repoModel.getObject(), commitHash, query);} catch (InterruptedException e) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.htmlindex 36b3973d1c..cb5237e578 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.html@@ -1,5 +1,6 @@<wicket:extend><a wicket:id="testIndex">test index</a>+ <a wicket:id="testSearch">test search</a><div wicket:id="searcher"></div>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.javaindex 93a2edbb37..c2816dcc4f 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java@@ -1,5 +1,7 @@package com.pmease.gitplex.web.page;+import java.util.List;+import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.markup.head.IHeaderResponse;import org.apache.wicket.markup.html.link.Link;@@ -9,7 +11,10 @@ import com.pmease.commons.hibernate.dao.Dao;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.manager.IndexManager;import com.pmease.gitplex.core.model.Repository;+import com.pmease.gitplex.search.SearchManager;import com.pmease.gitplex.search.hit.QueryHit;+import com.pmease.gitplex.search.query.BlobQuery;+import com.pmease.gitplex.search.query.TextQuery;import com.pmease.gitplex.web.component.search.BlobSearcher;@SuppressWarnings("serial")@@ -48,6 +53,24 @@ public class TestPage extends BasePage {});+ add(new Link<Void>("testSearch") {++ @Override+ public void onClick() {+ Repository repo = GitPlex.getInstance(Dao.class).load(Repository.class, 1L);+ SearchManager searchManager = GitPlex.getInstance(SearchManager.class);+ try {+ long time = System.currentTimeMillis();+ String commitHash = repo.git().parseRevision("master", true);+ BlobQuery query = new TextQuery("(s.*g)+w", true, false, false, null, null, 1000);+ List<QueryHit> hits = searchManager.search(repo, commitHash, query);+ System.out.println(hits.size());+ System.out.println(System.currentTimeMillis()-time);+ } catch (InterruptedException e) {+ }+ }++ });Repository repo = GitPlex.getInstance(Dao.class).load(Repository.class, 1L);String commitHash = repo.git().parseRevision("master", true);add(new BlobSearcher("searcher", Model.of(repo), commitHash, false) {