Hello people, I can't seem to figure this one out;
I have one search field; Name. It's supposed to search on
-firstName
-middleName
-surName
I'd like to find an entity if the value is in any of these fields.
Example;
Marylin Monroe is registered as
-firstName : Marolyn
-middleName : (nothing)
-surName : Monro
I'd like to find this entity when the search field's value is;
"Mar" - firstName restriction
"Mar Mon" - firstName and surName restriction
"Mon" - surName restriction
"ar ro" - firstName and surName restriction anywhere
"ro" - surName restriction anywhere.
How do I combine them?
First I tried something like this on the two first fields; I know now that this wont work;
Code:
customerCriteria.add(
Restrictions.or(
Restrictions.and(
Restrictions.ilike("firstName", getName(), MatchMode.ANYWHERE),
Restrictions.ilike("surName", getName(), MatchMode.ANYWHERE)),
Restrictions.or(
Restrictions.ilike("firstName", getName(), MatchMode.ANYWHERE),
Restrictions.ilike("surName", getName(), MatchMode.ANYWHERE))));