In one of my applications, I am to execute a search on multiple fields/columns. Its an Advanced Search and there are over 20 fields using which a user can search for results. For example, a user can search for bookings based on
- Booking Id
- Passenger Name
- Passenger Age
- From Location
- To Location
- Booking Status
- Name of the Airline
and 13 such fields.
I am trying to figure out if
-
Hibernate Search can and should be used here? If so, how? I was unable to find an example for such a complex search using Hibernate Search.
-
Instead of Hibernate search, I can simply use Hibernate and maybe design a multi-threaded search depending in the number of parameters. Would that be a good idea?
-
Is it possible to use Hibernate Filters here?
Can someone please provide inputs or reference links?
For these kinds of queries, I generally use a
Criteriaquery with a form object. I then check fornullin each passed form field, and if notnull, then add anotherRestrictioninto the query, using that field. Using aCriteriaquery keeps the Java code very clean and eliminates messy string concatenation. An example for your case: