use of org.opennms.newts.api.search.BooleanClause in project newts by OpenNMS.
the class CassandraSearcher method searchForIds.
/**
* Returns the set of resource ids that match the given
* boolean query.
*
* Separate clauses are performed with separate database queries and their
* results are joined in memory.
*/
private Set<String> searchForIds(Context context, BooleanQuery query, ConsistencyLevel readConsistency) {
Set<String> ids = Sets.newTreeSet();
for (BooleanClause clause : query.getClauses()) {
Set<String> subQueryIds;
Query subQuery = clause.getQuery();
if (subQuery instanceof BooleanQuery) {
subQueryIds = searchForIds(context, (BooleanQuery) subQuery, readConsistency);
} else if (subQuery instanceof TermQuery) {
subQueryIds = searchForIds(context, (TermQuery) subQuery, readConsistency);
} else {
throw new IllegalStateException("Unsupported query: " + subQuery);
}
switch(clause.getOperator()) {
case // Intersect
AND:
ids.retainAll(subQueryIds);
break;
case // Union
OR:
ids.addAll(subQueryIds);
break;
default:
throw new IllegalStateException("Unsupported operator: " + clause.getOperator());
}
}
return ids;
}
Aggregations