protected Query<Contact> buildQuery(Company company, String filter) {
Query<Contact> contactQuery = HiWebSuite.getDatastore().createQuery(Contact.class);
contactQuery.field("company").equal(company);
if (filter!=null) {
contactQuery.or(
contactQuery.criteria("firstName").containsIgnoreCase(filter),
contactQuery.criteria("name1").containsIgnoreCase(filter),
contactQuery.criteria("name2").containsIgnoreCase(filter),
contactQuery.criteria("name3").containsIgnoreCase(filter),
contactQuery.criteria("street").containsIgnoreCase(filter),
contactQuery.criteria("zip").containsIgnoreCase(filter),
contactQuery.criteria("city").containsIgnoreCase(filter)
);
}
contactQuery.or(
contactQuery.criteria("deleted").doesNotExist(),
contactQuery.criteria("deleted").equal(false)
);
contactQuery.order("name1");
return contactQuery;
}
I added the second "or" because I have documents in my collections that don't have the "deleted"-field yet.
As long as the filter is not set and the first "or" is not invoked, all works fine but if the first "or" is invoked, the query returns an empty result. The filter itself works because if I remove the second "or", all works fine again.
In this case I can remove the second "or" and set the "deleted" in all my documents but isn't it possible to use more than one "or" in a query?