5

I am working on a Spring Boot and Angular application which has a requirement to search based on any number of the available filters being applied to a list. For example, a user searches on 'Title' and 'Author,' but not 'Edition.'

I am comfortable with how I'll accomplish this at all layers except for the ORM. In my head the process would be to simply include the criteria for which the user has submitted values. However, with the tools available in JPA, I do not see a clear path to success. I believe my options are JPA's Criteria API, or Query DSL. I either case, it seems like I'd have to write a bunch of conditional logic to append .and or the equivalent on to a query. Is there a way to pass argument lists to JPA, similar to ActiveRecord? Am I asking the right questions?

1
  • Usually this is achieved by making use of search engines like Apache Solr or Elastic Search and the like and not by using an SQL database. Commented Oct 27 at 13:09

1 Answer 1

2

If your filters are simple (like equality per field) then check out query by example in Spring Data JPA.

If you need complex filters (like comparisons between fields, checking for existence, range checks, logical operators) then I would go with mapping each filter with single DTO and then transforming them into SQL predicate using library like JOOQ.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.