Skip to content

Instantly share code, notes, and snippets.

@iamthiago
Created June 23, 2017 01:04
Show Gist options
  • Save iamthiago/83c2e5c333e1a47dc8ed54fa162ac2b1 to your computer and use it in GitHub Desktop.
Save iamthiago/83c2e5c333e1a47dc8ed54fa162ac2b1 to your computer and use it in GitHub Desktop.
private Predicate createAdvancedSearchQuery(Long maxPrice, Long minPrice, Integer beds, Integer baths, String province) {
QProperty property = QProperty.property;
BooleanBuilder booleanBuilder = new BooleanBuilder();
if(maxPrice != null && minPrice != null) {
booleanBuilder.and(property.price.between(minPrice, maxPrice));
} else if (maxPrice != null) {
booleanBuilder.and(property.price.loe(maxPrice));
} else if (minPrice != null) {
booleanBuilder.and(property.price.goe(minPrice));
}
if(beds != null){
booleanBuilder.and(property.beds.eq(beds));
}
if(baths != null){
booleanBuilder.and(property.baths.eq(baths));
}
if(!StringUtils.isEmpty(province)) {
booleanBuilder.and(property.provinces.contains(Province.valueOf(province)));
}
return booleanBuilder.getValue();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment