I have a search box and while searching with user code, my expected result is the user codes which starts with the given keyword (keyword%
) and the remaining result should be (%keyword%
) .
Search with "TEST"
Expected result:
1. TEST1
2. TEST_ABC
3. TEST_QRS
...
11. ABC_TEST
12. BCTEST
like this
But the result I'm getting is :
1. ABC_TEST
2. BCTEST
...
11. TEST1
12. TEST_ABC
13. TEST_QRS
How can I write a groovy criteria to get the search result with these priorities ?
My current code is :
def searchKeyword = PERCENT+keyword+PERCENT
def userList = User.createCriteria().list (max: max, offset: offset) {
or {
ilike "code", searchKeyword
ilike "name", searchKeyword
}
order "code", "asc"
}
Thanks in advance.