Skip to content

The Unified and Autonomous Development Platform

Refactor blob advanced search dialog.

robin shinea69233895f4f
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.java
index 2f4adab276..eb5c7d64c9 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
@@ -63,5 +63,7 @@ public abstract class Symbol implements Serializable {
@Nullable
public abstract String getScope();
+
+ public abstract boolean isPrimary();
}
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/java/CompilationUnit.java b/commons.lang/src/main/java/com/pmease/commons/lang/java/CompilationUnit.java
index b826b355d8..109b70887e 100644
--- a/commons.lang/src/main/java/com/pmease/commons/lang/java/CompilationUnit.java
+++ b/commons.lang/src/main/java/com/pmease/commons/lang/java/CompilationUnit.java
@@ -58,4 +58,9 @@ public class CompilationUnit extends JavaSymbol {
return packageName;
}
+ @Override
+ public boolean isPrimary() {
+ return false;
+ }
+
}
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/java/FieldDef.java b/commons.lang/src/main/java/com/pmease/commons/lang/java/FieldDef.java
index a58765c517..4dfe91a1ba 100644
--- a/commons.lang/src/main/java/com/pmease/commons/lang/java/FieldDef.java
+++ b/commons.lang/src/main/java/com/pmease/commons/lang/java/FieldDef.java
@@ -82,4 +82,9 @@ public class FieldDef extends JavaSymbol {
return getParent().getName();
}
+ @Override
+ public boolean isPrimary() {
+ return false;
+ }
+
}
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/java/MethodDef.java b/commons.lang/src/main/java/com/pmease/commons/lang/java/MethodDef.java
index b2196ce1fd..8c053d841e 100644
--- a/commons.lang/src/main/java/com/pmease/commons/lang/java/MethodDef.java
+++ b/commons.lang/src/main/java/com/pmease/commons/lang/java/MethodDef.java
@@ -99,5 +99,10 @@ public class MethodDef extends JavaSymbol {
else
return getParent().getName();
}
+
+ @Override
+ public boolean isPrimary() {
+ return false;
+ }
}
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/java/TypeDef.java b/commons.lang/src/main/java/com/pmease/commons/lang/java/TypeDef.java
index 99045457b7..92ed6e0e79 100644
--- a/commons.lang/src/main/java/com/pmease/commons/lang/java/TypeDef.java
+++ b/commons.lang/src/main/java/com/pmease/commons/lang/java/TypeDef.java
@@ -152,4 +152,9 @@ public class TypeDef extends JavaSymbol {
return new PackageResourceReference(Icons.class, icon);
}
+ @Override
+ public boolean isPrimary() {
+ return true;
+ }
+
}
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.java
index 3303e51930..642a5ce7d7 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
@@ -1,16 +1,6 @@
package com.pmease.gitplex.search;
-import static com.pmease.gitplex.search.FieldConstants.BLOB_HASH;
-import static com.pmease.gitplex.search.FieldConstants.BLOB_INDEX_VERSION;
-import static com.pmease.gitplex.search.FieldConstants.BLOB_PATH;
-import static com.pmease.gitplex.search.FieldConstants.BLOB_SYMBOLS;
-import static com.pmease.gitplex.search.FieldConstants.BLOB_TEXT;
-import static com.pmease.gitplex.search.FieldConstants.COMMIT_HASH;
-import static com.pmease.gitplex.search.FieldConstants.COMMIT_INDEX_VERSION;
-import static com.pmease.gitplex.search.FieldConstants.LAST_COMMIT;
-import static com.pmease.gitplex.search.FieldConstants.LAST_COMMIT_HASH;
-import static com.pmease.gitplex.search.FieldConstants.LAST_COMMIT_INDEX_VERSION;
-import static com.pmease.gitplex.search.FieldConstants.META;
+import static com.pmease.gitplex.search.FieldConstants.*;
import static com.pmease.gitplex.search.IndexConstants.MAX_INDEXABLE_SIZE;
import static com.pmease.gitplex.search.IndexConstants.NGRAM_SIZE;
@@ -230,10 +220,11 @@ public class DefaultIndexManager implements IndexManager {
document.add(new StringField(BLOB_HASH.name(), blobId.name(), Store.NO));
document.add(new StringField(BLOB_PATH.name(), blobPath, Store.YES));
+ String blobName = blobPath;
if (blobPath.indexOf('/') != -1)
- document.add(new StringField(BLOB_SYMBOLS.name(), StringUtils.substringAfterLast(blobPath, "/").toLowerCase(), Store.NO));
- else
- document.add(new StringField(BLOB_SYMBOLS.name(), blobPath.toLowerCase(), Store.NO));
+ blobName = StringUtils.substringAfterLast(blobPath, "/");
+
+ document.add(new StringField(BLOB_NAME.name(), blobName.toLowerCase(), Store.NO));
ObjectLoader objectLoader = repo.open(blobId);
if (objectLoader.getSize() <= MAX_INDEXABLE_SIZE) {
@@ -246,9 +237,17 @@ public class DefaultIndexManager implements IndexManager {
if (extractor != null) {
try {
for (Symbol symbol: extractor.extract(content)) {
- String name = symbol.getName();
- if (name != null)
- document.add(new StringField(BLOB_SYMBOLS.name(), name.toLowerCase(), Store.NO));
+ String fieldValue = symbol.getName();
+ if (fieldValue != null) {
+ fieldValue = fieldValue.toLowerCase();
+
+ String fieldName;
+ if (symbol.isPrimary())
+ fieldName = BLOB_PRIMARY_SYMBOLS.name();
+ else
+ fieldName = BLOB_SECONDARY_SYMBOLS.name();
+ document.add(new StringField(fieldName, fieldValue, Store.NO));
+ }
}
} catch (ExtractException e) {
logger.debug("Error extracting symbols from blob (hash:" + blobId.name() + ", path:" + blobPath + ")", e);
diff --git a/gitplex.search/src/main/java/com/pmease/gitplex/search/FieldConstants.java b/gitplex.search/src/main/java/com/pmease/gitplex/search/FieldConstants.java
index 70a439102c..1dd0632746 100644
--- a/gitplex.search/src/main/java/com/pmease/gitplex/search/FieldConstants.java
+++ b/gitplex.search/src/main/java/com/pmease/gitplex/search/FieldConstants.java
@@ -4,8 +4,8 @@ import org.apache.lucene.index.Term;
import org.apache.lucene.search.TermQuery;
public enum FieldConstants {
- BLOB_INDEX_VERSION, BLOB_HASH, BLOB_PATH, BLOB_SYMBOLS, BLOB_TEXT,
- COMMIT_INDEX_VERSION, COMMIT_HASH,
+ BLOB_INDEX_VERSION, BLOB_HASH, BLOB_PATH, BLOB_NAME, BLOB_PRIMARY_SYMBOLS,
+ BLOB_SECONDARY_SYMBOLS, BLOB_TEXT, COMMIT_INDEX_VERSION, COMMIT_HASH,
META, LAST_COMMIT, LAST_COMMIT_HASH, LAST_COMMIT_INDEX_VERSION;
public TermQuery query(String value) {
diff --git a/gitplex.search/src/main/java/com/pmease/gitplex/search/hit/TextHit.java b/gitplex.search/src/main/java/com/pmease/gitplex/search/hit/TextHit.java
index a2c7048c05..b4419f7f1c 100644
--- a/gitplex.search/src/main/java/com/pmease/gitplex/search/hit/TextHit.java
+++ b/gitplex.search/src/main/java/com/pmease/gitplex/search/hit/TextHit.java
@@ -41,7 +41,7 @@ public class TextHit extends QueryHit {
@Override
public ResourceReference getIcon() {
- return new PackageResourceReference(FileHit.class, "bullet.png");
+ return new PackageResourceReference(FileHit.class, "bullet.gif");
}
@Override
diff --git a/gitplex.search/src/main/java/com/pmease/gitplex/search/hit/bullet.gif b/gitplex.search/src/main/java/com/pmease/gitplex/search/hit/bullet.gif
new file mode 100644
index 0000000000..7b1efa5498
Binary files /dev/null and b/gitplex.search/src/main/java/com/pmease/gitplex/search/hit/bullet.gif differ
diff --git a/gitplex.search/src/main/java/com/pmease/gitplex/search/hit/bullet.png b/gitplex.search/src/main/java/com/pmease/gitplex/search/hit/bullet.png
deleted file mode 100644
index 57619706d1..0000000000
Binary files a/gitplex.search/src/main/java/com/pmease/gitplex/search/hit/bullet.png and /dev/null differ
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.java
index b2cbbe0ab8..34d869b8a3 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
@@ -2,11 +2,7 @@ package com.pmease.gitplex.search.query;
import static com.pmease.gitplex.search.FieldConstants.BLOB_PATH;
-import java.util.Collection;
import java.util.List;
-import java.util.regex.Pattern;
-
-import javax.annotation.Nullable;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
@@ -18,70 +14,16 @@ import com.pmease.gitplex.search.hit.QueryHit;
public abstract class BlobQuery {
- private final String fieldName;
-
- private final String term;
-
private final int count;
- private final boolean wordMatch;
-
- private final boolean regex;
-
- private final boolean caseSensitive;
-
- private final String pathPrefix;
-
- private final Collection<String> pathSuffixes;
-
- private transient Pattern pattern;
-
- private transient String casedTerm;
-
- public BlobQuery(String fieldName, String term, boolean regex, boolean wordMatch, boolean caseSensitive,
- @Nullable String pathPrefix, @Nullable Collection<String> pathSuffixes, int count) {
- this.fieldName = fieldName;
- this.term = term;
- this.regex = regex;
- this.wordMatch = wordMatch;
- this.caseSensitive = caseSensitive;
- this.pathPrefix = pathPrefix;
- this.pathSuffixes = pathSuffixes;
+ public BlobQuery(int count) {
this.count = count;
}
- public String getFieldName() {
- return fieldName;
- }
-
- public String getTerm() {
- return term;
- }
-
public int getCount() {
return count;
}
- public boolean isWordMatch() {
- return wordMatch;
- }
-
- public boolean isCaseSensitive() {
- return caseSensitive;
- }
-
- public String getPathPrefix() {
- return pathPrefix;
- }
-
- public Collection<String> getPathSuffixes() {
- return pathSuffixes;
- }
-
- public boolean isRegex() {
- return regex;
- }
-
public abstract void collect(TreeWalk treeWalk, List<QueryHit> hits);
/**
@@ -92,71 +34,11 @@ public abstract class BlobQuery {
* @throws
* TooGeneralQueryException if supplied query term is too general to possibly cause query slow
*/
- public Query asLuceneQuery() throws TooGeneralQueryException {
- BooleanQuery query = new BooleanQuery(true);
- query.add(asLuceneQuery(getTerm()), Occur.MUST);
-
- if (pathPrefix != null)
- query.add(new WildcardQuery(BLOB_PATH.term(pathPrefix + "*")), Occur.MUST);
- if (pathSuffixes != null && !pathSuffixes.isEmpty()) {
- BooleanQuery suffixQuery = new BooleanQuery(true);
- for (String suffix: pathSuffixes)
- suffixQuery.add(new WildcardQuery(BLOB_PATH.term("*" + suffix)), Occur.SHOULD);
- query.add(suffixQuery, Occur.MUST);
- }
-
- if (query.getClauses().length != 0)
- return query;
- else
- return new WildcardQuery(BLOB_PATH.term("*"));
- }
+ public abstract Query asLuceneQuery() throws TooGeneralQueryException;
- /**
- * Get lucene query representation of the search term
- *
- * @return
- * lucene query
- * @throws
- * TooGeneralQueryException if supplied query term is too general to possibly cause query slow
- */
- protected abstract Query asLuceneQuery(String term) throws TooGeneralQueryException;
-
- protected Pattern getPattern() {
- if (regex) {
- if (pattern == null) {
- String expression = getTerm();
- if (isWordMatch()) {
- if (!expression.startsWith("\\b"))
- expression = "\\b" + expression;
- if (!expression.endsWith("\\b"))
- expression = expression + "\\b";
- }
- if (isCaseSensitive())
- pattern = Pattern.compile(expression);
- else
- pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
- }
- return pattern;
- } else {
- return null;
- }
- }
-
- protected String getCasedTerm() {
- if (casedTerm == null) {
- if (caseSensitive)
- casedTerm = term;
- else
- casedTerm = term.toLowerCase();
- }
- return casedTerm;
- }
-
- protected String getCasedText(String text) {
- if (caseSensitive)
- return text;
- else
- return text.toLowerCase();
+ protected void applyDirectory(BooleanQuery query, String directory) {
+ if (!directory.endsWith("/"))
+ directory += "/";
+ query.add(new WildcardQuery(BLOB_PATH.term(directory + "*")), Occur.MUST);
}
-
}
diff --git a/gitplex.search/src/main/java/com/pmease/gitplex/search/query/FileQuery.java b/gitplex.search/src/main/java/com/pmease/gitplex/search/query/FileQuery.java
new file mode 100644
index 0000000000..b4c449b189
--- /dev/null
+++ b/gitplex.search/src/main/java/com/pmease/gitplex/search/query/FileQuery.java
@@ -0,0 +1,89 @@
+package com.pmease.gitplex.search.query;
+
+import static com.pmease.gitplex.search.FieldConstants.BLOB_NAME;
+
+import java.util.List;
+
+import javax.annotation.Nullable;
+
+import org.apache.lucene.index.Term;
+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.google.common.base.Splitter;
+import com.pmease.commons.util.StringUtils;
+import com.pmease.commons.util.pattern.WildcardUtils;
+import com.pmease.gitplex.search.hit.FileHit;
+import com.pmease.gitplex.search.hit.QueryHit;
+
+public class FileQuery extends BlobQuery {
+
+ private final String fileNames;
+
+ private final boolean caseSensitive;
+
+ private final String directory;
+
+ public FileQuery(String fileNames, boolean caseSensitive, @Nullable String directory, int count) {
+ super(count);
+
+ this.fileNames = fileNames;
+ this.caseSensitive = caseSensitive;
+ this.directory = directory;
+ }
+
+ @Override
+ public void collect(TreeWalk treeWalk, List<QueryHit> hits) {
+ String blobPath = treeWalk.getPathString();
+ if (caseSensitive) {
+ String blobName;
+ int index = blobPath.indexOf('/');
+ if (index != -1)
+ blobName = StringUtils.substringAfterLast(blobPath, "/");
+ else
+ blobName = blobPath;
+
+ for (String pattern: Splitter.on(",").omitEmptyStrings().trimResults().split(fileNames)) {
+ if (WildcardUtils.matchString(pattern, blobName)) {
+ hits.add(new FileHit(blobPath));
+ break;
+ }
+ }
+ } else {
+ hits.add(new FileHit(blobPath));
+ }
+ }
+
+ @Override
+ public Query asLuceneQuery() throws TooGeneralQueryException {
+ BooleanQuery query = new BooleanQuery(true);
+
+ if (directory != null)
+ applyDirectory(query, directory);
+
+ boolean tooGeneral = true;
+ for (char ch: fileNames.toCharArray()) {
+ if (ch != '?' && ch != '*' && ch != ',' && ch != '.') {
+ tooGeneral = false;
+ break;
+ }
+ }
+ if (tooGeneral)
+ throw new TooGeneralQueryException();
+
+ BooleanQuery subQuery = new BooleanQuery(true);
+ for (String pattern: Splitter.on(",").omitEmptyStrings().trimResults().split(fileNames.toLowerCase()))
+ subQuery.add(new WildcardQuery(new Term(BLOB_NAME.name(), pattern)), Occur.SHOULD);
+
+ if (subQuery.getClauses().length != 0)
+ query.add(subQuery, Occur.MUST);
+ else
+ throw new TooGeneralQueryException();
+
+ return query;
+ }
+
+}
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.java
index dca67b4150..ad353c4c67 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
@@ -1,50 +1,62 @@
package com.pmease.gitplex.search.query;
+import static com.pmease.gitplex.search.FieldConstants.BLOB_NAME;
+import static com.pmease.gitplex.search.FieldConstants.BLOB_PRIMARY_SYMBOLS;
+import static com.pmease.gitplex.search.FieldConstants.BLOB_SECONDARY_SYMBOLS;
+import static com.pmease.gitplex.search.IndexConstants.MAX_INDEXABLE_SIZE;
+
import java.io.IOException;
import java.nio.charset.Charset;
-import java.util.Collection;
import java.util.List;
-import java.util.regex.Pattern;
import javax.annotation.Nullable;
import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause.Occur;
+import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Query;
-import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.WildcardQuery;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Splitter;
import com.pmease.commons.lang.ExtractException;
import com.pmease.commons.lang.Extractor;
import com.pmease.commons.lang.Extractors;
import com.pmease.commons.lang.Symbol;
import com.pmease.commons.util.Charsets;
-import com.pmease.commons.util.StringUtils;
+import com.pmease.commons.util.pattern.WildcardUtils;
import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.search.FieldConstants;
-import com.pmease.gitplex.search.IndexConstants;
-import com.pmease.gitplex.search.hit.FileHit;
import com.pmease.gitplex.search.hit.QueryHit;
import com.pmease.gitplex.search.hit.SymbolHit;
-import com.pmease.gitplex.search.query.regex.RegexLiterals;
public class SymbolQuery extends BlobQuery {
private static final Logger logger = LoggerFactory.getLogger(SymbolQuery.class);
+
+ private final String term;
+
+ private final boolean primary;
+
+ private final boolean caseSensitive;
+
+ private final String directory;
+
+ private final String fileNames;
- public SymbolQuery(String term, boolean regex, boolean exactMatch, boolean caseSensitive,
- @Nullable String pathPrefix, Collection<String> pathSuffixes, int count) {
- super(FieldConstants.BLOB_SYMBOLS.name(), term, regex, exactMatch,
- caseSensitive, pathPrefix, pathSuffixes, count);
+ public SymbolQuery(String term, boolean primary, boolean caseSensitive,
+ @Nullable String directory, @Nullable String fileNames, int count) {
+ super(count);
+
+ this.term = term;
+ this.primary = primary;
+ this.caseSensitive = caseSensitive;
+ this.directory = directory;
+ this.fileNames = fileNames;
}
- public SymbolQuery(String term, boolean regex, boolean exactMatch, boolean caseSensitive, int count) {
- this(term, regex, exactMatch, caseSensitive, null, null, count);
- }
-
@Override
public void collect(TreeWalk treeWalk, List<QueryHit> hits) {
String blobPath = treeWalk.getPathString();
@@ -54,7 +66,7 @@ public class SymbolQuery extends BlobQuery {
ObjectLoader objectLoader;
try {
objectLoader = treeWalk.getObjectReader().open(treeWalk.getObjectId(0));
- if (objectLoader.getSize() <= IndexConstants.MAX_INDEXABLE_SIZE) {
+ if (objectLoader.getSize() <= MAX_INDEXABLE_SIZE) {
byte[] bytes = objectLoader.getCachedBytes();
Charset charset = Charsets.detectFrom(bytes);
if (charset != null) {
@@ -62,9 +74,20 @@ public class SymbolQuery extends BlobQuery {
try {
for (Symbol symbol: extractor.extract(content)) {
if (hits.size() < getCount()) {
- String name = symbol.getName();
- if (name != null) {
- if (matches(name))
+ if (primary == symbol.isPrimary() && symbol.getName() != null) {
+ String normalizedTerm;
+ if (!caseSensitive)
+ normalizedTerm = term.toLowerCase();
+ else
+ normalizedTerm = term;
+
+ String normalizedSymbolName;
+ if (!caseSensitive)
+ normalizedSymbolName = symbol.getName().toLowerCase();
+ else
+ normalizedSymbolName = symbol.getName();
+
+ if (WildcardUtils.matchString(normalizedTerm, normalizedSymbolName))
hits.add(new SymbolHit(blobPath, symbol));
}
} else {
@@ -81,49 +104,42 @@ public class SymbolQuery extends BlobQuery {
throw new RuntimeException(e);
}
}
+ }
- if (hits.size() < getCount()) {
- String blobName;
- int index = blobPath.indexOf('/');
- if (index != -1)
- blobName = StringUtils.substringAfterLast(blobPath, "/");
- else
- blobName = blobPath;
-
- if (matches(blobName))
- hits.add(new FileHit(blobPath));
+ @Override
+ public Query asLuceneQuery() throws TooGeneralQueryException {
+ BooleanQuery query = new BooleanQuery(true);
+
+ if (directory != null)
+ applyDirectory(query, directory);
+
+ if (fileNames != null) {
+ BooleanQuery subQuery = new BooleanQuery(true);
+ for (String pattern: Splitter.on(",").omitEmptyStrings().trimResults().split(fileNames.toLowerCase()))
+ subQuery.add(new WildcardQuery(new Term(BLOB_NAME.name(), pattern)), Occur.SHOULD);
+ if (subQuery.getClauses().length != 0)
+ query.add(subQuery, Occur.MUST);
}
- }
- private boolean matches(String text) {
- Pattern pattern = getPattern();
- String searchFor = getCasedTerm();
- if (pattern != null) {
- return pattern.matcher(text).find();
- } else {
- if (isWordMatch())
- return getCasedText(text).equals(searchFor);
- else
- return getCasedText(text).startsWith(searchFor);
+ boolean tooGeneral = true;
+ for (char ch: term.toCharArray()) {
+ if (ch != '?' && ch != '*') {
+ tooGeneral = false;
+ break;
+ }
}
+ if (tooGeneral)
+ throw new TooGeneralQueryException();
- }
-
- @Override
- protected Query asLuceneQuery(String term) {
- if (isRegex()) {
- return new RegexLiterals(term).asWildcardQuery(getFieldName());
- } else {
- term = StringUtils.replaceChars(term, "*?", "");
- if (StringUtils.isNotBlank(term)) {
- if (isWordMatch())
- return new TermQuery(new Term(getFieldName(), term.toLowerCase()));
- else
- return new WildcardQuery(new Term(getFieldName(), term.toLowerCase() + "*"));
- } else {
- throw new TooGeneralQueryException();
- }
- }
+ String fieldName;
+ if (primary)
+ fieldName = BLOB_PRIMARY_SYMBOLS.name();
+ else
+ fieldName = BLOB_SECONDARY_SYMBOLS.name();
+
+ query.add(new WildcardQuery(new Term(fieldName, term.toLowerCase())), Occur.MUST);
+
+ return query;
}
}
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.java
index 0c0267a2a3..dac53c0741 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
@@ -1,10 +1,11 @@
package com.pmease.gitplex.search.query;
+import static com.pmease.gitplex.search.FieldConstants.BLOB_NAME;
+import static com.pmease.gitplex.search.FieldConstants.BLOB_TEXT;
import static com.pmease.gitplex.search.IndexConstants.NGRAM_SIZE;
import java.io.IOException;
import java.nio.charset.Charset;
-import java.util.Collection;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -12,7 +13,11 @@ import java.util.regex.Pattern;
import javax.annotation.Nullable;
import org.apache.commons.lang3.CharUtils;
+import org.apache.lucene.index.Term;
+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.lib.ObjectLoader;
import org.eclipse.jgit.treewalk.TreeWalk;
@@ -20,7 +25,6 @@ import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
import com.pmease.commons.lang.TokenPosition;
import com.pmease.commons.util.Charsets;
-import com.pmease.gitplex.search.FieldConstants;
import com.pmease.gitplex.search.IndexConstants;
import com.pmease.gitplex.search.hit.QueryHit;
import com.pmease.gitplex.search.hit.TextHit;
@@ -29,15 +33,53 @@ import com.pmease.gitplex.search.query.regex.RegexLiterals;
public class TextQuery extends BlobQuery {
private static int MAX_LINE_LEN = 1024;
+
+ private final String term;
+
+ private final boolean regex;
+
+ private final boolean caseSensitive;
+
+ private final boolean wholeWord;
+
+ private final String directory;
+
+ private final String fileNames;
- public TextQuery(String term, boolean regex, boolean matchWord, boolean caseSensitive,
- @Nullable String pathPrefix, @Nullable Collection<String> pathSuffixes, int count) {
- super(FieldConstants.BLOB_TEXT.name(), term, regex, matchWord, caseSensitive,
- pathPrefix, pathSuffixes, count);
+ private transient Pattern pattern;
+
+ public TextQuery(String term, boolean regex, boolean caseSensitive, boolean wordMatch,
+ @Nullable String directory, @Nullable String fileNames, int count) {
+ super(count);
+
+ this.term = term;
+ this.regex = regex;
+ this.caseSensitive = caseSensitive;
+ this.wholeWord = wordMatch;
+ this.directory = directory;
+ this.fileNames = fileNames;
}
- public TextQuery(String term, boolean regex, boolean matchWord, boolean caseSensitive, int count) {
- this(term, regex, matchWord, caseSensitive, null, null, count);
+ @Nullable
+ private Pattern getPattern() {
+ if (regex) {
+ if (pattern == null) {
+ String expression = term;
+ if (wholeWord) {
+ if (!expression.startsWith("\\b"))
+ expression = "\\b" + expression;
+ if (!expression.endsWith("\\b"))
+ expression = expression + "\\b";
+ }
+ if (caseSensitive)
+ pattern = Pattern.compile(expression);
+ else
+ pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
+ }
+ return pattern;
+ } else {
+ return null;
+ }
}
@Override
@@ -70,15 +112,24 @@ public class TextQuery extends BlobQuery {
lineNo++;
}
} else {
- String casedTerm = getCasedTerm();
+ String normalizedTerm;
+ if (!caseSensitive)
+ normalizedTerm = term.toLowerCase();
+ else
+ normalizedTerm = term;
int lineNo = 0;
for (String line: Splitter.on("\n").split(content)) {
- String casedLine = getCasedText(line);
- int start = casedLine.indexOf(casedTerm, 0);
+ String normalizedLine;
+ if (!caseSensitive)
+ normalizedLine = line.toLowerCase();
+ else
+ normalizedLine = line;
+
+ int start = normalizedLine.indexOf(normalizedTerm, 0);
while (start != -1) {
- int end = start + casedTerm.length();
- if (isWordMatch()) {
+ int end = start + normalizedTerm.length();
+ if (wholeWord) {
char beforeChar;
if (start == 0)
beforeChar = ' ';
@@ -103,7 +154,7 @@ public class TextQuery extends BlobQuery {
if (hits.size() >= getCount())
break;
}
- start = casedLine.indexOf(casedTerm, end);
+ start = normalizedLine.indexOf(normalizedTerm, end);
}
if (hits.size() >= getCount())
break;
@@ -122,13 +173,28 @@ public class TextQuery extends BlobQuery {
}
@Override
- protected Query asLuceneQuery(String term) {
- if (isRegex())
- return new RegexLiterals(term).asNGramQuery(getFieldName(), NGRAM_SIZE);
- else if (term.length() >= NGRAM_SIZE)
- return new NGramLuceneQuery(getFieldName(), term, NGRAM_SIZE);
+ public Query asLuceneQuery() throws TooGeneralQueryException {
+ BooleanQuery query = new BooleanQuery(true);
+
+ if (directory != null)
+ applyDirectory(query, directory);
+
+ if (fileNames != null) {
+ BooleanQuery subQuery = new BooleanQuery(true);
+ for (String pattern: Splitter.on(",").omitEmptyStrings().trimResults().split(fileNames.toLowerCase()))
+ subQuery.add(new WildcardQuery(new Term(BLOB_NAME.name(), pattern)), Occur.SHOULD);
+ if (subQuery.getClauses().length != 0)
+ query.add(subQuery, Occur.MUST);
+ }
+
+ if (regex)
+ query.add(new RegexLiterals(term).asNGramQuery(BLOB_TEXT.name(), NGRAM_SIZE), Occur.MUST);
+ else if (term.length() >= NGRAM_SIZE)
+ query.add(new NGramLuceneQuery(BLOB_TEXT.name(), term, NGRAM_SIZE), Occur.MUST);
else
throw new TooGeneralQueryException();
+
+ return query;
}
}
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.java
index c5005de447..9d05acadbd 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
@@ -5,12 +5,15 @@ import static com.pmease.gitplex.search.IndexConstants.NGRAM_SIZE;
import java.util.List;
import org.antlr.v4.runtime.ANTLRInputStream;
+import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.CommonTokenStream;
-import org.apache.lucene.index.Term;
+import org.antlr.v4.runtime.RecognitionException;
+import org.antlr.v4.runtime.Recognizer;
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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.google.common.base.Strings;
import com.pmease.gitplex.search.query.NGramLuceneQuery;
@@ -18,14 +21,22 @@ import com.pmease.gitplex.search.query.TooGeneralQueryException;
public class RegexLiterals {
+ private static final Logger logger = LoggerFactory.getLogger(RegexLiterals.class);
+
private final List<List<LeafLiterals>> rows;
public RegexLiterals(String regex) {
ANTLRInputStream stream = new ANTLRInputStream(regex);
PCRELexer lexer = new PCRELexer(stream);
+ lexer.removeErrorListeners();
+ lexer.addErrorListener(ErrorListener.INSTANCE);
CommonTokenStream tokens = new CommonTokenStream(lexer);
- OrLiterals orLiterals = (OrLiterals) new LiteralVisitor().visit(new PCREParser(tokens).parse());
+ PCREParser parser = new PCREParser(tokens);
+ parser.removeErrorListeners();
+ parser.addErrorListener(ErrorListener.INSTANCE);
+
+ OrLiterals orLiterals = (OrLiterals) new LiteralVisitor().visit(parser.parse());
rows = orLiterals.flattern(true);
}
@@ -52,28 +63,6 @@ public class RegexLiterals {
throw new TooGeneralQueryException();
}
- /**
- * @param fieldName
- * @return
- * @throws TooGeneralQueryException
- */
- public Query asWildcardQuery(String fieldName) throws TooGeneralQueryException {
- BooleanQuery orQuery = new BooleanQuery();
- for (List<LeafLiterals> row: rows) {
- BooleanQuery andQuery = new BooleanQuery();
- for (LeafLiterals literals: row) {
- if (literals.getLiteral() != null && literals.getLiteral().length() != 0)
- andQuery.add(new WildcardQuery(new Term(fieldName, literals.getLiteral() + "*")), Occur.MUST);
- }
- if (andQuery.getClauses().length != 0)
- orQuery.add(andQuery, Occur.SHOULD);
- }
- if (orQuery.getClauses().length != 0)
- return orQuery;
- else
- throw new TooGeneralQueryException();
- }
-
@Override
public String toString() {
StringBuilder orBuilder = new StringBuilder();
@@ -93,4 +82,19 @@ public class RegexLiterals {
return orBuilder.toString();
}
+ private static class ErrorListener extends BaseErrorListener {
+
+ private static final ErrorListener INSTANCE = new ErrorListener();
+
+ @Override
+ public void syntaxError(Recognizer<?, ?> recognizer,
+ Object offendingSymbol,
+ int line,
+ int charPositionInLine,
+ String msg,
+ RecognitionException e) {
+ logger.error("line " + line + ":" + charPositionInLine + " " + msg);
+ }
+
+ }
}
diff --git a/gitplex.search/src/test/java/com/pmease/gitplex/search/IndexAndSearchTest.java b/gitplex.search/src/test/java/com/pmease/gitplex/search/IndexAndSearchTest.java
index 84a73538e4..8ef4ce6cbd 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
@@ -93,22 +93,26 @@ public class IndexAndSearchTest extends AbstractGitTest {
String commitHash = git.parseRevision("master", true);
assertEquals(2, indexManager.index(repository, commitHash).getIndexed());
- BlobQuery query = new TextQuery("public", false, false, false, Integer.MAX_VALUE);
+ BlobQuery query = new TextQuery("public", false, false, false, null, null, Integer.MAX_VALUE);
List<QueryHit> hits = searchManager.search(repository, commitHash, query);
assertEquals(4, hits.size());
- query = new SymbolQuery("nam", false, false, false, Integer.MAX_VALUE);
+ query = new SymbolQuery("nam*", false, false, null, null, Integer.MAX_VALUE);
hits = searchManager.search(repository, commitHash, query);
assertEquals(2, hits.size());
- query = new SymbolQuery("name", false, true, false, Integer.MAX_VALUE);
+ query = new SymbolQuery("nam", false, false, null, null, Integer.MAX_VALUE);
hits = searchManager.search(repository, commitHash, query);
- assertEquals(2, hits.size());
+ assertEquals(0, hits.size());
- query = new SymbolQuery("cat", false, false, false, Integer.MAX_VALUE);
+ query = new SymbolQuery("name", false, false, null, null, Integer.MAX_VALUE);
hits = searchManager.search(repository, commitHash, query);
assertEquals(2, hits.size());
+ query = new SymbolQuery("cat", true, false, null, null, Integer.MAX_VALUE);
+ hits = searchManager.search(repository, commitHash, query);
+ assertEquals(1, hits.size());
+
code = ""
+ "public class Dog {\n"
+ " public String name;\n"
@@ -119,11 +123,11 @@ public class IndexAndSearchTest extends AbstractGitTest {
commitHash = git.parseRevision("master", true);
assertEquals(1, indexManager.index(repository, commitHash).getIndexed());
- query = new TextQuery("strin", false, false, false, Integer.MAX_VALUE);
+ query = new TextQuery("strin", false, false, false, null, null, Integer.MAX_VALUE);
hits = searchManager.search(repository, commitHash, query);
assertEquals(2, hits.size());
- query = new SymbolQuery("Age", false, true, false, Integer.MAX_VALUE);
+ query = new SymbolQuery("Age", false, false, null, null, Integer.MAX_VALUE);
hits = searchManager.search(repository, commitHash, query);
assertEquals(1, hits.size());
@@ -177,6 +181,11 @@ public class IndexAndSearchTest extends AbstractGitTest {
public String getScope() {
throw new UnsupportedOperationException();
}
+
+ @Override
+ public boolean isPrimary() {
+ return false;
+ }
});
}
@@ -195,7 +204,7 @@ public class IndexAndSearchTest extends AbstractGitTest {
assertEquals(2, indexManager.index(repository, commitHash).getIndexed());
- query = new SymbolQuery("tiger", false, true, false, Integer.MAX_VALUE);
+ query = new SymbolQuery("tiger", false, true, null, null, Integer.MAX_VALUE);
hits = searchManager.search(repository, commitHash, query);
assertEquals(2, hits.size());
}
@@ -218,27 +227,15 @@ public class IndexAndSearchTest extends AbstractGitTest {
String commitHash = git.parseRevision("master", true);
indexManager.index(repository, commitHash);
- BlobQuery query = new TextQuery("public|}", true, false, false, Integer.MAX_VALUE);
+ BlobQuery query = new TextQuery("public|}", true, false, false, null, null, Integer.MAX_VALUE);
List<QueryHit> hits = searchManager.search(repository, commitHash, query);
assertEquals(7, 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(7, hits.size());
-
- query = new SymbolQuery("nam", true, false, false, Integer.MAX_VALUE);
+ query = new TextQuery("nam", true, false, false, null, null, Integer.MAX_VALUE);
hits = searchManager.search(repository, commitHash, query);
assertEquals(3, hits.size());
- query = new SymbolQuery("nam", true, true, false, Integer.MAX_VALUE);
+ query = new TextQuery("nam", true, false, true, null, null, Integer.MAX_VALUE);
hits = searchManager.search(repository, commitHash, query);
assertEquals(1, hits.size());
}
@@ -265,11 +262,11 @@ public class IndexAndSearchTest extends AbstractGitTest {
indexManager.index(repository, "master");
- BlobQuery query = new TextQuery("name", false, false, true, "plants/", null, Integer.MAX_VALUE);
+ BlobQuery query = new TextQuery("name", false, true, false, "plants/", null, Integer.MAX_VALUE);
List<QueryHit> hits = searchManager.search(repository, "master", query);
assertEquals(1, hits.size());
- query = new TextQuery("name", false, false, true, null, Lists.newArrayList(".c"), Integer.MAX_VALUE);
+ query = new TextQuery("name", false, true, false, null, "*.c", Integer.MAX_VALUE);
hits = searchManager.search(repository, "master", query);
assertEquals(2, hits.size());
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/BlobSearchPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/BlobSearchPanel.html
deleted file mode 100644
index 4c22140352..0000000000
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/BlobSearchPanel.html
+++ /dev/null
@@ -1,105 +0,0 @@
-<wicket:panel>
- <div class="blob-search">
- <input wicket:id="instantSearchInput" placeholder="File names, symbols, contents" class="form-control input-sm"/>
- <a title="Instant search" onclick="if (!$(this).prev().is(':visible')) $(this).prev().show().focus();" class="instant-search"><i class="fa fa-search"></i></a>
- <a wicket:id="advancedSearch" title="Advanced search"><i class="fa fa-binoculars"></i></a>
- </div>
- <div wicket:id="instantSearchDropdown"></div>
- <div wicket:id="advancedSearchDlg"></div>
- <wicket:fragment wicket:id="instantSearchResultFrag">
- <div class="instant-search-result">
- <div class="symbols section">
- <div class="title">File names and symbols</div>
- <wicket:enclosure child="symbolHits">
- <ul class="list-unstyled">
- <li wicket:id="symbolHits" class="hit selectable">
- <a wicket:id="link">
- <span class="icon"><img wicket:id="icon"></img></span>
- <span wicket:id="label" class="text"></span>
- <wicket:enclosure child="scope">
- <span class="scope">
- -- <span wicket:id="scope"></span>
- </span>
- </wicket:enclosure>
- </a>
- </li>
- <wicket:enclosure child="moreSymbolHits">
- <li class="hit selectable more-matches">
- <a wicket:id="moreSymbolHits">
- <span class="icon"><i class="fa fa-arrow-circle-right"></i></span>
- <span class="text">Show more</span>
- </a>
- </li>
- </wicket:enclosure>
- </ul>
- </wicket:enclosure>
- <div wicket:id="noSymbolHits" class="no-matches"><i class="fa fa-info-circle"></i> No matches</div>
- </div>
- <div wicket:id="texts" class="texts section">
- <div class="title">Text occurrences</div>
- <wicket:enclosure child="textHits">
- <ul class="list-unstyled">
- <li wicket:id="textHits" class="hit selectable">
- <a wicket:id="link">
- <span class="icon"><img wicket:id="icon"></img></span>
- <span wicket:id="label" class="text"></span>
- <wicket:enclosure child="scope">
- <span class="scope">
- -- <span wicket:id="scope"></span>
- </span>
- </wicket:enclosure>
- </a>
- </li>
- <wicket:enclosure child="moreTextHits">
- <li class="hit selectable more-matches">
- <a wicket:id="moreTextHits">
- <span class="icon"><i class="fa fa-arrow-circle-right"></i></span>
- <span class="text">Show more</span>
- </a>
- </li>
- </wicket:enclosure>
- </ul>
- </wicket:enclosure>
- <div wicket:id="noTextHits" class="no-matches"><i class="fa fa-info-circle"></i> No matches</div>
- </div>
- </div>
- </wicket:fragment>
- <wicket:fragment wicket:id="advancedSearchFrag">
- <form wicket:id="form" class="advanced-search">
- <div class="modal-header">
- <h4 class="modal-title">Advanced Search</h4>
- </div>
- <div class="modal-body">
- <div wicket:id="searchFor" class="form-group">
- <label>Search For</label>
- <input wicket:id="input" name="searchFor" class="form-control" type="text"></input>
- <div wicket:id="feedback"></div>
- </div>
- <div class="form-group">
- <label class="checkbox-inline"><input wicket:id="regex" type="checkbox"></input> Regular expression</label>
- <label class="checkbox-inline"><input wicket:id="wholeWord" type="checkbox"></input> Whole word</label>
- <label class="checkbox-inline"><input wicket:id="caseSensitive" type="checkbox"></input> Case sensitive</label>
- </div>
- <fieldset>
- <legend>Search Scope</legend>
- <div>
- <div class="form-group">
- <label>File types (separated by comma or space)</label>
- <input wicket:id="fileTypes" class="form-control" type="text" placeholder="File types such as *.java, *.c"></input>
- </div>
- <div wicket:id="searchType" class="form-group">
- <label class="radio-inline"><input wicket:id="texts" type="radio" name="searchScope"></input> Text occurrences</label>
- <label class="radio-inline"><input wicket:id="symbols" type="radio" name="searchScope"></input> File names and symbols</label>
- </div>
- </div>
- </fieldset>
- </div>
- <div class="modal-footer">
- <div class="form-group">
- <button wicket:id="search" class="btn btn-primary">Search</button>
- <button wicket:id="cancel" class="btn btn-default">Cancel</button>
- </div>
- </div>
- </form>
- </wicket:fragment>
-</wicket:panel>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/advanced/AdvancedSearchPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/advanced/AdvancedSearchPanel.html
new file mode 100644
index 0000000000..7e276cae46
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/advanced/AdvancedSearchPanel.html
@@ -0,0 +1,74 @@
+<wicket:panel>
+ <form wicket:id="form" class="advanced-search">
+ <div class="modal-header">
+ <h4 class="modal-title">Advanced Search</h4>
+ </div>
+ <div class="modal-body">
+ <ul wicket:id="tabs" class="nav nav-tabs"></ul>
+ <div wicket:id="searchOptions"></div>
+ </div>
+ <div class="modal-footer">
+ <div class="form-group">
+ <button wicket:id="search" class="btn btn-primary">Search</button>
+ <button wicket:id="cancel" class="btn btn-default">Cancel</button>
+ </div>
+ </div>
+ </form>
+ <wicket:fragment wicket:id="symbolSearchFrag">
+ <div wicket:id="term" class="form-group">
+ <label>Search For</label>
+ <input wicket:id="term" name="searchFor" class="form-control" type="text"></input>
+ <p class="help-block">(* = any string, ? = any character)</p>
+ <div wicket:id="feedback"></div>
+ </div>
+ <div class="form-group">
+ <label class="checkbox-inline"><input wicket:id="caseSensitive" type="checkbox"></input> Case sensitive</label>
+ </div>
+ <div class="form-group">
+ <label>File name patterns (separated by comma)</label>
+ <input wicket:id="fileNames" class="form-control" type="text"></input>
+ </div>
+ <wicket:enclosure child="insideCurrentDir">
+ <div class="form-group">
+ <label class="checkbox-inline"><input wicket:id="insideCurrentDir" type="checkbox"></input> Search inside current directory and sub directories</label>
+ </div>
+ </wicket:enclosure>
+ </wicket:fragment>
+ <wicket:fragment wicket:id="fileSearchFrag">
+ <div wicket:id="term" class="form-group">
+ <label>Search For</label>
+ <input wicket:id="term" name="searchFor" class="form-control" type="text"></input>
+ <p class="help-block">(* = any string, ? = any character)</p>
+ <div wicket:id="feedback"></div>
+ </div>
+ <div class="form-group">
+ <label class="checkbox-inline"><input wicket:id="caseSensitive" type="checkbox"></input> Case sensitive</label>
+ </div>
+ <wicket:enclosure child="insideCurrentDir">
+ <div class="form-group">
+ <label class="checkbox-inline"><input wicket:id="insideCurrentDir" type="checkbox"></input> Search inside current directory and sub directories</label>
+ </div>
+ </wicket:enclosure>
+ </wicket:fragment>
+ <wicket:fragment wicket:id="textSearchFrag">
+ <div wicket:id="term" class="form-group">
+ <label>Search For</label>
+ <input wicket:id="term" name="searchFor" class="form-control" type="text"></input>
+ <div wicket:id="feedback"></div>
+ </div>
+ <div class="form-group">
+ <label class="checkbox-inline"><input wicket:id="regex" type="checkbox"></input> Regular expression</label>
+ <label class="checkbox-inline"><input wicket:id="wholeWord" type="checkbox"></input> Whole word</label>
+ <label class="checkbox-inline"><input wicket:id="caseSensitive" type="checkbox"></input> Case sensitive</label>
+ </div>
+ <div class="form-group">
+ <label>File name patterns (separated by comma)</label>
+ <input wicket:id="fileNames" class="form-control" type="text" placeholder="File name patterns such as *.java, *.c"></input>
+ </div>
+ <wicket:enclosure child="insideCurrentDir">
+ <div class="form-group">
+ <label class="checkbox-inline"><input wicket:id="insideCurrentDir" type="checkbox"></input> Search inside current directory and sub directories</label>
+ </div>
+ </wicket:enclosure>
+ </wicket:fragment>
+</wicket:panel>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/advanced/AdvancedSearchPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/advanced/AdvancedSearchPanel.java
new file mode 100644
index 0000000000..87e68cb355
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/advanced/AdvancedSearchPanel.java
@@ -0,0 +1,577 @@
+package com.pmease.gitplex.web.component.blobsearch.advanced;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Nullable;
+import javax.servlet.http.Cookie;
+
+import org.apache.commons.lang3.SerializationUtils;
+import org.apache.shiro.codec.Base64;
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
+import org.apache.wicket.behavior.AttributeAppender;
+import org.apache.wicket.markup.head.CssHeaderItem;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.form.CheckBox;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.markup.html.panel.Fragment;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LoadableDetachableModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.model.PropertyModel;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.request.http.WebRequest;
+import org.apache.wicket.request.http.WebResponse;
+import org.apache.wicket.request.resource.CssResourceReference;
+import org.apache.wicket.validation.IErrorMessageSource;
+import org.apache.wicket.validation.INullAcceptingValidator;
+import org.apache.wicket.validation.IValidatable;
+import org.apache.wicket.validation.IValidationError;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.pmease.commons.git.BlobIdent;
+import com.pmease.commons.util.StringUtils;
+import com.pmease.commons.wicket.behavior.RunTaskBehavior;
+import com.pmease.commons.wicket.component.feedback.FeedbackPanel;
+import com.pmease.commons.wicket.component.tabbable.AjaxActionTab;
+import com.pmease.commons.wicket.component.tabbable.Tab;
+import com.pmease.commons.wicket.component.tabbable.Tabbable;
+import com.pmease.gitplex.core.GitPlex;
+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.FileQuery;
+import com.pmease.gitplex.search.query.SymbolQuery;
+import com.pmease.gitplex.search.query.TextQuery;
+import com.pmease.gitplex.search.query.TooGeneralQueryException;
+import com.pmease.gitplex.web.page.repository.file.SearchResultPanel;
+
+@SuppressWarnings("serial")
+public abstract class AdvancedSearchPanel extends Panel {
+
+ private static final String COOKIE_SEARCH_TYPE = "blob.search.advanced.type";
+
+ private static final Logger logger = LoggerFactory.getLogger(AdvancedSearchPanel.class);
+
+ private final IModel<Repository> repoModel;
+
+ private final IModel<String> revisionModel;
+
+ private Form<?> form;
+
+ private SearchOption option = new TextSearchOption();
+
+ public AdvancedSearchPanel(String id, IModel<Repository> repoModel, IModel<String> revisionModel) {
+ super(id);
+
+ this.repoModel = repoModel;
+ this.revisionModel = revisionModel;
+
+ WebRequest request = (WebRequest) RequestCycle.get().getRequest();
+ Cookie cookie = request.getCookie(COOKIE_SEARCH_TYPE);
+ if (cookie != null) {
+ try {
+ option = (SearchOption) Class.forName(cookie.getValue()).newInstance();
+ } catch (Exception e) {
+ logger.debug("Error restoring search option from cookie", e);
+ }
+ }
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ form = new Form<Void>("form");
+ form.setOutputMarkupId(true);
+ add(form);
+
+ List<Tab> tabs = new ArrayList<Tab>();
+ tabs.add(new AjaxActionTab(Model.of("Text occurrences")) {
+
+ @Override
+ protected void onSelect(AjaxRequestTarget target, Component tabLink) {
+ option = new TextSearchOption();
+ onSelectTab(target);
+ }
+
+ }.setSelected(option instanceof TextSearchOption));
+
+ tabs.add(new AjaxActionTab(Model.of("File names")) {
+
+ @Override
+ protected void onSelect(AjaxRequestTarget target, Component tabLink) {
+ option = new FileSearchOption();
+ onSelectTab(target);
+ }
+
+ }.setSelected(option instanceof FileSearchOption));
+
+ tabs.add(new AjaxActionTab(Model.of("Symbol names")) {
+
+ @Override
+ protected void onSelect(AjaxRequestTarget target, Component tabLink) {
+ option = new SymbolSearchOption();
+ onSelectTab(target);
+ }
+
+ }.setSelected(option instanceof SymbolSearchOption));
+
+ form.add(new Tabbable("tabs", tabs));
+
+ form.add(newSearchOptionEditor(option));
+
+ form.add(new AjaxSubmitLink("search") {
+
+ private RunTaskBehavior runTaskBehavior;
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ add(runTaskBehavior = new RunTaskBehavior() {
+
+ @Override
+ protected void runTask(AjaxRequestTarget target) {
+ List<QueryHit> hits;
+ try {
+ hits = option.query(AdvancedSearchPanel.this);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ WebResponse response = (WebResponse) RequestCycle.get().getResponse();
+ byte[] bytes = SerializationUtils.serialize(option);
+ Cookie cookie = new Cookie(option.getClass().getName(), Base64.encodeToString(bytes));
+ cookie.setMaxAge(Integer.MAX_VALUE);
+ response.addCookie(cookie);
+
+ onSearchComplete(target, hits);
+ }
+
+ });
+ }
+
+ @Override
+ protected void onError(AjaxRequestTarget target, Form<?> form) {
+ super.onError(target, form);
+ target.add(form);
+ }
+
+ @Override
+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
+ super.onSubmit(target, form);
+
+ runTaskBehavior.requestRun(target);
+ }
+
+ });
+
+ form.add(new AjaxLink<Void>("cancel") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ onCancel(target);
+ }
+
+ });
+ }
+
+ private void onSelectTab(AjaxRequestTarget target) {
+ WebResponse response = (WebResponse) RequestCycle.get().getResponse();
+ Cookie cookie = new Cookie(COOKIE_SEARCH_TYPE, option.getClass().getName());
+ cookie.setMaxAge(Integer.MAX_VALUE);
+ response.addCookie(cookie);
+ SearchOptionEditor editor = newSearchOptionEditor(option);
+ form.replace(editor);
+ target.add(editor);
+ }
+
+ private SearchOptionEditor newSearchOptionEditor(SearchOption option) {
+ if (option instanceof SymbolSearchOption)
+ return newSymbolSearchOptionEditor();
+ else if (option instanceof FileSearchOption)
+ return newFileSearchOptionEditor();
+ else
+ return newTextSearchOptionEditor();
+ }
+
+ private SearchOptionEditor newSymbolSearchOptionEditor() {
+ return new SearchOptionEditor("symbolSearchFrag") {
+
+ private TextField<String> termInput;
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ WebMarkupContainer termContainer = new WebMarkupContainer("term");
+ add(termContainer);
+ termInput = new TextField<String>("term", new PropertyModel<String>(option, "term"));
+ termInput.add(new INullAcceptingValidator<String>() {
+
+ @Override
+ public void validate(IValidatable<String> validatable) {
+ if (StringUtils.isBlank(validatable.getValue())) {
+ validatable.error(new IValidationError() {
+
+ @Override
+ public Serializable getErrorMessage(IErrorMessageSource messageSource) {
+ return "This field is required";
+ }
+
+ });
+ } else {
+ SymbolQuery query = new SymbolQuery(validatable.getValue(), true, false, null, null, 0);
+ try {
+ query.asLuceneQuery();
+ } catch (TooGeneralQueryException e) {
+ validatable.error(new IValidationError() {
+
+ @Override
+ public Serializable getErrorMessage(IErrorMessageSource messageSource) {
+ return "Search is too general";
+ }
+
+ });
+ }
+ }
+ }
+
+ });
+ termContainer.add(termInput);
+ termContainer.add(new FeedbackPanel("feedback", termInput));
+ termContainer.add(AttributeAppender.append("class", new LoadableDetachableModel<String>() {
+
+ @Override
+ protected String load() {
+ if (termInput.hasErrorMessage())
+ return " has-error";
+ else
+ return "";
+ }
+
+ }));
+
+ add(new CheckBox("caseSensitive", new PropertyModel<Boolean>(option, "caseSensitive")));
+
+ add(new TextField<String>("fileNames", new PropertyModel<String>(option, "fileNames")));
+
+ add(new CheckBox("insideCurrentDir", new PropertyModel<Boolean>(option, "insideCurrentDir")) {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ setVisible(getCurrentBlob().path != null);
+ }
+
+ });
+
+ }
+
+ };
+ }
+
+ private SearchOptionEditor newFileSearchOptionEditor() {
+ return new SearchOptionEditor("fileSearchFrag") {
+
+ private TextField<String> termInput;
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ WebMarkupContainer termContainer = new WebMarkupContainer("term");
+ add(termContainer);
+ termInput = new TextField<String>("term", new PropertyModel<String>(option, "term"));
+ termInput.add(new INullAcceptingValidator<String>() {
+
+ @Override
+ public void validate(IValidatable<String> validatable) {
+ if (StringUtils.isBlank(validatable.getValue())) {
+ validatable.error(new IValidationError() {
+
+ @Override
+ public Serializable getErrorMessage(IErrorMessageSource messageSource) {
+ return "This field is required";
+ }
+
+ });
+ } else {
+ FileQuery query = new FileQuery(validatable.getValue(), false, null, 0);
+ try {
+ query.asLuceneQuery();
+ } catch (TooGeneralQueryException e) {
+ validatable.error(new IValidationError() {
+
+ @Override
+ public Serializable getErrorMessage(IErrorMessageSource messageSource) {
+ return "Search is too general";
+ }
+
+ });
+ }
+ }
+ }
+
+ });
+
+ termContainer.add(termInput);
+ termContainer.add(new FeedbackPanel("feedback", termInput));
+ termContainer.add(AttributeAppender.append("class", new LoadableDetachableModel<String>() {
+
+ @Override
+ protected String load() {
+ if (termInput.hasErrorMessage())
+ return " has-error";
+ else
+ return "";
+ }
+
+ }));
+
+ add(new CheckBox("caseSensitive", new PropertyModel<Boolean>(option, "caseSensitive")));
+
+ add(new CheckBox("insideCurrentDir", new PropertyModel<Boolean>(option, "insideCurrentDir")) {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ setVisible(getCurrentBlob().path != null);
+ }
+
+ });
+
+ }
+
+ };
+ }
+
+ private SearchOptionEditor newTextSearchOptionEditor() {
+ return new SearchOptionEditor("textSearchFrag") {
+
+ private TextField<String> termInput;
+
+ private CheckBox regexCheck;
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ WebMarkupContainer termContainer = new WebMarkupContainer("term");
+ add(termContainer);
+ termInput = new TextField<String>("term", new PropertyModel<String>(option, "term"));
+ termInput.add(new INullAcceptingValidator<String>() {
+
+ @Override
+ public void validate(IValidatable<String> validatable) {
+ if (StringUtils.isBlank(validatable.getValue())) {
+ validatable.error(new IValidationError() {
+
+ @Override
+ public Serializable getErrorMessage(IErrorMessageSource messageSource) {
+ return "This field is required";
+ }
+
+ });
+ } else {
+ boolean regex = regexCheck.getInput()!=null?true:false;
+ TextQuery query = new TextQuery(validatable.getValue(), regex, false, false, null, null, 0);
+ try {
+ query.asLuceneQuery();
+ } catch (TooGeneralQueryException e) {
+ validatable.error(new IValidationError() {
+
+ @Override
+ public Serializable getErrorMessage(IErrorMessageSource messageSource) {
+ return "Search is too general";
+ }
+
+ });
+ }
+ }
+ }
+
+ });
+
+ termContainer.add(termInput);
+ termContainer.add(new FeedbackPanel("feedback", termInput));
+ termContainer.add(AttributeAppender.append("class", new LoadableDetachableModel<String>() {
+
+ @Override
+ protected String load() {
+ if (termInput.hasErrorMessage())
+ return " has-error";
+ else
+ return "";
+ }
+
+ }));
+
+ add(regexCheck = new CheckBox("regex", new PropertyModel<Boolean>(option, "regex")));
+
+ add(new CheckBox("wholeWord", new PropertyModel<Boolean>(option, "wholeWord")));
+
+ add(new CheckBox("caseSensitive", new PropertyModel<Boolean>(option, "caseSensitive")));
+
+ add(new TextField<String>("fileNames", new PropertyModel<String>(option, "fileNames")));
+
+ add(new CheckBox("insideCurrentDir", new PropertyModel<Boolean>(option, "insideCurrentDir")) {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ setVisible(getCurrentBlob().path != null);
+ }
+
+ });
+
+ }
+
+ };
+ }
+
+ @Override
+ protected void onDetach() {
+ repoModel.detach();
+ revisionModel.detach();
+
+ super.onDetach();
+ }
+
+ @Override
+ public void renderHead(IHeaderResponse response) {
+ super.renderHead(response);
+ response.render(CssHeaderItem.forReference(
+ new CssResourceReference(AdvancedSearchPanel.class, "advanced-search.css")));
+ }
+
+ protected abstract void onSearchComplete(AjaxRequestTarget target, List<QueryHit> hits);
+
+ protected abstract void onCancel(AjaxRequestTarget target);
+
+ @Nullable
+ protected abstract BlobIdent getCurrentBlob();
+
+ private class SearchOptionEditor extends Fragment {
+
+ public SearchOptionEditor(String markupId) {
+ super("searchOptions", markupId, AdvancedSearchPanel.this);
+
+ WebRequest request = (WebRequest) RequestCycle.get().getRequest();
+ Cookie cookie = request.getCookie(option.getClass().getName());
+ if (cookie != null) {
+ try {
+ byte[] bytes = Base64.decode(cookie.getValue());
+ option = (SearchOption) SerializationUtils.deserialize(bytes);
+ } catch (Exception e) {
+ logger.debug("Error restoring search option from cookie", e);
+ }
+ }
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+ setOutputMarkupId(true);
+ }
+
+ }
+
+ protected String getDirectory(boolean insideDir) {
+ BlobIdent blobIdent = getCurrentBlob();
+ if (blobIdent == null || blobIdent.path == null || !insideDir)
+ return null;
+ else if (blobIdent.isTree())
+ return blobIdent.path;
+ else
+ return StringUtils.substringBeforeLast(blobIdent.path, "/");
+ }
+
+ static interface SearchOption extends Serializable {
+ List<QueryHit> query(AdvancedSearchPanel context) throws InterruptedException;
+ }
+
+ static class SymbolSearchOption implements SearchOption {
+ private String term;
+
+ private String fileNames;
+
+ private boolean caseSensitive;
+
+ private boolean insideCurrentDir;
+
+ @Override
+ public List<QueryHit> query(AdvancedSearchPanel context) throws InterruptedException {
+ SearchManager searchManager = GitPlex.getInstance(SearchManager.class);
+ List<QueryHit> hits;
+ BlobQuery query = new SymbolQuery(term, true, caseSensitive,
+ context.getDirectory(insideCurrentDir), fileNames,
+ SearchResultPanel.QUERY_ENTRIES);
+ hits = searchManager.search(context.repoModel.getObject(), context.revisionModel.getObject(), query);
+
+ if (hits.size() < SearchResultPanel.QUERY_ENTRIES) {
+ query = new SymbolQuery(term, false, caseSensitive,
+ context.getDirectory(insideCurrentDir), fileNames,
+ SearchResultPanel.QUERY_ENTRIES - hits.size());
+ hits.addAll(searchManager.search(context.repoModel.getObject(), context.revisionModel.getObject(), query));
+ }
+
+ return hits;
+ }
+
+ }
+
+ static class FileSearchOption implements SearchOption {
+
+ private String term;
+
+ private boolean caseSensitive;
+
+ private boolean insideCurrentDir;
+
+ @Override
+ public List<QueryHit> query(AdvancedSearchPanel context) throws InterruptedException {
+ SearchManager searchManager = GitPlex.getInstance(SearchManager.class);
+ BlobQuery query = new FileQuery(term, caseSensitive,
+ context.getDirectory(insideCurrentDir), SearchResultPanel.QUERY_ENTRIES);
+ return searchManager.search(context.repoModel.getObject(), context.revisionModel.getObject(), query);
+ }
+
+ }
+
+ static class TextSearchOption implements SearchOption {
+ private String term;
+
+ private boolean regex;
+
+ private boolean caseSensitive;
+
+ private boolean wholeWord;
+
+ private String fileNames;
+
+ private boolean insideCurrentDir;
+
+ @Override
+ public List<QueryHit> query(AdvancedSearchPanel context) throws InterruptedException {
+ SearchManager searchManager = GitPlex.getInstance(SearchManager.class);
+ BlobQuery query = new TextQuery(term, regex, caseSensitive, wholeWord,
+ context.getDirectory(insideCurrentDir), fileNames, SearchResultPanel.QUERY_ENTRIES);
+ return searchManager.search(context.repoModel.getObject(), context.revisionModel.getObject(), query);
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/advanced/advanced-search.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/advanced/advanced-search.css
new file mode 100644
index 0000000000..618d6ed01e
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/advanced/advanced-search.css
@@ -0,0 +1,19 @@
+.advanced-search .nav-tabs {
+ margin-bottom: 16px;
+}
+.advanced-search .help-block {
+ margin-bottom: 0;
+}
+.advanced-search .alert {
+ background: none;
+ border: none;
+ padding: 12px 0 0 0;
+ margin-bottom: 0;
+}
+.advanced-search .alert:before {
+ font-family: "FontAwesome";
+ content: "\f071";
+}
+.advanced-search .alert .close {
+ display: none;
+}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/blob-search.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/blob-search.css
deleted file mode 100644
index 65ff74a4ce..0000000000
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/blob-search.css
+++ /dev/null
@@ -1,73 +0,0 @@
-.blob-search input.form-control {
- width: 200px;
- display: none;
- cursor: text;
-}
-.blob-search a {
- color: #666;
- margin-right: 4px;
-}
-.instant-search-result .section {
- margin-bottom: 8px;
-}
-.instant-search-result {
- padding: 8px;
- width: 600px;
- max-height: 600px;
- overflow: auto;
-}
-.instant-search-result a {
- color: #444;
-}
-.instant-search-result .section>.title {
- font-weight: bold;
- margin-bottom: 4px;
-}
-.instant-search-result tr.hit>td {
- vertical-align: top;
- padding: 1px 0;
-}
-.instant-search-result tr.hit>td.icon {
- width: 24px;
-}
-.instant-search-result tr.hit.active>td {
- background: #E8E8E8;
-}
-.instant-search-result tr.more-matches .fa {
- font-size: 16px;
-}
-.instant-search-result tr.more-matches>td {
- padding: 8px 0;
- font-style: italic;
-}
-.instant-search-result .no-matches {
- font-style: italic;
-}
-.instant-search-result td.content .scope {
- color: #666;
- font-size: 12px;
-}
-
-.advanced-search label {
- font-weight: normal;
-}
-.advanced-search .modal-footer {
- border-top: none;
-}
-.advanced-search fieldset {
- border: 1px solid #DDD;
- padding: 16px 12px;
-}
-.advanced-search fieldset legend {
- width: inherit;
- padding: 4px;
- margin: 0 0 0 -4px;
- border-bottom: none;
- font-size: 16px;
-}
-.advanced-search fieldset>div {
- margin-top: -12px;
-}
-.advanced-search .feedbackPanelERROR {
- margin-top: 16px;
-}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/instant/InstantSearchPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/instant/InstantSearchPanel.html
new file mode 100644
index 0000000000..81615566b0
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/instant/InstantSearchPanel.html
@@ -0,0 +1,64 @@
+<wicket:panel>
+ <span class="instant-search">
+ <input wicket:id="input" placeholder="Symbol, file, or text" class="form-control input-sm"/>
+ <a title="Instant search" onclick="if (!$(this).prev().is(':visible')) $(this).prev().show().focus();"><i class="fa fa-search"></i></a>
+ </span>
+ <div wicket:id="resultDropdown"></div>
+ <wicket:fragment wicket:id="resultFrag">
+ <div class="instant-search-result">
+ <wicket:enclosure child="symbolHits">
+ <div class="symbols section">
+ <div wicket:id="symbolsTitle" class="title">Symbols and files</div>
+ <ul class="list-unstyled">
+ <li wicket:id="symbolHits" class="hit selectable">
+ <a wicket:id="link">
+ <span class="icon"><img wicket:id="icon"></img></span>
+ <span wicket:id="label" class="text"></span>
+ <wicket:enclosure child="scope">
+ <span class="scope">
+ -- <span wicket:id="scope"></span>
+ </span>
+ </wicket:enclosure>
+ </a>
+ </li>
+ <wicket:enclosure child="moreSymbolHits">
+ <li class="hit selectable more-matches">
+ <a wicket:id="moreSymbolHits">
+ <span class="icon"><wicket:link><img src="point.png"></img></wicket:link></span>
+ <em class="text">Show more</em>
+ </a>
+ </li>
+ </wicket:enclosure>
+ </ul>
+ </div>
+ </wicket:enclosure>
+ <wicket:enclosure child="textHits">
+ <div class="texts section">
+ <div wicket:id="textsTitle" class="title">Text occurrences</div>
+ <ul class="list-unstyled">
+ <li wicket:id="textHits" class="hit selectable">
+ <a wicket:id="link">
+ <span class="icon"><img wicket:id="icon"></img></span>
+ <span wicket:id="label" class="text"></span>
+ <wicket:enclosure child="scope">
+ <span class="scope">
+ -- <span wicket:id="scope"></span>
+ </span>
+ </wicket:enclosure>
+ </a>
+ </li>
+ <wicket:enclosure child="moreTextHits">
+ <li class="hit selectable more-matches">
+ <a wicket:id="moreTextHits">
+ <span class="icon"><wicket:link><img src="point.png"></img></wicket:link></span>
+ <em class="text">Show more</em>
+ </a>
+ </li>
+ </wicket:enclosure>
+ </ul>
+ </div>
+ </wicket:enclosure>
+ <em wicket:id="noMatches"><i class="fa fa-info-circle"></i> No any matches</em>
+ </div>
+ </wicket:fragment>
+</wicket:panel>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/BlobSearchPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/instant/InstantSearchPanel.java
similarity index 51%
rename from gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/BlobSearchPanel.java
rename to gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/instant/InstantSearchPanel.java
index 6f83c6dc71..630d23ea50 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/BlobSearchPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/instant/InstantSearchPanel.java
@@ -1,4 +1,4 @@
-package com.pmease.gitplex.web.component.blobsearch;
+package com.pmease.gitplex.web.component.blobsearch.instant;
import java.util.ArrayList;
import java.util.List;
@@ -12,18 +12,12 @@ import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
import org.apache.wicket.ajax.attributes.CallbackParameter;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.AjaxLink;
-import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
-import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.form.CheckBox;
-import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.markup.html.form.Radio;
-import org.apache.wicket.markup.html.form.RadioGroup;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.list.ListItem;
@@ -32,63 +26,45 @@ import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
-import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.IRequestParameters;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.resource.CssResourceReference;
import org.apache.wicket.request.resource.JavaScriptResourceReference;
import org.apache.wicket.request.resource.ResourceReference;
-import com.google.common.base.CharMatcher;
-import com.google.common.base.Splitter;
import com.pmease.commons.util.StringUtils;
import com.pmease.commons.wicket.assets.hotkeys.HotkeysResourceReference;
import com.pmease.commons.wicket.behavior.RunTaskBehavior;
import com.pmease.commons.wicket.behavior.dropdown.DropdownBehavior;
import com.pmease.commons.wicket.behavior.dropdown.DropdownPanel;
-import com.pmease.commons.wicket.behavior.modal.ModalBehavior;
-import com.pmease.commons.wicket.behavior.modal.ModalPanel;
-import com.pmease.commons.wicket.component.feedback.FeedbackPanel;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.model.Repository;
-import com.pmease.gitplex.search.IndexConstants;
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.FileQuery;
import com.pmease.gitplex.search.query.SymbolQuery;
import com.pmease.gitplex.search.query.TextQuery;
import com.pmease.gitplex.search.query.TooGeneralQueryException;
-import com.pmease.gitplex.web.page.repository.file.RepoFilePage;
+import com.pmease.gitplex.web.page.repository.file.SearchResultPanel;
@SuppressWarnings("serial")
-public abstract class BlobSearchPanel extends Panel {
+public abstract class InstantSearchPanel extends Panel {
- public static final int ADVANCED_QUERY_ENTRIES = 1000;
+ private static final int QUERY_ENTRIES = 15;
- /*
- * Entries to query is much more than entries to be displayed in order to
- * cover important symbols (for instant types are important than fields...)
- * so that they can be sorted to be displayed first
- */
- private static final int SYMBOL_QUERY_ENTRIES = 300;
+ final IModel<Repository> repoModel;
- private static final int SYMBOL_DISPLAY_ENTRIES = 15;
+ final IModel<String> revisionModel;
- private static final int TEXT_QUERY_ENTRIES = 15;
+ private TextField<String> searchField;
- private final IModel<Repository> repoModel;
+ private String searchInput;
- private final IModel<String> revisionModel;
+ private DropdownPanel searchDropdown;
- private TextField<String> instantSearchField;
-
- private String instantSearchInput;
-
- private DropdownPanel instantSearchDropdown;
-
- private WebMarkupContainer instantSearchResult;
+ private WebMarkupContainer searchResult;
private List<QueryHit> symbolHits;
@@ -100,7 +76,7 @@ public abstract class BlobSearchPanel extends Panel {
private int activeHitIndex;
- public BlobSearchPanel(String id, IModel<Repository> repoModel, IModel<String> revisionModel) {
+ public InstantSearchPanel(String id, IModel<Repository> repoModel, IModel<String> revisionModel) {
super(id);
this.repoModel = repoModel;
@@ -111,14 +87,23 @@ public abstract class BlobSearchPanel extends Panel {
protected void onInitialize() {
super.onInitialize();
- instantSearchDropdown = new DropdownPanel("instantSearchDropdown") {
+ searchDropdown = new DropdownPanel("resultDropdown") {
@Override
protected Component newContent(String id) {
- instantSearchResult = new Fragment(id, "instantSearchResultFrag", BlobSearchPanel.this);
- instantSearchResult.setOutputMarkupId(true);
+ searchResult = new Fragment(id, "resultFrag", InstantSearchPanel.this);
+ searchResult.setOutputMarkupId(true);
- instantSearchResult.add(new ListView<QueryHit>("symbolHits", new AbstractReadOnlyModel<List<QueryHit>>() {
+ searchResult.add(new WebMarkupContainer("symbolsTitle") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(!textHits.isEmpty());
+ }
+
+ });
+ searchResult.add(new ListView<QueryHit>("symbolHits", new AbstractReadOnlyModel<List<QueryHit>>() {
@Override
public List<QueryHit> getObject() {
@@ -161,7 +146,7 @@ public abstract class BlobSearchPanel extends Panel {
}
});
- instantSearchResult.add(new AjaxLink<Void>("moreSymbolHits") {
+ searchResult.add(new AjaxLink<Void>("moreSymbolHits") {
@Override
protected void onInitialize() {
@@ -170,19 +155,35 @@ public abstract class BlobSearchPanel extends Panel {
@Override
protected void runTask(AjaxRequestTarget target) {
- SymbolQuery query = new SymbolQuery(
- instantSearchInput, false, false, false, RepoFilePage.MAX_QUERY_ENTRIES);
try {
+ List<QueryHit> hits = new ArrayList<>();
+
+ BlobQuery query = new SymbolQuery(searchInput+"*", true, false,
+ null, null, SearchResultPanel.QUERY_ENTRIES);
+
SearchManager searchManager = GitPlex.getInstance(SearchManager.class);
- List<QueryHit> hits = searchManager.search(repoModel.getObject(), revisionModel.getObject(), query);
- renderQueryHits(target, hits);
+
+ hits.addAll(searchManager.search(repoModel.getObject(), revisionModel.getObject(), query));
+
+ if (hits.size() < SearchResultPanel.QUERY_ENTRIES) {
+ query = new FileQuery(searchInput+"*", false, null,
+ SearchResultPanel.QUERY_ENTRIES-hits.size());
+ hits.addAll(searchManager.search(repoModel.getObject(), revisionModel.getObject(), query));
+ }
+
+ if (hits.size() < SearchResultPanel.QUERY_ENTRIES) {
+ query = new SymbolQuery(searchInput+"*", false, false,
+ null, null, SearchResultPanel.QUERY_ENTRIES-hits.size());
+ hits.addAll(searchManager.search(repoModel.getObject(), revisionModel.getObject(), query));
+ }
+ onSearchComplete(target, hits);
} catch (TooGeneralQueryException e) {
// this is impossible as we already queried part of the result
throw new IllegalStateException();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
- instantSearchDropdown.hide(target);
+ searchDropdown.hide(target);
}
});
@@ -191,7 +192,7 @@ public abstract class BlobSearchPanel extends Panel {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(symbolHits.size()==SYMBOL_DISPLAY_ENTRIES);
+ setVisible(symbolHits.size() == QUERY_ENTRIES);
}
@Override
@@ -199,28 +200,18 @@ public abstract class BlobSearchPanel extends Panel {
moreSymbolHitsBehavior.requestRun(target);
}
- });
- instantSearchResult.add(new WebMarkupContainer("noSymbolHits") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(symbolHits.isEmpty());
- }
-
});
- WebMarkupContainer textSection = new WebMarkupContainer("texts") {
+ searchResult.add(new WebMarkupContainer("textsTitle") {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(instantSearchInput != null && instantSearchInput.length() >= IndexConstants.NGRAM_SIZE);
+ setVisible(!symbolHits.isEmpty());
}
- };
- instantSearchResult.add(textSection);
- textSection.add(new ListView<QueryHit>("textHits", new AbstractReadOnlyModel<List<QueryHit>>() {
+ });
+ searchResult.add(new ListView<QueryHit>("textHits", new AbstractReadOnlyModel<List<QueryHit>>() {
@Override
public List<QueryHit> getObject() {
@@ -263,7 +254,7 @@ public abstract class BlobSearchPanel extends Panel {
}
});
- textSection.add(new AjaxLink<Void>("moreTextHits") {
+ searchResult.add(new AjaxLink<Void>("moreTextHits") {
@Override
protected void onInitialize() {
@@ -272,19 +263,19 @@ public abstract class BlobSearchPanel extends Panel {
@Override
protected void runTask(AjaxRequestTarget target) {
- TextQuery query = new TextQuery(
- instantSearchInput, false, false, false, RepoFilePage.MAX_QUERY_ENTRIES);
+ TextQuery query = new TextQuery(searchInput, false, false, false,
+ null, null, SearchResultPanel.QUERY_ENTRIES);
try {
SearchManager searchManager = GitPlex.getInstance(SearchManager.class);
List<QueryHit> hits = searchManager.search(repoModel.getObject(), revisionModel.getObject(), query);
- renderQueryHits(target, hits);
+ onSearchComplete(target, hits);
} catch (TooGeneralQueryException e) {
// this is impossible as we already queried part of the result
throw new IllegalStateException();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
- instantSearchDropdown.hide(target);
+ searchDropdown.hide(target);
}
});
@@ -293,7 +284,7 @@ public abstract class BlobSearchPanel extends Panel {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(textHits.size()==TEXT_QUERY_ENTRIES);
+ setVisible(textHits.size() == QUERY_ENTRIES);
}
@Override
@@ -302,82 +293,89 @@ public abstract class BlobSearchPanel extends Panel {
}
});
- textSection.add(new WebMarkupContainer("noTextHits") {
+
+ searchResult.add(new WebMarkupContainer("noMatches") {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(textHits.isEmpty());
+ setVisible(symbolHits.isEmpty() && textHits.isEmpty());
}
});
- return instantSearchResult;
+ return searchResult;
}
};
- add(instantSearchDropdown);
+ add(searchDropdown);
- instantSearchField = new TextField<>("instantSearchInput", Model.of(""));
- instantSearchField.add(new AjaxFormComponentUpdatingBehavior("inputchange focus click") {
+ searchField = new TextField<>("input", Model.of(""));
+ searchField.add(new AjaxFormComponentUpdatingBehavior("inputchange focus click") {
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
- attributes.setChannel(new AjaxChannel("blob-instant-search", AjaxChannel.Type.DROP));
+ attributes.setChannel(new AjaxChannel("instant-search", AjaxChannel.Type.DROP));
}
@Override
protected void onUpdate(AjaxRequestTarget target) {
- if (instantSearchResult != null)
- target.add(instantSearchResult);
+ if (searchResult != null)
+ target.add(searchResult);
- instantSearchInput = instantSearchField.getInput();
+ searchInput = searchField.getInput();
- if (StringUtils.isNotBlank(instantSearchInput)) {
+ if (StringUtils.isNotBlank(searchInput)) {
SearchManager searchManager = GitPlex.getInstance(SearchManager.class);
- BlobQuery blobQuery = new SymbolQuery(instantSearchInput, false, false, false, SYMBOL_QUERY_ENTRIES);
-
try {
- symbolHits = searchManager.search(repoModel.getObject(), revisionModel.getObject(), blobQuery);
+ BlobQuery query = new SymbolQuery(searchInput+"*", true, false,
+ null, null, QUERY_ENTRIES);
+ symbolHits = searchManager.search(repoModel.getObject(), revisionModel.getObject(), query);
+
+ if (symbolHits.size() < QUERY_ENTRIES) {
+ query = new FileQuery(searchInput+"*", false, null,
+ QUERY_ENTRIES-symbolHits.size());
+ symbolHits.addAll(searchManager.search(repoModel.getObject(), revisionModel.getObject(), query));
+ }
+
+ if (symbolHits.size() < QUERY_ENTRIES) {
+ query = new SymbolQuery(searchInput+"*", false, false,
+ null, null, QUERY_ENTRIES-symbolHits.size());
+ symbolHits.addAll(searchManager.search(repoModel.getObject(), revisionModel.getObject(), query));
+ }
} catch (TooGeneralQueryException e) {
symbolHits = new ArrayList<>();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
- if (symbolHits.size() > SYMBOL_DISPLAY_ENTRIES)
- symbolHits = new ArrayList<>(symbolHits.subList(0, SYMBOL_DISPLAY_ENTRIES));
-
- if (instantSearchInput.length() >= IndexConstants.NGRAM_SIZE) {
- TextQuery textQuery = new TextQuery(instantSearchInput, false, false, false, TEXT_QUERY_ENTRIES);
- try {
- textHits = searchManager.search(repoModel.getObject(), revisionModel.getObject(), textQuery);
- } catch (TooGeneralQueryException e) {
- symbolHits = new ArrayList<>();
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- } else {
+ try {
+ BlobQuery query = new TextQuery(searchInput, false, false, false,
+ null, null, QUERY_ENTRIES);
+ textHits = searchManager.search(repoModel.getObject(), revisionModel.getObject(), query);
+ } catch (TooGeneralQueryException e) {
textHits = new ArrayList<>();
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
}
- instantSearchDropdown.show(target);
+ searchDropdown.show(target);
} else {
symbolHits = new ArrayList<>();
textHits = new ArrayList<>();
- instantSearchDropdown.hide(target);
+ searchDropdown.hide(target);
}
activeHitIndex = 0;
}
});
- instantSearchField.add(new DropdownBehavior(instantSearchDropdown)
+ searchField.add(new DropdownBehavior(searchDropdown)
.mode(null)
.alignWithTrigger(100, 100, 100, 0, 6, true));
- instantSearchField.add(new AbstractDefaultAjaxBehavior() {
+ searchField.add(new AbstractDefaultAjaxBehavior() {
@Override
protected void respond(AjaxRequestTarget target) {
@@ -409,31 +407,27 @@ public abstract class BlobSearchPanel extends Panel {
response.render(JavaScriptHeaderItem.forReference(HotkeysResourceReference.INSTANCE));
response.render(JavaScriptHeaderItem.forReference(
- new JavaScriptResourceReference(BlobSearchPanel.class, "blob-search.js")));
+ new JavaScriptResourceReference(InstantSearchPanel.class, "instant-search.js")));
String script = String.format(
- "gitplex.blobSearch.init('%s', '%s', %s);",
- instantSearchField.getMarkupId(true), instantSearchDropdown.getMarkupId(true),
+ "gitplex.instantsearch.init('%s', '%s', %s);",
+ searchField.getMarkupId(true), searchDropdown.getMarkupId(true),
getCallbackFunction(CallbackParameter.explicit("key")));
response.render(OnDomReadyHeaderItem.forScript(script));
}
});
- add(instantSearchField);
-
- ModalPanel advancedSearchDlg = new AdvancedSearchDlg("advancedSearchDlg");
- add(advancedSearchDlg);
- add(new WebMarkupContainer("advancedSearch").add(new ModalBehavior(advancedSearchDlg)));
+ add(searchField);
}
private QueryHit getActiveHit() {
List<QueryHit> hits = new ArrayList<>();
hits.addAll(symbolHits);
- if (symbolHits.size() == SYMBOL_DISPLAY_ENTRIES)
+ if (symbolHits.size() == QUERY_ENTRIES)
hits.add(new MoreSymbolHit());
hits.addAll(textHits);
- if (textHits.size() == TEXT_QUERY_ENTRIES)
+ if (textHits.size() == QUERY_ENTRIES)
hits.add(new MoreTextHit());
if (activeHitIndex >=0 && activeHitIndex<hits.size())
@@ -449,7 +443,7 @@ public abstract class BlobSearchPanel extends Panel {
super.renderHead(response);
response.render(CssHeaderItem.forReference(
- new CssResourceReference(BlobSearchPanel.class, "blob-search.css")));
+ new CssResourceReference(InstantSearchPanel.class, "instant-search.css")));
}
@Override
@@ -461,173 +455,14 @@ public abstract class BlobSearchPanel extends Panel {
}
private void selectHit(AjaxRequestTarget target, QueryHit hit) {
- target.appendJavaScript(String.format("$('#%s').hide();", instantSearchField.getMarkupId(true)));
- instantSearchDropdown.hide(target);
+ target.appendJavaScript(String.format("$('#%s').hide();", searchField.getMarkupId(true)));
+ searchDropdown.hide(target);
onSelect(target, hit);
}
protected abstract void onSelect(AjaxRequestTarget target, QueryHit hit);
- protected abstract void renderQueryHits(AjaxRequestTarget target, List<QueryHit> hits);
-
- private class AdvancedSearchDlg extends ModalPanel {
-
- private static final String SEARCH_TEXTS = "texts";
-
- private static final String SEARCH_SYMBOLS = "symbols";
-
- private String searchFor;
-
- private boolean regex;
-
- private boolean wholeWord;
-
- private boolean caseSensitive;
-
- private String searchType = SEARCH_TEXTS;
-
- private String fileTypes;
-
- public AdvancedSearchDlg(String id) {
- super(id);
- }
-
- @Override
- protected Component newContent(String id, ModalBehavior behavior) {
- Fragment fragment = new Fragment(id, "advancedSearchFrag", BlobSearchPanel.this);
- final Form<?> form = new Form<Void>("form");
- form.setOutputMarkupId(true);
- fragment.add(form);
-
- WebMarkupContainer searchForContainer = new WebMarkupContainer("searchFor");
- form.add(searchForContainer);
- final TextField<String> searchForInput = new TextField<String>("input", new IModel<String>() {
-
- @Override
- public void detach() {
- }
-
- @Override
- public String getObject() {
- return searchFor;
- }
-
- @Override
- public void setObject(String object) {
- searchFor = object;
- }
-
- });
- searchForInput.setOutputMarkupId(true);
- searchForInput.setRequired(true);
- searchForContainer.add(searchForInput);
- searchForContainer.add(new FeedbackPanel("feedback", searchForInput));
- searchForContainer.add(AttributeAppender.append("class", new LoadableDetachableModel<String>() {
-
- @Override
- protected String load() {
- if (searchForInput.hasErrorMessage())
- return " has-error";
- else
- return "";
- }
-
- }));
-
- form.add(new CheckBox("regex", new PropertyModel<Boolean>(this, "regex")));
- form.add(new CheckBox("wholeWord", new PropertyModel<Boolean>(this, "wholeWord")));
- form.add(new CheckBox("caseSensitive", new PropertyModel<Boolean>(this, "caseSensitive")));
-
- form.add(new RadioGroup<String>("searchType", new PropertyModel<String>(this, "searchType")) {
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- add(new Radio<String>("texts", Model.of(SEARCH_TEXTS)));
- add(new Radio<String>("symbols", Model.of(SEARCH_SYMBOLS)));
- }
-
- });
-
- form.add(new TextField<String>("fileTypes", new PropertyModel<String>(this, "fileTypes")));
-
- form.add(new AjaxSubmitLink("search") {
-
- private RunTaskBehavior runTaskBehavior;
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- add(runTaskBehavior = new RunTaskBehavior() {
-
- @Override
- protected void runTask(AjaxRequestTarget target) {
- List<String> pathSuffixes = new ArrayList<>();
- if (fileTypes != null) {
- for (String fileType: Splitter.on(CharMatcher.anyOf(", \t")).trimResults().omitEmptyStrings().split(fileTypes)) {
- if (fileType.startsWith("*"))
- fileType = fileType.substring(1);
- if (!fileType.startsWith("."))
- fileType = "." + fileType;
- pathSuffixes.add(fileType);
- }
- }
-
- BlobQuery query;
- if (searchType.equals(SEARCH_SYMBOLS)) {
- query = new SymbolQuery(searchFor, regex, wholeWord, caseSensitive,
- null, pathSuffixes, ADVANCED_QUERY_ENTRIES);
- } else {
- query = new TextQuery(searchFor, regex, wholeWord, caseSensitive,
- null, pathSuffixes, ADVANCED_QUERY_ENTRIES);
- }
-
- try {
- SearchManager searchManager = GitPlex.getInstance(SearchManager.class);
- List<QueryHit> hits = searchManager.search(repoModel.getObject(), revisionModel.getObject(), query);
- renderQueryHits(target, hits);
- close(target);
- } catch (TooGeneralQueryException e) {
- searchForInput.error("Query term is too general.");
- target.add(form);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
-
- });
- }
-
- @Override
- protected void onError(AjaxRequestTarget target, Form<?> form) {
- super.onError(target, form);
- target.add(form);
- }
-
- @Override
- protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
- super.onSubmit(target, form);
-
- runTaskBehavior.requestRun(target);
- }
-
- });
-
- form.add(new AjaxLink<Void>("cancel") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- close(target);
- }
-
- });
-
- return fragment;
- }
-
- };
+ protected abstract void onSearchComplete(AjaxRequestTarget target, List<QueryHit> hits);
private static class MoreSymbolHit extends QueryHit {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/instant/instant-search.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/instant/instant-search.css
new file mode 100644
index 0000000000..5fab45e5e2
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/instant/instant-search.css
@@ -0,0 +1,25 @@
+.instant-search input.form-control {
+ width: 200px;
+ display: none;
+ cursor: text;
+}
+.instant-search a {
+ color: #666;
+}
+.instant-search-result .section {
+ margin-bottom: 8px;
+}
+.instant-search-result {
+ padding: 8px;
+ width: 600px;
+ max-height: 600px;
+ overflow: auto;
+}
+.instant-search-result .section>.title {
+ font-weight: bold;
+ margin-bottom: 4px;
+}
+.instant-search-result li.hit .scope {
+ color: #666;
+ font-size: 12px;
+}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/blob-search.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/instant/instant-search.js
similarity index 99%
rename from gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/blob-search.js
rename to gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/instant/instant-search.js
index 0a19cfbb58..b337b03240 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/blob-search.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/instant/instant-search.js
@@ -1,4 +1,4 @@
-gitplex.blobSearch = {
+gitplex.instantsearch = {
init: function(inputId, dropdownId, callback) {
var $input = $("#" + inputId);
var $dropdown = $("#" + dropdownId);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/instant/point.png b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/instant/point.png
new file mode 100644
index 0000000000..7efc7c6c38
Binary files /dev/null and b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobsearch/instant/point.png differ
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/source/SourceViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/source/SourceViewPanel.java
index 044eb3adf2..ab9799e981 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/source/SourceViewPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/source/SourceViewPanel.java
@@ -51,13 +51,12 @@ import com.pmease.gitplex.search.query.SymbolQuery;
import com.pmease.gitplex.search.query.TextQuery;
import com.pmease.gitplex.web.component.blobview.BlobViewContext;
import com.pmease.gitplex.web.component.blobview.BlobViewPanel;
+import com.pmease.gitplex.web.page.repository.file.SearchResultPanel;
@SuppressWarnings("serial")
public class SourceViewPanel extends BlobViewPanel {
- private static final int MAX_DECLARATION_QUERY_ENTRIES = 20;
-
- private static final int MAX_OCCURRENCE_QUERY_ENTRIES = 1000;
+ private static final int QUERY_ENTRIES = 20;
private static final Logger logger = LoggerFactory.getLogger(SourceViewPanel.class);
@@ -188,7 +187,7 @@ public class SourceViewPanel extends BlobViewPanel {
@Override
protected void runTask(AjaxRequestTarget target) {
BlobQuery query = new TextQuery(symbol, false, true, true,
- null, null, MAX_OCCURRENCE_QUERY_ENTRIES);
+ null, null, SearchResultPanel.QUERY_ENTRIES);
try {
SearchManager searchManager = GitPlex.getInstance(SearchManager.class);
List<QueryHit> hits = searchManager.search(context.getRepository(),
@@ -222,10 +221,15 @@ public class SourceViewPanel extends BlobViewPanel {
symbol = params.getParameterValue("symbol").toString();
if (symbol.startsWith("@"))
symbol = symbol.substring(1);
- SymbolQuery query = new SymbolQuery(symbol, false, true, true, MAX_DECLARATION_QUERY_ENTRIES);
try {
+ SymbolQuery query = new SymbolQuery(symbol, true, true, null, null, QUERY_ENTRIES);
SearchManager searchManager = GitPlex.getInstance(SearchManager.class);
symbolHits = searchManager.search(context.getRepository(), context.getBlobIdent().revision, query);
+ if (symbolHits.size() < QUERY_ENTRIES) {
+ query = new SymbolQuery(symbol, false, true, null, null, QUERY_ENTRIES - symbolHits.size());
+ symbolHits.addAll(searchManager.search(context.getRepository(),
+ context.getBlobIdent().revision, query));
+ }
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.html
index 85b548ba24..0b42a23cb0 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.html
@@ -4,7 +4,11 @@
<div class="head clearfix">
<div wicket:id="revisionSelector" class="pull-left"></div>
<div wicket:id="fileNavigator" class="pull-left"></div>
- <div wicket:id="fileSearcher" class="pull-right"></div>
+ <div class="pull-right search">
+ <span wicket:id="instantSearch"></span>
+ <a wicket:id="advancedSearch" title="Advanced search"><i class="fa fa-binoculars"></i></a>
+ <div wicket:id="advancedSearchModal"></div>
+ </div>
</div>
<div wicket:id="revisionIndexing" class="revision-indexing">
<img wicket:id="icon"></img>
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java
index 04f451da6e..b9879df18f 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java
@@ -41,13 +41,16 @@ import com.pmease.commons.lang.TokenPosition;
import com.pmease.commons.wicket.assets.closestdescendant.ClosestDescendantResourceReference;
import com.pmease.commons.wicket.assets.cookies.CookiesResourceReference;
import com.pmease.commons.wicket.behavior.HistoryBehavior;
+import com.pmease.commons.wicket.behavior.modal.ModalBehavior;
+import com.pmease.commons.wicket.behavior.modal.ModalPanel;
import com.pmease.commons.wicket.websocket.WebSocketRenderBehavior;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.search.IndexListener;
import com.pmease.gitplex.search.IndexManager;
import com.pmease.gitplex.search.hit.QueryHit;
-import com.pmease.gitplex.web.component.blobsearch.BlobSearchPanel;
+import com.pmease.gitplex.web.component.blobsearch.advanced.AdvancedSearchPanel;
+import com.pmease.gitplex.web.component.blobsearch.instant.InstantSearchPanel;
import com.pmease.gitplex.web.component.blobview.BlobViewContext;
import com.pmease.gitplex.web.component.blobview.source.SourceViewPanel;
import com.pmease.gitplex.web.component.filelist.FileListPanel;
@@ -61,8 +64,6 @@ import de.agilecoders.wicket.extensions.markup.html.bootstrap.jqueryui.JQueryUIR
@SuppressWarnings("serial")
public class RepoFilePage extends RepositoryPage {
- public static final int MAX_QUERY_ENTRIES = 1000;
-
private static final String PARAM_REVISION = "revision";
private static final String PARAM_PATH = "path";
@@ -138,7 +139,7 @@ public class RepoFilePage extends RepositoryPage {
newFileNavigator(null);
newFileViewer(null);
- add(new BlobSearchPanel("fileSearcher", repoModel, new AbstractReadOnlyModel<String>() {
+ add(new InstantSearchPanel("instantSearch", repoModel, new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
@@ -159,12 +160,48 @@ public class RepoFilePage extends RepositoryPage {
}
@Override
- protected void renderQueryHits(AjaxRequestTarget target, List<QueryHit> hits) {
+ protected void onSearchComplete(AjaxRequestTarget target, List<QueryHit> hits) {
renderSearchResult(target, hits);
}
});
+ ModalPanel advancedSearchModal = new ModalPanel("advancedSearchModal") {
+
+ @Override
+ protected Component newContent(String id, ModalBehavior behavior) {
+ return new AdvancedSearchPanel(id, repoModel, new AbstractReadOnlyModel<String>() {
+
+ @Override
+ public String getObject() {
+ return file.revision;
+ }
+
+ }) {
+
+ @Override
+ protected void onSearchComplete(AjaxRequestTarget target, List<QueryHit> hits) {
+ renderSearchResult(target, hits);
+ close(target);
+ }
+
+ @Override
+ protected void onCancel(AjaxRequestTarget target) {
+ close(target);
+ }
+
+ @Override
+ protected BlobIdent getCurrentBlob() {
+ return file;
+ }
+
+ };
+ }
+
+ };
+ add(advancedSearchModal);
+ add(new WebMarkupContainer("advancedSearch").add(new ModalBehavior(advancedSearchModal)));
+
add(revisionIndexing = new WebMarkupContainer("revisionIndexing") {
@Override
@@ -350,7 +387,6 @@ public class RepoFilePage extends RepositoryPage {
}.render(FILE_VIEWER_ID);
}
-
lastCommit = new AjaxLazyLoadPanel(LAST_COMMIT_ID) {
@Override
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/SearchResultPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/SearchResultPanel.java
index 7df6259798..37eee36a33 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/SearchResultPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/SearchResultPanel.java
@@ -34,11 +34,12 @@ import com.pmease.commons.wicket.assets.hotkeys.HotkeysResourceReference;
import com.pmease.gitplex.search.hit.FileHit;
import com.pmease.gitplex.search.hit.QueryHit;
import com.pmease.gitplex.search.hit.TextHit;
-import com.pmease.gitplex.web.component.blobsearch.BlobSearchPanel;
@SuppressWarnings("serial")
-abstract class SearchResultPanel extends Panel {
+public abstract class SearchResultPanel extends Panel {
+ public static final int QUERY_ENTRIES = 1000;
+
private enum ExpandStatus {EXPAND_ALL, COLLAPSE_ALL};
private static final String HITS_ID = "hits";
@@ -62,7 +63,7 @@ abstract class SearchResultPanel extends Panel {
public SearchResultPanel(String id, List<QueryHit> hits) {
super(id);
- hasMore = (hits.size() == BlobSearchPanel.ADVANCED_QUERY_ENTRIES);
+ hasMore = (hits.size() == QUERY_ENTRIES);
Map<String, MatchedBlob> hitsByBlob = new LinkedHashMap<>();
@@ -165,7 +166,7 @@ abstract class SearchResultPanel extends Panel {
protected void onInitialize() {
super.onInitialize();
- String message = "too many matches, displaying " + BlobSearchPanel.ADVANCED_QUERY_ENTRIES + " of them";
+ String message = "too many matches, displaying " + QUERY_ENTRIES + " of them";
add(new Label("hasMoreMessage", message).setVisible(hasMore));
add(prevMatchLink = new AjaxLink<Void>("prevMatch") {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/repo-file.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/repo-file.css
index d0824d69f1..a96ab59dd5 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/repo-file.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/repo-file.css
@@ -11,18 +11,12 @@
background: #EEE;
}
-#repo-file>.head .revision-selector, #repo-file>.head .file-navigator, #repo-file>.head .blob-search {
+#repo-file>.head .revision-selector, #repo-file>.head .file-navigator, #repo-file>.head .search {
padding: 5px 8px;
}
-#repo-file>.head .blob-search input {
- margin: -9px 4px -5px 0;
- border-top: none;
- border-bottom: none;
- border-left: 1px solid #BBB;
- border-right: 1px solid #BBB;
- box-shadow: none;
- border-radius: 0;
- height: 28px;
+#repo-file>.head .search>a {
+ color: #666;
+ margin: 0 4px;
}
#repo-file>.revision-indexing {