I'm using CriteriaBuilder to add Search filters in Postgres. I need also add an additional filter entries that have Location that is a part of a Map window.
final Envelope envelope = new Envelope();
envelope.expandToInclude(Double.parseDouble(nwLat), Double.parseDouble(nwLng));
envelope.expandToInclude(Double.parseDouble(seLat), Double.parseDouble(seLng));
envelope.contains(envelope.contains(33.6462, -117.7559));
How to add that as Predicate in CriteriaBuilder?
Code I have so far
public Specification<Listing> getFilteredListings(Short minBeds, Short minBaths, Integer minPrice, Integer maxPrice, String nwLat, String nwLng, String seLat, String seLng) {
return (root, query, criteriaBuilder) -> {
List<Predicate> predicates = new ArrayList<>();
/* CODE I NEED TO ADD
final Envelope envelope = new Envelope();
envelope.expandToInclude(Double.parseDouble(nwLat), Double.parseDouble(nwLng));
envelope.expandToInclude(Double.parseDouble(seLat), Double.parseDouble(seLng));
envelope.contains()
*/
predicates.add(criteriaBuilder.equal(root.get("listingStatus"), ACTIVE));
if (nonNull(minBeds)) {
predicates.add(criteriaBuilder.ge(root.get("beds"), minBeds));
}
if (nonNull(minBaths)) {
predicates.add(criteriaBuilder.ge(root.get("baths"), minBaths));
}
if (nonNull(minPrice)) {
predicates.add(criteriaBuilder.ge(root.get("price"), minPrice));
}
if (nonNull(maxPrice)) {
predicates.add(criteriaBuilder.le(root.get("price"), maxPrice));
}
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
};
}