Lucene: Prohibit searching empty string over a full-text field
org.apache.lucene.util.QueryBuilder returns a null query when given an empty string to tokenize (see line 245). We can detect this case earlier in the query building process and return a readable error to the user. This may not be the only way that QueryBuilder can return a null query, so add a null check in LuceneChangeIndex so the resulting stack trace is less obtuse. Change-Id: Icf9a1ab50881d61ae4400a34cc2ce7e2a78e1162
This commit is contained in:
parent
42850cf30b
commit
7a9c7e6a00
|
@ -14,6 +14,7 @@
|
|||
|
||||
package com.google.gerrit.lucene;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||
import static com.google.gerrit.server.git.QueueProvider.QueueType.INTERACTIVE;
|
||||
|
@ -393,7 +394,7 @@ public class LuceneChangeIndex implements ChangeIndex {
|
|||
private QuerySource(List<SubIndex> indexes, Query query, int start,
|
||||
int limit, Sort sort) {
|
||||
this.indexes = indexes;
|
||||
this.query = query;
|
||||
this.query = checkNotNull(query, "null query from Lucene");
|
||||
this.start = start;
|
||||
this.limit = limit;
|
||||
this.sort = sort;
|
||||
|
|
|
@ -242,8 +242,14 @@ public class QueryBuilder {
|
|||
return new PrefixQuery(new Term(p.getField().getName(), p.getValue()));
|
||||
}
|
||||
|
||||
private Query fullTextQuery(IndexPredicate<ChangeData> p) {
|
||||
return queryBuilder.createPhraseQuery(p.getField().getName(), p.getValue());
|
||||
private Query fullTextQuery(IndexPredicate<ChangeData> p)
|
||||
throws QueryParseException {
|
||||
String value = p.getValue();
|
||||
if (value == null) {
|
||||
throw new QueryParseException(
|
||||
"Full-text search over empty string not supported");
|
||||
}
|
||||
return queryBuilder.createPhraseQuery(p.getField().getName(), value);
|
||||
}
|
||||
|
||||
public int toIndexTimeInMinutes(Date ts) {
|
||||
|
|
Loading…
Reference in New Issue