code: 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 AND: // Intersect
                      ids.retainAll(subQueryIds);
                      break;
                  case OR: // Union
                      ids.addAll(subQueryIds);
                      break;
                  default:
                      throw new IllegalStateException("Unsupported operator: " + clause.getOperator());
              }
          }
  
          return ids;
      }
docs: 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.