Added null checks when adding inner queries
This commit is contained in:
parent
6f8c0ce966
commit
f2573da77b
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue