0
votes

Given the following domain class:

class Test {
    String name
    Integer val1, val2
}

I'm currently searching this class with the following criteria:

Test.createCriteria().list(params) {
    params.key.split(' ').each {
        ilike('name', "%${it}%")
    }
    gtProperty('val1', 'val2')
}

I'm trying to use Grails Searchable Plugin to improve my search results. More specifically its Query Builder. The only problem is that I can't find a way to filter results where val1 > val2. As shown bellow:

Test.search(params) {
    must(queryString(params.key))
    must(
        // Something to require that val1 > val2
    )
}

I could filter it after searching but it would mess pagination.

Any ideas?

1

1 Answers

0
votes

What's wrong with this?

def result = Test.where {
    it.name = name
    it.val1 > val2
}

edit: In the documentation it shows this as an example

search {                    // <-- create an implicit boolean query
    lt("pages", 50)         // <-- uses CompassQueryBuilder#lt, and adds a boolean "should" clause
    term("type", "poetry")  // <-- uses CompassQueryBuilder#term, and adds a boolean "should" clause
}

So would something like this work for you? Not sure on the syntax, never used this before.

search {                      
    term("name", foo) 
    gt("val1", val2)
}