Jan Jan - 6 months ago 64
Java Question

Grails how to do multiple search queries

I have this from my controller:

def purchaseRequestList = PurchaseRequest.createCriteria().list (params) {
if ( params.query) {
ilike('requestBy', "%${params.query}%")

Above is a snippet from my list method

It can only do one search by the params requestBy

Then i do this in my gsp

<g:form action="listPurchaseRequest" method="GET">
<g:textField id="search" class="pull-right" name="query" value="${params.query}" placeholder=" Search"/>

Now i added a new param of requestNumber

How do i do two or more searches?


I'll take a guess that you want to use the single param query to search against multiple fields in the domain class PurchaseRequest. This could be done like:

def purchaseRequestList = PurchaseRequest.findAllByRequestByLikeOrRequestNumberLike("%${params.query}%", "%${params.query}%", params)

See the Dynamic Finders section of the Grails docs.