Added null checks when adding inner queries

This commit is contained in:
Christoph Büscher 2015-06-23 11:45:00 +02:00
parent 6f8c0ce966
commit f2573da77b
4 changed files with 19 additions and 4 deletions

View File

@ -107,7 +107,11 @@ public class AndQueryBuilder extends AbstractQueryBuilder<AndQueryBuilder> {
BooleanQuery query = new BooleanQuery();
for (QueryBuilder f : filters) {
query.add(f.toQuery(parseContext), Occur.MUST);
Query innerQuery = f.toQuery(parseContext);
// ignore queries that are null
if (innerQuery != null) {
query.add(innerQuery, Occur.MUST);
}
}
if (queryName != null) {
parseContext.addNamedQuery(queryName, query);

View File

@ -106,7 +106,11 @@ public class OrQueryBuilder extends AbstractQueryBuilder<OrQueryBuilder> {
BooleanQuery query = new BooleanQuery();
for (QueryBuilder f : filters) {
query.add(f.toQuery(parseContext), Occur.SHOULD);
Query innerQuery = f.toQuery(parseContext);
// ignore queries that are null
if (innerQuery != null) {
query.add(innerQuery, Occur.SHOULD);
}
}
if (queryName != null) {
parseContext.addNamedQuery(queryName, query);

View File

@ -40,7 +40,10 @@ public class AndQueryBuilderTest extends BaseQueryTestCase<AndQueryBuilder> {
}
BooleanQuery query = new BooleanQuery();
for (QueryBuilder subQuery : queryBuilder.filters()) {
query.add(subQuery.toQuery(context), Occur.MUST);
Query innerQuery = subQuery.toQuery(context);
if (innerQuery != null) {
query.add(innerQuery, Occur.MUST);
}
}
return query;
}

View File

@ -40,7 +40,11 @@ public class OrQueryBuilderTest extends BaseQueryTestCase<OrQueryBuilder> {
}
BooleanQuery query = new BooleanQuery();
for (QueryBuilder subQuery : queryBuilder.filters()) {
query.add(subQuery.toQuery(context), Occur.SHOULD);
Query innerQuery = subQuery.toQuery(context);
// ignore queries that are null
if (innerQuery != null) {
query.add(innerQuery, Occur.SHOULD);
}
}
return query;
}